modelcontextprotocol / modelcontextprotocol/typescript-sdk

Issue: No Reliable Mapping Between sessionId and streamId for Stateless Resumability

Open
#892 0 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs decision P2 v2
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Is your feature request related to a problem? Please describe.
Yes. When building a stateless, multi-pod MCP server using Redis for event storage, the MCP SDK does not provide a way to reliably map the external sessionId (used in HTTP headers and returned to the client) to the internal streamId (used for event storage and replay). The SDK’s event store methods (storeEvent, replayEventsAfter) only receive the streamId, while the onsessioninitialized callback only receives the sessionId. There is no point in the API where both values are available together. This makes it impossible to implement true stateless session resumability across pods or after restarts, since the server cannot look up or reconstruct the correct event stream for a given session.

Describe the solution you'd like
Please provide a way in the SDK to:

  • Expose both the sessionId and the corresponding streamId together (e.g., in onsessioninitialized or a new callback).
  • Or, guarantee that sessionId === streamId for all sessions.
  • Or, provide a mapping utility or hook so stateless resumability can be implemented robustly.

Describe alternatives you've considered

  • Attempted to use the session ID as the stream ID by passing it to sessionIdGenerator, but the SDK may still generate its own internal stream ID, breaking this assumption.
  • Considered using a global variable or context to temporarily associate the session ID and stream ID during initialization, but this is not safe for concurrent or multi-user environments.
  • Currently, the only robust solution is to use in-memory storage, which does not support stateless, cross-pod resumability.

Additional context
Stateless resumability is critical for scalable, production MCP deployments. Without a reliable mapping between session ID and stream ID, it is not possible to resume sessions across pods or after restarts using Redis or any other external event store. This limitation is a blocker for running MCP in a cloud-native, scalable environment.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the event store methods storeEvent and replayEventsAfter alongside the onsessioninitialized callback. Compare how sessionId and streamId are created and passed, then define a reliable mapping mechanism that works with external storage and concurrent sessions; done means resumability works across pods or restarts without in-memory state.

Written by the indexing model from the issue text.

Assessment

Tech stack
redis, typescript
Domain
api, backend, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.