Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON string
メンテナーはふだん 1 日以内に返信
@starryeye がすでに取り組んでいます。
2026年11月25日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 75/100
調査の方向性
モダンな HttpServletMcpTransport.validateHeaders から始め、params.name または params.uri が JSON 文字列でない場合の早期 return の周辺を確認してください。そのうえで、HTTP 400 と -32020 を返す既存のヘッダーと本文の不一致パスと比較してください。null の名前に関連する動作については 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時間
- マージ済み PR(30日)
- 38
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信
-
Tool result _meta is lost when the server automatically adds text content for structured outputオープン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