GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — feat: validate SEP-2243 Mcp-Param headers in modern server by prathamgoyal787 · Pull Request #1202 · modelcontextprotocol/java-sdk Conversation
|
| Case | Outcome |
|---|---|
| Argument present | Header required and must match. Strings exactly, integers numerically (42.0 = 42), booleans as true/false |
Argument null or absent (incl. missing intermediate object) |
No header expected |
| Argument present, header missing | Rejected |
| Header of a declared parameter malformed | Rejected |
Mcp-Param-* header no parameter declares |
Ignored |
Rejections throw McpException with ErrorCodes.HEADER_MISMATCH (-32020), which the servlet answers with 400.
Invalid definitions: invalid server-side x-mcp-header definitions are ignored with a debug log, per the open question in Validate SEP-2243 Mcp-Param-{Name} headers in the modern server #1199. Invalid means a name that is empty or not an RFC 9110 token, a type other than string/integer/boolean, or a case-insensitive duplicate.
New and extended tests:
TransportParamsTests covers:
attach overriding a value forged by the extractorMcpParamHeadersTests: nested properties paths; annotations behind items/allOf/$ref/$defs ignored; invalid names, types and duplicates.ToolsFeatureParamHeaderTests: one test per table row, each asserting the tool and inputSchema validation never ran on rejection. Also 42.0 vs 42, booleans, Base64 and literal values, NOT_MIRRORED skipping validation, and a missing key not skipping it.StdioMcpTransportTests: stdio passes NOT_MIRRORED.HttpServletMcpTransportIntegrationTests, end to end over Tomcat: matching header → 200; mismatched, missing or malformed header → 400 / -32020.Results:
mvn test -pl mcp-core: 635 tests, 0 failures, 0 errors.mvn test -pl mcp-test: 1036 tests, 0 failures, 1 skipped. All modern-server tests pass. There were 12 errors, all Testcontainers "Could not find a valid Docker environment" in legacy client tests, because Docker wasn't available locally.@modelcontextprotocol/[email protected] against conformance-tests/server-servlet-modern, with the new test_custom_header fixture:
--scenario http-custom-header-server-validation: 10/10 passed.--requirements 2026-07-28: all 37 required scenarios pass, so no regressions. The only failures are the unscored tasks-* extension.No public API is removed or changed. One behaviour change to be aware of: a custom transport or in-memory caller that passes an McpTransportContext without TransportParams (for example McpTransportContext.EMPTY) now gets -32020 when it calls a tool with an x-mcp-header argument value. This is deliberate: #1199 requires that a missing key must not skip validation. Such transports should attach TransportParams.NOT_MIRRORED, or the parsed headers, with TransportParams.attach(...). Tools without x-mcp-header are unaffected.
Mcp-Param-X header counts as malformed.BigDecimal, so 42, 42.0 and 4.2e1 all match.Mcp-Name decoder still accepts unpadded Base64.VALIDATION_RESULTS.md moves the scenario to Passing and narrows Known Limitation Update the License #2 to "definitions aren't enforced at registration/listing". The server-servlet-modern README lists the new fixture.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
HttpServletMcpTransport collects every Mcp-Param-* header into TransportParams (case-insensitive names, =?base64?...?= decoding, malformed values flagged rather than failing) and attaches it to the McpTransportContext after the user's contextExtractor, so the extractor can neither drop nor forge it. StdioMcpTransport declares NOT_MIRRORED; a context without params counts as a request with no headers. ToolsFeature checks, after find and before inputSchema validation, every x-mcp-header parameter reachable through properties: a present argument needs a matching header (integers compared numerically, booleans as true/false), a null or absent argument expects none, malformed headers of declared parameters are rejected and undeclared headers are ignored. Rejections fail with -32020 (HEADER_MISMATCH), answered with 400 over HTTP. Invalid x-mcp-header definitions are ignored with a debug log. Adds the test_custom_header conformance fixture; the http-custom-header-server-validation scenario now passes (10/10). Closes modelcontextprotocol#1199
Move ToolsFeatureParamHeaderTests to mcp-test with the other modern server tests that rely on JSON serialization (modelcontextprotocol#1215), using the default mapper instead of Gson.
Adapt to find returning the tool with its handler (modelcontextprotocol#1282): validate the Mcp-Param headers against the found tool's definition, after the required-capabilities check and before inputSchema validation, and port the tests to McpAsyncTool.
|
Hi @Kehrlann, I saw you picked up #1199. This PR implements it (closes #1199) and is up to date with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hey @prathamgoyal787 This is too big for us to review and interact over in GitHub. We need tighter feedback loops and will be implementing it internally. Closing as superseded by #1286 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Validate SEP-2243Mcp-Param-{Name} headers in the modern server
There was an error while loading. Please reload this page.