Skip to content

Fix JSON parse error on SSE events with empty data - #1184

Merged
felixweinberger merged 2 commits into
mainfrom
fweinberger/fix-empty-sse-data
Nov 27, 2025
Merged

Fix JSON parse error on SSE events with empty data#1184
felixweinberger merged 2 commits into
mainfrom
fweinberger/fix-empty-sse-data

Conversation

@felixweinberger

Copy link
Copy Markdown
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 ownerNovember 27, 2025 19:56
@pkg-pr-new

pkg-pr-newBot commented Nov 27, 2025

Copy link
Copy Markdown

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
felixweinbergerforce-pushed the fweinberger/fix-empty-sse-data branch from 2ec83ef to f0c6062CompareNovember 27, 2025 19:58
@felixweinberger
felixweinberger merged commit 9203091 into mainNov 27, 2025
10 checks passed
@felixweinberger
felixweinberger deleted the fweinberger/fix-empty-sse-data branch November 27, 2025 21:22
Sign up for freeto 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

@felixweinberger@mattzcarey@maxisbey