Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON string
Maintainers usually reply within 1 day
@starryeye is already working on this.
Since Nov 25, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start in the modern HttpServletMcpTransport.validateHeaders, around the early return when params.name or params.uri is not a JSON string, and compare it with the existing header/body mismatch path that returns HTTP 400 with -32020. Read McpServer.extractPrimitiveName for the related null-name behavior, then add regression tests covering tools/call, prompts/get, and resources/read with numeric and boolean name/uri, asserting a 400 and no handler invocation.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Java
- Stars
- 3.8k
- Forks
- 1.1k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 38
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/java-sdk
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was calledOpen
Difficulty 1/5 Under an hour Newbie friendliness 85/100
modelcontextprotocol/java-sdk#1346 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
modelcontextprotocol/java-sdk#1345 · 1 comment ·
Maintainers usually reply within 1 day
-
Tool result _meta is lost when the server automatically adds text content for structured outputOpenarea/server legacy P3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
modelcontextprotocol/java-sdk#1330 · 1 comment ·
Maintainers usually reply within 1 day
-
Client request handlers that complete empty send no JSON-RPC responsePossibly taken @1fanwang claimed this 83 days ago. Openarea/client bug P2
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelcontextprotocol/java-sdk#1124 · 6 comments ·
Maintainers usually reply within 1 day
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilitiesPossibly taken @1yuxiangJ claimed this 98 days ago. Openbug P2 ready for work
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
modelcontextprotocol/java-sdk#1086 · 2 comments ·
Maintainers usually reply within 1 day
All issues in modelcontextprotocol/java-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
account bug course exam iris lecture
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
CycloneDX/cyclonedx-core-java#1002 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
linagora/tmail-backend#3168 ·
Maintainers usually reply within 1 day