fix: prevent SSE transport crash on concurrent STDIO connections#1130
Open
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: prevent SSE transport crash on concurrent STDIO connections#1130MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
SSEServerTransportwas registered in thewebAppTransportsmap beforeawait transport.start()completed. This allowed the/messageendpoint to look up and use a transport that wasn't fully connected yet, causingsend()to throw.Changes:
webAppTransports.set()to afterawait webAppTransport.start()in both/stdioand/sseendpoints, so only fully-connected transports are discoverable.catch()handlers tosend()andclose()calls in the stderr forwarding handler to prevent unhandled promise rejections when the SSE connection drops while the server process is still runningTest plan
npm run buildpassesnpm run lintpassesnpm test)fastmcp dev server.py, open inspector — no crash