Validate the Streamable HTTP request-metadata headers (#110) - #126
Merged
Conversation
SEP-2243 mirrors a few body fields into HTTP headers so an intermediary can route without parsing JSON. That only holds if the two agree - otherwise a load balancer and this server act on different requests - so a disagreement is HeaderMismatch (-32020) with a 400. Mcp-Method must equal the body method; Mcp-Name must equal params.name or params.uri, decoded first from the =?base64?...?= sentinel, or a tool named in anything but ASCII would look like a mismatch against its own body; MCP-Protocol-Version must equal what _meta declares. Enforcement is two-speed, like the rest of this revision: a request declaring 2026-07-28 MUST carry them, while a 2025-06-18 client - which is every HTTP client we serve today - never sent them and is not asked to start. What holds in both cases is that a header which IS present must be true. The rest of the issues list: - GET and DELETE both answer 405 now. The GET stream became subscriptions/listen and DELETE tore down a session that no longer exists in the protocol - and never existed here, since no session id was ever minted. Nothing can break: a client that never received one has nothing to tear down. - CORS drops Mcp-Session-Id and allows Mcp-Method/Mcp-Name. - Mcp-Session-Id and Last-Event-ID are ignored, with a test proving no session id is ever echoed back. - Batch arrays: kept. Batching left MCP in 2025-06-18 and nothing we serve sends one, but accepting it costs nothing and refusing would help nobody. The metadata headers describe ONE message, so a batch skips that validation - there is no meaningful Mcp-Method for an array of different methods. - x-mcp-header (custom headers from tool parameters) deliberately not implemented: it is optional for servers, and none of our tools would gain from having a parameter mirrored into a header for routing. 10 tests.
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #110.
SEP-2243 mirrors a few body fields into HTTP headers so an intermediary can route without parsing JSON. That only holds if the two agree — otherwise a load balancer and this server are acting on different requests — so a disagreement is
HeaderMismatch(-32020) with a400.Header validation
Mcp-Methodmust equal the body'smethod.Mcp-Namemust equalparams.name(orparams.uri), decoded from the=?base64?…?=sentinel first — otherwise a tool named in anything but ASCII would look like a mismatch against its own body.MCP-Protocol-Versionmust equal what_metadeclares.Two-speed enforcement, like the rest of this revision: a request declaring 2026-07-28 must carry them; a 2025-06-18 client — which is every HTTP client we serve today — never sent them and isn't asked to start. What holds in both cases is that a header which is present must be true.
The rest of the issue's list
GETandDELETEboth answer 405. The GET stream becamesubscriptions/listen; DELETE tore down a session that no longer exists in the protocol — and never existed here, since no session id was ever minted. A client that never received one has nothing to tear down, so nothing can break.Mcp-Session-Id, allowsMcp-Method/Mcp-Name.Mcp-Session-IdandLast-Event-IDare ignored, with a test proving no session id is ever echoed back.Mcp-Methodfor an array of different methods. Now commented and tested either way, as the issue asked.x-mcp-headerdeliberately not implemented. It is optional for servers, and none of our tools would gain from having a parameter mirrored into a header for routing — nothing here is routed by tenant or region. Worth revisiting only if the HTTP transport ever sits behind something that routes on tool arguments.Deliberately out of scope
The same spec section says an unimplemented method over HTTP should return
404(with the JSON-RPC-32601body) rather than200. That is not on this issue's list and it interacts with the backward-compatibility probe, so I left it — happy to file it as a follow-up if you want it.Verification
Mcp-Methodand onMcp-Name; base64 sentinel decoded; agreeing headers accepted; an older client not asked for them; a new-revision client required to send them; a protocol-version header contradicting the body; stale session/resumability headers ignored and never echoed; GET and DELETE both 405; a batch still accepted and skipping header validation.README: the HTTP transport section covers the 405s and the header rules.