Skip to content

SSE Transport Statefulness Breaks in Serverless Deployments #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Vinlic opened this issue Apr 7, 2025 · 2 comments
Open

SSE Transport Statefulness Breaks in Serverless Deployments #273

Vinlic opened this issue Apr 7, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@Vinlic
Copy link

Vinlic commented Apr 7, 2025

Describe the bug
The current SSE transport implementation (SSEServerTransport) is stateful—it relies on in-memory session storage (transports: {[sessionId: string]: SSEServerTransport}). This creates a critical issue in serverless environments (AWS Lambda, Cloudflare Workers, etc.) where:

  1. The initial GET /sse request may be handled by Instance A.
  2. Subsequent POST /messages requests (with the same sessionId) may land on Instance B, which lacks the in-memory transport state.
  3. Result: 400: No transport found for sessionId, breaking the SSE workflow.

Additionally, this also renders load balancing completely unusable in the SSE Server.

To Reproduce
Steps to reproduce the behavior:

  1. Deploy the example MCP SSE server to a serverless platform (e.g., AWS Lambda + API Gateway).
  2. Connect a client to /sse.
  3. Send a message to /messages?sessionId=<ID>.
    Expected: Message delivered via SSE.
    Actual: 400 error unless the request hits the same instance.
@Vinlic Vinlic added the bug Something isn't working label Apr 7, 2025
@Vinlic
Copy link
Author

Vinlic commented Apr 7, 2025

Perhaps WebSocket would be a better choice for the underlying protocol? I don't understand why SSE was chosen.

Let's reopen this PR: #232

@kentcdodds
Copy link

SSE has been replaced by Streamable HTTP in the spec and this was recently merged: #266

This is in part to support serverless architecture better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants