fix(server): prevent SSE disconnect from crashing inspector proxy - #1523
fix(server): prevent SSE disconnect from crashing inspector proxy#1523syf2211 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
|
Closing: v1 is deprecated. Thank you for this contribution, and apologies for the long wait for a response. v1 will receive security fixes only. We reviewed every open v1 PR for security impact before closing — see the backlog triage in #1819 — and a small number were retained for a final If the underlying problem still exists in v2, we'd genuinely like to know. Please open an issue describing it against v2. Note that we accept external contributions as issues rather than pull requests — maintainers handle design and implementation through a prompt-driven workflow. See Thanks again for taking the time to contribute to the Inspector. |
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.