Skip to content

fix(server): stop replay cleanly when streamable HTTP replay stream c…#1681

Open
meirk-brd wants to merge 1 commit intomodelcontextprotocol:mainfrom
meirk-brd:fix/streamable-http-replay-disconnect-cleanup
Open

fix(server): stop replay cleanly when streamable HTTP replay stream c…#1681
meirk-brd wants to merge 1 commit intomodelcontextprotocol:mainfrom
meirk-brd:fix/streamable-http-replay-disconnect-cleanup

Conversation

@meirk-brd
Copy link

Summary

This fixes streamable HTTP event replay when a client disconnects in the middle of a replayed SSE response.

The shared WebStandardStreamableHTTPServerTransport now treats a closed replay stream as a normal abort condition: it stops replay immediately, closes the controller safely, and avoids leaving a stale replay entry in _streamMapping.

A regression test was added at the shared transport layer to cover the exact failure mode.

Motivation and Context

When a client reconnects with Last-Event-ID, the server replays missed events through replayEvents().

Before this change, if the replay stream closed mid-replay, the transport could continue attempting to write to a closed stream and then surface replay failures downstream. That forced consumers (like me ;) ) to add local monkey patches around the SDK transport.

This change fixes the issue where it originates, in the shared streamable HTTP server transport, so downstream projects do not need replay-disconnect workarounds.

How Has This Been Tested?

Tested locally in the @modelcontextprotocol/server package with:

pnpm --filter @modelcontextprotocol/server check
pnpm --filter @modelcontextprotocol/server test -- test/server/streamableHttp.test.ts

Scenarios covered:

  • normal streamable HTTP replay behavior still works
  • a replay stream that closes after the first replayed event aborts replay cleanly
  • no extra replay error is emitted for that disconnect path
  • no stale replay stream mapping is left behind after the abort

Breaking Changes

None.

This is an internal bug fix in the shared streamable HTTP server transport. There are no public API or configuration changes.

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

Additional context

This intentionally fixes the issue in the shared WebStandardStreamableHTTPServerTransport instead of patching downstream wrappers. The NodeStreamableHTTPServerTransport does not require code changes because it delegates to this shared implementation.

The EventStore contract was left unchanged. The fix works by making replay writes fail fast and cleanly once the replay response stream has already been closed.

@meirk-brd meirk-brd requested a review from a team as a code owner March 15, 2026 07:54
@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

⚠️ No Changeset found

Latest commit: 29f2158

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 15, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 29f2158

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.

1 participant