Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON string
维护者通常 1 天内回复
@starryeye 已经在做这个了。
开始于 2026年11月25日。
评估
调研方向
从现代的 HttpServletMcpTransport.validateHeaders 开始,关注当 params.name 或 params.uri 不是 JSON 字符串时的提前返回,并将其与现有的请求头与请求体不一致路径进行比较,该路径会返回 HTTP 400 和 -32020。阅读 McpServer.extractPrimitiveName 以了解相关的空名称行为,然后添加回归测试,覆盖 tools/call、prompts/get 和 resources/read,使用数字和布尔类型的 name/uri,断言返回 400 且没有调用任何处理器。
由索引模型根据 Issue 内容生成。
描述
Bug description
The modern HttpServletMcpTransport (MCP 2026-07-28) checks Mcp-Name against the body only when params.name (or params.uri) is a JSON string. For any other value it returns early, so neither a mismatch nor a missing Mcp-Name header is detected:
// HttpServletMcpTransport.validateHeaders (v2.2.0, lines 464-466)
if (!(paramsMap.get(nameKey) instanceof String expectedName)) {
return null;
}
The params are then decoded with Jackson, which coerces scalars to the String field. "name": 1 becomes the tool name "1", and ToolsFeature looks up and runs tool "1". prompts/get takes the same path, and resources/read does the same for a non-string uri.
So a request with Mcp-Name: searchProducts and "name": 1 is not rejected and runs tool 1. The same request with "name": "1" (a string) is correctly rejected with HTTP 400 and -32020.
The 2026-07-28 Streamable HTTP spec ("Server Validation") asks servers to reject header/body mismatches with HTTP 400 and -32020 (HeaderMismatch). The class javadoc also says that filters may authorize on Mcp-Method/Mcp-Name because mismatching requests are rejected before dispatch.
The practical impact is narrow. Only a primitive whose name is a number or boolean literal is reachable, and only a deployment that authorizes by Mcp-Name in a front filter is affected. Arrays, objects and null already end as -32602.
This was first reported privately; the maintainers asked for it to be tracked as a public hardening issue.
Environment
io.modelcontextprotocol.sdk:mcp-core 2.2.0 (also 2.2.0-M1 and 2.2.0-M2), Java 21. The code is unchanged on main (779893c).
Steps to reproduce
- Register two tools on a modern server:
searchProductsand1. - Map
HttpServletMcpTransportat/mcp, with a servlet filter in front that returns 403 fortools/callunlessMcp-NameissearchProducts. - Send:
POST /mcp
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: searchProducts
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":1,
"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
Observed on 2.2.0-M1: HTTP 200, and tool 1 runs. The code path is unchanged in 2.2.0.
Expected behavior
For tools/call, prompts/get and resources/read, a name/uri that is present but not a JSON string is rejected before dispatch (HTTP 400 with -32020, or -32602), and no handler runs. For example:
Object bodyName = paramsMap.get(nameKey);
if (bodyName == null) {
return null; // left to params decoding (-32602)
}
if (!(bodyName instanceof String expectedName)) {
return "Request " + nameKey + " must be a string";
}
A related detail: McpServer.extractPrimitiveName also returns null for a non-string name, so rejecting these requests early also keeps primitiveName non-null for named methods.
Minimal Complete Reproducible example
The request in step 3 is enough to see it against any modern server that has a tool named 1. A regression test could cover each named method against HttpServletMcpTransport, with name/uri set to a number and to a boolean, expecting HTTP 400 and no handler call.
- 主要语言
- Java
- 星标
- 3.8k
- 派生
- 1.1k
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 38
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/java-sdk 的其他 Issue
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was called未关闭
难度 1/5 1 小时以内 新手友好度 85/100
modelcontextprotocol/java-sdk#1346 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
modelcontextprotocol/java-sdk#1345 · 1 条评论 ·
维护者通常 1 天内回复
-
area/server legacy P3
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/java-sdk#1330 · 1 条评论 ·
维护者通常 1 天内回复
-
Client request handlers that complete empty send no JSON-RPC response可能已有人在做 @1fanwang 于 83 天前认领。 未关闭area/client bug P2
难度 2/5 1-3 小时 新手友好度 84/100
modelcontextprotocol/java-sdk#1124 · 6 条评论 ·
维护者通常 1 天内回复
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities可能已有人在做 @1yuxiangJ 于 98 天前认领。 未关闭bug P2 ready for work
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/java-sdk#1086 · 2 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/java-sdk 的全部 Issue
相似的 Issue
-
crash
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 74/100
-
account bug course exam iris lecture
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100