Skip to content

Conversation

@felixweinberger
Copy link
Contributor

Fixes backwards compatibility issue where SEP-1699 priming events break old clients.

Motivation and Context

SEP-1699 introduced "priming events" - SSE events with an ID but empty data (data: \n). Old clients (SDK versions before the empty-data fix) try to JSON.parse("") and crash with "Unexpected end of JSON input".

Additionally, the closeSSEStream callbacks should not be provided to old clients because they can't resume if the stream is closed early (they never received a priming event with an event ID).

How Has This Been Tested?

  • Added test for backwards compatibility: verifies priming events are NOT sent for protocol version < 2025-11-25
  • Added test for callback gating: verifies closeSSEStream callbacks are NOT provided for old protocol versions
  • Updated existing priming event tests to use protocol version 2025-11-25
  • All 140 tests pass

Breaking Changes

None. This is a backwards-compatible fix that makes new servers work correctly with old clients.

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

The fix gates on protocol version >= 2025-11-25:

  • For initialize requests: extracts version from params.protocolVersion
  • For other requests: uses mcp-protocol-version header

String comparison works for ISO date format versions (e.g., '2025-03-26' < '2025-11-25' → true).

@felixweinberger felixweinberger force-pushed the fweinberger/fix-priming-backwards-compat branch from 5d1206e to 36e5bf6 Compare December 4, 2025 12:06
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 4, 2025

Open in StackBlitz

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

commit: 63f7f2e

@felixweinberger felixweinberger force-pushed the fweinberger/fix-priming-backwards-compat branch from 36e5bf6 to eaec72b Compare December 4, 2025 12:08
Priming events (SEP-1699) have empty SSE data which older clients cannot
handle - they try to JSON.parse("") and crash. Only send priming events
to clients with protocol version >= 2025-11-25, which includes the fix
for handling empty SSE data.

For the initialize request, the protocol version is extracted from the
request params. For subsequent requests, it's taken from the
mcp-protocol-version header.
@felixweinberger felixweinberger force-pushed the fweinberger/fix-priming-backwards-compat branch from fdc9ba3 to 63f7f2e Compare December 4, 2025 12:15
@felixweinberger felixweinberger marked this pull request as ready for review December 4, 2025 12:22
@felixweinberger felixweinberger requested a review from a team as a code owner December 4, 2025 12:22
@felixweinberger felixweinberger requested a review from a team December 4, 2025 12:24
@KKonstantinov
Copy link
Contributor

LGTM!

@KKonstantinov KKonstantinov merged commit 2f76ac8 into main Dec 4, 2025
10 checks passed
@KKonstantinov KKonstantinov deleted the fweinberger/fix-priming-backwards-compat branch December 4, 2025 13:19
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.

4 participants