fix: negotiate stateless initialize versions - #1080
Merged
Merged
Conversation
DaleSeo
marked this pull request as ready for review
July 29, 2026 18:58
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes stateless Streamable HTTP initialization so that protocol version negotiation is enforced at the transport boundary even when a ServerHandler overrides initialize, aligning behavior with stdio and stateful HTTP and satisfying the lifecycle requirement to echo a requested known protocol version.
Changes:
- Introduces a private
NegotiatingStatelessHttpServicewrapper that post-processesInitializeResultwithnegotiate_protocol_versionand synchronizes the stored peer info protocol version. - Wraps both stateless direct-dispatch entry points in
streamable_http_server/tower.rsso JSON and SSE framing both return the negotiated version. - Updates/extends stateless protocol-version tests to cover handlers that override
initialize, for both JSON and SSE responses, plus unknown-version fallback preservation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/rmcp/src/transport/streamable_http_server/tower.rs | Adds a stateless-only service wrapper to negotiate InitializeResult::protocol_version and keep peer info consistent, applied to both direct-dispatch paths. |
| crates/rmcp/tests/test_stateless_protocol_version.rs | Adds regression coverage for overridden initialize across JSON and SSE stateless responses, and verifies unknown-version fallback behavior. |
jamadeo
approved these changes
Jul 29, 2026
Merged
9 tasks
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.
Fixes #1079.
Motivation and Context
Stateless Streamable HTTP dispatches each request with
serve_directly_with_ct, bypassing the initialization post-processing used by stdio and stateful HTTP. The defaultServerHandler::initializenegotiates versions itself, but an override replaces that default. Before this PR, such an override could return the server's latest version even when the client requested another version the SDK supports.This PR puts the invariant at the stateless transport boundary. A private
Servicewrapper records the requested initialize version, delegates to the handler, negotiates anyInitializeResultwith the existing helper, and synchronizes peer info. Both stateless direct-dispatch entry points use the wrapper, so JSON and SSE response framing receive the same corrected result.How Has This Been Tested?
Added tests
Breaking Changes
None
Types of changes
Checklist