Skip to content

fix: negotiate stateless initialize versions - #1080

Merged
DaleSeo merged 1 commit into
mainfrom
fix/issue-1079
Jul 29, 2026
Merged

fix: negotiate stateless initialize versions#1080
DaleSeo merged 1 commit into
mainfrom
fix/issue-1079

Conversation

@DaleSeo

@DaleSeo DaleSeo commented Jul 29, 2026

Copy link
Copy Markdown
Member

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 default ServerHandler::initialize negotiates 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 Service wrapper records the requested initialize version, delegates to the handler, negotiates any InitializeResult with 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-transport Transport layer changes labels Jul 29, 2026
@DaleSeo DaleSeo self-assigned this Jul 29, 2026
@DaleSeo
DaleSeo marked this pull request as ready for review July 29, 2026 18:58
@DaleSeo
DaleSeo requested a review from a team as a code owner July 29, 2026 18:58
@DaleSeo
DaleSeo requested a review from Copilot July 29, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 NegotiatingStatelessHttpService wrapper that post-processes InitializeResult with negotiate_protocol_version and synchronizes the stored peer info protocol version.
  • Wraps both stateless direct-dispatch entry points in streamable_http_server/tower.rs so 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.

@DaleSeo
DaleSeo merged commit 596a7e1 into main Jul 29, 2026
23 checks passed
@DaleSeo
DaleSeo deleted the fix/issue-1079 branch July 29, 2026 19:47
@github-actions github-actions Bot mentioned this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stateless streamable HTTP skips protocol version negotiation when the handler overrides initialize

3 participants