Skip to content

Conversation

min-mwei
Copy link

@min-mwei min-mwei commented Oct 3, 2025

Streamable HTTP: drain SSE frames until the initialize response, ignoring early notifications to prevent handshake timeouts

Motivation and Context

The streamable HTTP transport can deliver server-sent notifications (e.g., logging or connection-established events) before the JSON‑RPC initialize response. The previous implementation read only the f
irst SSE frame and treated it as the response, which could stall initialization and cause later requests (like tools/list) to time out. This change makes the handshake resilient by waiting for the actual response.

How Has This Been Tested?

  • rmcp crate builds and unit tests pass with default features (cargo test -p rmcp).
  • The change is localized to SSE handling; manual verification is recommended against an MCP server that emits pre-response notifications to confirm the handshake completes and subsequent requests succeed.

Breaking Changes

None. Behavior is more permissive and robust during initialization; other transports are unaffected.

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 (https://modelcontextprotocol.io)
  • 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

Additional context

  • Implementation detail: StreamableHttpPostResponse::expect_initialized now drains SSE frames until a ServerJsonRpcMessage::Response is received, skipping empty payloads and logging intermediate no
    tifications with tracing::debug.
  • Scope: crates/rmcp/src/transport/streamable_http_client.rs only; no changes to public API or dependencies.

Protocol Compliance

  • MCP allows servers to send notifications at any time; clients must tolerate and ignore them until the corresponding response arrives. This change adheres to that model for the streamable HTTP transport.
  • JSON-RPC semantics are preserved: initialization completes only upon receiving a Response message; notifications and requests received before that are not treated as completion.
  • SSE specifics: event data is parsed as JSON per message; the client continues draining frames until the expected response is found.

…ring early notifications to prevent handshake timeouts
@github-actions github-actions bot added T-core Core library changes T-transport Transport layer changes labels Oct 3, 2025
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-transport Transport layer changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants