createMcpHandler: Mcp-Param header validation and scope challenges only run when the factory returns an McpServer

オープン
#3,126 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript

調査の方向性

Start by locating createMcpHandler and its existing checks for McpServer products; the issue identifies the affected behavior but names no file or test. Trace how factory products reach handler.fetch and how the schema and scope challenge helpers are called. Done means a low-level Server can use the proposed options or exported helpers for both checks, with tests covering header validation and scope challenges.

索引モデルが issue の本文から書いたものです。

説明

v2

In 2.4.0, createMcpHandler runs two pre-dispatch checks for modern requests, but only when the factory's product is an McpServer:

if (route.messageKind === "request" && route.message.method === "tools/call" && product instanceof McpServer) {
  const inputSchema = product.toolInputSchemaJson(toolName);
  // scanXMcpHeaderDeclarations → validateMcpParamHeaders → rejectionResponse
}
if (route.messageKind === "request" && product instanceof McpServer) {
  const challenge = await findScopeChallenge([route.message], authInfo, (context) => product.resolveScopeChallenge(context));
  // createScopeChallengeResponse
}

The factory may return a low-level Server instead. In that case both checks are skipped without any warning:

  • SEP-2243 Mcp-Param-* header validation. A request whose headers disagree with its tool arguments goes straight through to the handler.
  • OAuth scope challenges. No 403 insufficient_scope is ever produced.

A low-level Server is the only option when the tool list can't be fixed when the instance is created. Examples:

  • visibility that depends on the request's client capabilities;
  • pagination cursors bound to the caller;
  • extension methods;
  • task and input-required results.

Such servers have to re-implement both checks before calling handler.fetch. scanXMcpHeaderDeclarations, validateMcpParamHeaders and createScopeChallengeResponse are not exported, so they have to be re-implemented from scratch rather than called.

Proposal, either of:

  1. Handler options that work with any product (preferred):
    createMcpHandler(factory, {
      toolInputSchema?: (name: string, context) => JsonSchema | undefined,
      scopeChallenge?: ScopeChallengeHandler,
    })
    
    McpServer keeps supplying its own through toolInputSchemaJson and resolveScopeChallenge when the options are absent.
  2. At minimum, export the helpers: scanXMcpHeaderDeclarations, validateMcpParamHeaders, findScopeChallenge and createScopeChallengeResponse. Servers built on Server could then reuse the exact SDK behavior.

Either way, it would help if the handler warned when a non-McpServer product skips these checks.

Context: we maintain an MCP server component on the low-level Server. It currently carries its own copy of the header validation and the scope-challenge responses for exactly this reason.

主要言語
TypeScript
スター
13.8k
フォーク
2.5k
平均マージ
6日 23時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/typescript-sdk のほかの issue

modelcontextprotocol/typescript-sdk の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。