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

未关闭
#3,126 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/typescript-sdk 的其他 Issue

查看 modelcontextprotocol/typescript-sdk 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。