Skip to content

Conversation

@felixweinberger
Copy link
Contributor

Priming events for resumability (SEP-1699) have an event ID but empty data. The client was attempting JSON.parse("") which throws "Unexpected end of JSON input".

Motivation and Context

When connecting to a server that supports SSE resumability, the server sends priming events like:

id: 123
data: 

The client's SSE handler was only checking for empty data inside the message event type check, but priming events may not have an explicit event type. This caused a JSON parse error on every connection to servers with resumability enabled.

How Has This Been Tested?

  • Added unit test that sends a priming event with empty data followed by a real message
  • Verified no JSON parse error occurs
  • Verified resumption token callback is still invoked for both events
  • All 1130 tests pass

Breaking Changes

None.

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

@felixweinberger felixweinberger requested a review from a team as a code owner November 27, 2025 19:56
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 27, 2025

Open in StackBlitz

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

commit: a8818ac

Priming events for resumability (SEP-1699) have an event ID but empty
data. The client was attempting JSON.parse("") which throws "Unexpected
end of JSON input".

Skip processing for all events with empty data, not just message events.
This handles priming events, keep-alives, and any other events that may
have empty data fields.
@felixweinberger felixweinberger force-pushed the fweinberger/fix-empty-sse-data branch from 2ec83ef to f0c6062 Compare November 27, 2025 19:58
@felixweinberger felixweinberger merged commit 9203091 into main Nov 27, 2025
10 checks passed
@felixweinberger felixweinberger deleted the fweinberger/fix-empty-sse-data branch November 27, 2025 21:22
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