Skip to content

Conversation

@felixweinberger
Copy link
Contributor

@felixweinberger felixweinberger commented Dec 4, 2025

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 close_sse_stream 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?

  • Existing tests continue to pass (42 tests)
  • The implementation gates priming events and callbacks on protocol version >= 2025-11-25

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

Changes:

  • _maybe_send_priming_event: renamed from _send_priming_event, now checks protocol version
  • _create_session_message: only provides close_sse_stream callbacks when protocol version supports resumability

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 8 times, most recently from 57ab2d3 to 68c3d29 Compare December 4, 2025 12:40
@felixweinberger felixweinberger marked this pull request as ready for review December 4, 2025 12:44
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 68c3d29 to 0e7ea31 Compare December 4, 2025 14:35
@maxisbey maxisbey merged commit 89ff338 into main Dec 4, 2025
21 checks passed
@maxisbey maxisbey deleted the fweinberger/fix-priming-backwards-compat branch December 4, 2025 14:44
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