Skip to content

Conversation

@felixweinberger
Copy link
Contributor

Fixes SSE reconnection issues that were causing errors with SEP-1699 usage.

Motivation and Context

When using SSE streaming with SEP-1699 priming events, several issues occurred:

  1. The client would reconnect even after a response was already received
  2. Reconnection timeouts would fire after close() was called, causing "Failed to reconnect SSE stream" errors

How Has This Been Tested?

  • Added unit tests for both fixes
  • Tested with the inspector against a local MCP server

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

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

Per SEP-1699, the client should only reconnect when the server
disconnects BEFORE sending a response (for long-running operations).
The previous implementation would reconnect after ANY stream completion
when a priming event was received, even when the response was already
delivered.

This fix tracks whether a response was received and skips reconnection
if so. This prevents:
1. Unnecessary network round-trips
2. Race conditions with rapid stream cycling (which caused crashes in
   consumers like the inspector)

Adds test case to verify the correct behavior.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 28, 2025

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/sdk@1191

commit: 3cd7447

Track the reconnection timeout ID and clear it when close() is called.
This prevents reconnection attempts after the transport is closed,
which was causing "Failed to reconnect SSE stream" errors on disconnect.

Adds test case to verify reconnection is cancelled after close().
@felixweinberger felixweinberger force-pushed the fweinberger/sep1699-debug branch from 37276ea to 3be665f Compare November 28, 2025 18:34
@felixweinberger felixweinberger marked this pull request as ready for review November 28, 2025 19:44
@felixweinberger felixweinberger requested a review from a team as a code owner November 28, 2025 19:44
const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
if (replayMessageId !== undefined && isJSONRPCResponse(message)) {
message.id = replayMessageId;
if (isJSONRPCResponse(message)) {
Copy link
Member

Choose a reason for hiding this comment

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

i wasn't sure if this would get triggered by notifications etc. but those would be a different schema, so shouldn't.

@felixweinberger felixweinberger merged commit f67fc2f into main Dec 1, 2025
10 checks passed
@felixweinberger felixweinberger deleted the fweinberger/sep1699-debug branch December 1, 2025 16:31
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.

3 participants