Skip to content

feat(transport): add SEP-2243 Mcp-Method / Mcp-Name header mirroring with MCP-Protocol-Version validation - #1112

Draft
slachiewicz wants to merge 7 commits into
modelcontextprotocol:mainfrom
slachiewicz:feat/sep-2243-headers
Draft

slachiewicz wants to merge 7 commits into
modelcontextprotocol:mainfrom
slachiewicz:feat/sep-2243-headers

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Keep the current body, and add two bullets under Semantics. First, the client no longer sends MCP-Protocol-Version on the initialize POST. Second, the streamable servlet transport now validates MCP-Protocol-Version on GET and DELETE as well as POST.

@slachiewicz

Copy link
Copy Markdown
Contributor Author

Pushed 67e89e70, addressing three gaps.

  • Builder.requireMcpHeaders(boolean) on both servlet transports, default false. When on, a request that omits Mcp-Method, or targets a tool, prompt or resource without Mcp-Name, is rejected with 400 and HEADER_MISMATCH. This is the opt-in toggle discussed in SEP-2243: HTTP Header Standardization for Streamable HTTP Transport #990; a present but mismatched header is rejected regardless.
  • The validation now lives in one package-private Sep2243RequestValidator shared by both transports, reading headers through the HeaderAccessor from ServerTransportSecurityValidator accepts an accessor function for header #870. It sits beside ServerHttpHeaderValidator rather than inside it because the mirroring checks need the parsed JSON-RPC body. Happy to move it if you would rather widen that interface.
  • An unsupported MCP-Protocol-Version returns INVALID_REQUEST instead of METHOD_NOT_FOUND.

Verified: ./mvnw -B -pl mcp-core -am test → 408 tests, 0 failures.

This comment was created with AI assistance.

slachiewicz and others added 7 commits November 27, 2026 14:36
…with MCP-Protocol-Version validation

Implement SEP-2243 HTTP header standardization across client and server
servlet transports.

* Client: Emit 'Mcp-Method' on outbound Streamable HTTP requests and
  notifications, and 'Mcp-Name' when targeting named tools, prompts, or
  resources.
* Server: Validate 'Mcp-Method' and 'Mcp-Name' headers against deserialized
  JSON-RPC payloads in HttpServletStreamableServerTransportProvider and
  HttpServletStatelessServerTransport. Reject mismatches with HTTP 400 while
  tolerating absent headers for backward compatibility.
* Versioning: Validate 'MCP-Protocol-Version' against supported protocol
  versions on incoming servlet requests.
* Tests: Add Sep2243ClientRequestHeaderTests and Sep2243ServerHeaderValidationTests
  verifying emission, mismatch rejections, and absent-header tolerance.
…checks

Per the Streamable HTTP spec the MCP-Protocol-Version header is required only after initialization completes; version selection for initialize happens through body-level negotiation, not header validation.

* Client: stop sending MCP-Protocol-Version on initialize requests

* Servlet servers: skip strict header validation for initialize so clients advertising an unsupported version negotiate instead of getting 400

* Tests: pin client omission and server tolerance for initialize; make version-negotiation test contextExtractor null-safe for absent headers
The GET /mcp stream is opened asynchronously once initialize creates the session, so asserting recorded calls immediately races under load (seen as Jackson 2 Integration Tests failing usesLatestVersion with Expected size: 3 but was: 2). Await the recorded GET before asserting header propagation.
… and return -32020 HeaderMismatch

* Encode non-ASCII and sentinel-matching Mcp-Name values in Base64 sentinel
  format (=?base64?...?=) in HttpClientStreamableHttpTransport to prevent
  JDK HttpClient IllegalArgumentException on non-Latin-1 characters.
* Decode Base64 sentinel Mcp-Name values on HttpServletStreamableServerTransportProvider
  and HttpServletStatelessServerTransport prior to body validation.
* Add HEADER_MISMATCH (-32020) error code to McpSchema.ErrorCodes per SEP-2243
  and return it on header/body mismatches.
* Add unit and integration tests for Base64 sentinel encoding/decoding and
  -32020 mismatch error codes.

Co-authored-by: Nikita Kibitkin <nikita.n.kibitkin@gmail.com>
…vlet transports

Move the duplicated MCP-Protocol-Version / Mcp-Method / Mcp-Name validation out
of both servlet transports into a package-private Sep2243RequestValidator they
share. An unsupported MCP-Protocol-Version now returns INVALID_REQUEST instead
of the previously incorrect METHOD_NOT_FOUND. requireMcpHeaders defaults to
false, so clients that do not send the SEP-2243 headers are unaffected.
mcp-test no longer depends on Spring, so the MockHttpServlet* based tests did not compile. Also cover MCP-Protocol-Version rejection on GET and DELETE.
@slachiewicz
slachiewicz force-pushed the feat/sep-2243-headers branch from db44092 to bf04765 Compare November 27, 2026 15:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant