fix(server): prevent SSE disconnect from crashing inspector proxy#1523
Open
syf2211 wants to merge 1 commit into
Open
fix(server): prevent SSE disconnect from crashing inspector proxy#1523syf2211 wants to merge 1 commit into
syf2211 wants to merge 1 commit into
Conversation
When the browser closes or replaces an SSE session, stderr forwarding and mcpProxy could still call SSEServerTransport.send() after the stream was torn down, throwing an unhandled 'Not connected' error. - Add safe client send helper that ignores disconnected SSE sessions - Remove proxy session maps and stdio stderr listeners on client close - Chain cleanup after mcpProxy onclose for /stdio and /sse routes Fixes modelcontextprotocol#1014
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
Prevent the inspector proxy from crashing with an unhandled
Not connectederror when an SSE client disconnects or is replaced (e.g. browser refresh, multiple tabs, or rapid reconnects).Motivation
Fixes #1014. When the browser closes an SSE session,
SSEServerTransport.send()throws if the stream is already torn down. The stdio stderr forwarder andmcpProxycould still callsend()on in-flight server messages, producing an unhandled rejection that crashes the inspector process.Unlike Streamable HTTP, the legacy
/stdioand/sseroutes also never removed stale entries from the proxy session maps on client disconnect.Changes
sessionRegistryhelpers:sendToClientSafe()— catches disconnected SSE sends instead of crashingremoveSession()— clears proxy session mapschainOnClose()— runs cleanup before existingmcpProxyteardown/stdio: use safe sends for stderr notifications; remove stderr listener and session maps on client close/sse: remove session maps on client closemcpProxy: route client-bound sends throughsendToClientSafeTests
cd server && npm run build— passcd server && npm test— 3/3 passnpm run prettier-check— passNotes
"Not connected"message, consistent with other MCP transports.