Skip to content

fix: handle SSE transport send errors in stdio stderr handler#1129

Open
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW:fix/sse-transport-crash-1014
Open

fix: handle SSE transport send errors in stdio stderr handler#1129
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW:fix/sse-transport-crash-1014

Conversation

@MumuTW
Copy link

@MumuTW MumuTW commented Mar 6, 2026

Summary

Fixes #1014

When multiple STDIO connection requests are made in quick succession (e.g. an MCP server mounting ~20 proxied servers), the SSE connection can close before stderr data finishes being forwarded. The webAppTransport.send() calls in the stderr handler were not catching the returned promise, so a "Not connected" rejection from SSEServerTransport.send() would crash the server as an unhandled promise rejection.

  • Add .catch() to both send() call sites in the stderr data handler to silently ignore errors from a closed SSE connection
  • Move transport cleanup in the MODULE_NOT_FOUND branch into .finally() so resources are released regardless of whether the notification send succeeded

Test plan

  • npm run build-server passes
  • Prettier formatting verified (npx prettier --check server/src/index.ts)
  • Manual: start inspector with a multi-server MCP setup, rapidly refresh — no more "Not connected" crash

…ontextprotocol#1014)

When the SSE connection is closed (e.g. client disconnects during rapid
reconnection), webAppTransport.send() rejects with "Not connected".
The stderr handler was calling send() without awaiting or catching the
returned promise, causing unhandled rejections that crash the server.

Add .catch() to both send() call sites in the stderr data handler so
that errors from a closed SSE connection are silently ignored instead
of crashing the process. Also move the cleanup logic in the
MODULE_NOT_FOUND branch into .finally() so transports are cleaned up
regardless of whether the notification send succeeded.
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