Skip to content

fix(server): prevent SSE disconnect from crashing inspector proxy - #1523

Closed
syf2211 wants to merge 1 commit into
modelcontextprotocol:v1/mainfrom
syf2211:fix/1014-sse-disconnected-send-crash
Closed

fix(server): prevent SSE disconnect from crashing inspector proxy#1523
syf2211 wants to merge 1 commit into
modelcontextprotocol:v1/mainfrom
syf2211:fix/1014-sse-disconnected-send-crash

Conversation

@syf2211

@syf2211 syf2211 commented Jun 25, 2026

Copy link
Copy Markdown

Summary

Prevent the inspector proxy from crashing with an unhandled Not connected error 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 and mcpProxy could still call send() on in-flight server messages, producing an unhandled rejection that crashes the inspector process.

Unlike Streamable HTTP, the legacy /stdio and /sse routes also never removed stale entries from the proxy session maps on client disconnect.

Changes

  • Add sessionRegistry helpers:
    • sendToClientSafe() — catches disconnected SSE sends instead of crashing
    • removeSession() — clears proxy session maps
    • chainOnClose() — runs cleanup before existing mcpProxy teardown
  • /stdio: use safe sends for stderr notifications; remove stderr listener and session maps on client close
  • /sse: remove session maps on client close
  • mcpProxy: route client-bound sends through sendToClientSafe
  • Add unit tests for the new helpers

Tests

  • cd server && npm run build — pass
  • cd server && npm test — 3/3 pass
  • npm run prettier-check — pass

Notes

  • The fix is intentionally minimal and scoped to V1 proxy session lifecycle.
  • Error matching uses the SDK's "Not connected" message, consistent with other MCP transports.

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
@cliffhall
cliffhall changed the base branch from main to v1/main July 28, 2026 03:04
@cliffhall

cliffhall commented Jul 31, 2026

Copy link
Copy Markdown
Member

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 1.0.5 patch release. This one is a functionality, compatibility, or cleanup change rather than a vulnerability fix, so it is being closed unmerged. This is not a judgment on the quality of the work — it's a consequence of the branch it targets being frozen.

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 CONTRIBUTORS.md.

Thanks again for taking the time to contribute to the Inspector.

@cliffhall cliffhall closed this Jul 31, 2026
@cliffhall cliffhall added the closed-v1-deprecated Closed: v1 is deprecated and accepting security fixes only label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closed-v1-deprecated Closed: v1 is deprecated and accepting security fixes only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants