modelcontextprotocol / modelcontextprotocol/typescript-sdk
The bug in InMemoryEventStore break SSE stream resumability
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
Describe the bug
The standalong sse stream Id is coded to _GET_stream and the current InMemoryEventStore generate event Ids in the format -
${streamId}-${Date.now()}_${Math.random().toString(36).substring(2, 10)}
The replayEventsAfter(...) is called when client try to re-connect and resume the stream which further calls getStreamIdFromEventId(...) -
// Extract the stream ID from the event ID
const streamId = this.getStreamIdFromEventId(lastEventId);
if (!streamId) {
return '';
}
The issue is that getStreamIdFromEventId(...) will always return an empty string as the streamId due to the current eventId format and the code will return from this if check.
To Reproduce
Steps to reproduce the behavior:
- Create a tool with at least 2 elicitation requests.
- Call the tool.
- Try to reconnect with SSE stream - nothing will be returned.
Expected behavior
MCP client should be able to re-connect to SSE stream.
Fix
The fix could be to use a different delimiter than underscore when combining streamId with rest of the eventId.
Used dash("-") in below sample fix -
/**
* Generates a unique event ID for a given stream ID
*/
private generateEventId(streamId: string): string {
---> return `${streamId}**-**${Date.now()}_${Math.random().toString(36).substring(2, 10)}`;
}
/**
* Extracts the stream ID from an event ID
*/
private getStreamIdFromEventId(eventId: string): string {
---> const parts = eventId.split('**-**');
return parts.length > 0 ? parts[0] : '';
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/examples/shared/inMemoryEventStore.ts and compare generateEventId, getStreamIdFromEventId, and replayEventsAfter with the stream handling in src/server/streamableHttp.ts. Reproduce the two-elicitation reconnect scenario, then verify that the Last-Event-ID is parsed consistently and previously emitted events are returned when the SSE stream resumes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100