feat: Implement Stateless MCP (SEP-2575) support#73
Open
stenalpjolly wants to merge 3 commits into
Open
Conversation
…TP transport layers
- Register stateless protocol version 2026-06-18 - Add _meta parameters for inline protocol negotiation metadata - Support MCP-Protocol-Version HTTP header - Bypass connection handshakes in HttpMcpTransportV20260618 - Implement dynamic client-side fallback/retry protocol negotiation TAG=agy CONV=2e1a2106-f882-4b08-92df-a27ba37c6fae
… tests to obey 700 lines limit
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.
Summary
Implement Stateless MCP (SEP-2575) support in the Java SDK. This includes bypassing connection handshake initialization for version
2026-06-18, embedding namespace-prefixed protocol metadata inside_metaon all outgoing tool requests, setting theMCP-Protocol-VersionHTTP request header, and implementing dynamic client-side fallback/retry version negotiation when target servers return version mismatch errors (-32004 or -32001).Expectation & Implementation
2026-06-18inProtocolVersion._metamap toCallToolParamsto support inline protocol metadata.HttpMcpTransportV20260618which inherits fromBaseMcpTransport. It overridesmodifyRequestParamsto inject reverse-DNS prefixed_metakeys (io.modelcontextprotocol/protocolVersion, etc.), sets theMCP-Protocol-Versionheader, and overridesensureInitializedto bypass stateful handshake checks.modifyRequestParamsrequest lifecycle hook inBaseMcpTransport.switchVersion(ProtocolVersion)inHttpMcpTransportto reconstruct delegate transports.-32004(Unsupported protocol version) and-32001(Method not found) during response deserialization, parsed server-supported versions, and threw a customMcpProtocolNegotiationException.executeWithFallbackinMcpToolboxClientImplwhich catchesMcpProtocolNegotiationException, selects the highest mutually supported version, invokesswitchVersionon the transport, and retries the request exactly once.Test cases
HttpMcpTransportStatelessTestto verify:2026-06-18transport._metaandMCP-Protocol-Versionheader.McpProtocolNegotiationExceptionwith compatible version lists.HttpMcpTransportTestto cover all error states (non-200, missing session ID, version mismatches) across all stateful transport versions.Acceptance criteria
google-java-format), checkstyle, and Jacoco coverage checks (>98%) pass.Breaking changes