Skip to content

fix: prevent SSE transport crash on concurrent STDIO connections#1130

Open
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW:fix/sse-transport-race-condition
Open

fix: prevent SSE transport crash on concurrent STDIO connections#1130
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW:fix/sse-transport-race-condition

Conversation

@MumuTW
Copy link
Contributor

@MumuTW MumuTW commented Mar 6, 2026

Summary

Fixes #1014

When multiple STDIO connection requests arrive in quick succession (e.g. an MCP server mounting ~20 proxied servers), the SSE transport crashes with a "Not connected" error.

Root cause: SSEServerTransport was registered in the webAppTransports map before await transport.start() completed. This allowed the /message endpoint to look up and use a transport that wasn't fully connected yet, causing send() to throw.

Changes:

  • Move webAppTransports.set() to after await webAppTransport.start() in both /stdio and /sse endpoints, so only fully-connected transports are discoverable
  • Add .catch() handlers to send() and close() calls in the stderr forwarding handler to prevent unhandled promise rejections when the SSE connection drops while the server process is still running

Test plan

  • npm run build passes
  • npm run lint passes
  • All 486 tests pass (npm test)
  • Manual: create MCP server with ~20 proxied servers, run fastmcp dev server.py, open inspector — no crash

Move webAppTransports map registration to after SSEServerTransport.start()
completes in both /stdio and /sse endpoints. Previously, the transport was
registered before being fully connected, allowing the /message endpoint to
access it prematurely and causing "Not connected" errors when multiple
STDIO connection requests arrived in quick succession.

Also add .catch() handlers to stderr forwarding send() and close() calls
to prevent unhandled rejections when the SSE connection drops while the
server process is still running.

Fixes modelcontextprotocol#1014

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

SSE transport crashes with "Not connected" error when multiple connections occur

1 participant