Skip to content

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

@neerazz-parafin

Description

@neerazz-parafin

Description

When using fastmcp dev to launch the MCP inspector, the server crashes with an "Error: Not connected" in the SSE transport when multiple STDIO connection requests are made in quick succession.

Steps to Reproduce

  1. Create an MCP server that mounts multiple proxied servers (e.g., 20 servers)
  2. Run fastmcp dev server.py
  3. Open the inspector URL in browser
  4. Observe multiple "New STDIO connection request" log entries
  5. Server crashes with SSE error

Error Output

New STDIO connection request
Query parameters: {"command":"fastmcp","args":"run server.py --no-banner",...}
STDIO transport: command=.../fastmcp, args=run,server.py,--no-banner
Created client transport
Created server transport
Received POST message for sessionId 5e74a561-90d8-4d1a-876f-3bd80dbf56ae
Received POST message for sessionId 5e74a561-90d8-4d1a-876f-3bd80dbf56ae
Received POST message for sessionId 5e74a561-90d8-4d1a-876f-3bd80dbf56ae
Received POST message for sessionId 5e74a561-90d8-4d1a-876f-3bd80dbf56ae
New STDIO connection request  <-- Second connection triggers the issue
...
file:///.../@modelcontextprotocol/sdk/dist/esm/server/sse.js:145
            throw new Error('Not connected');
                  ^

Error: Not connected
    at SSEServerTransport.send (file:///.../@modelcontextprotocol/sdk/dist/esm/server/sse.js:145:19)
    at PassThrough.<anonymous> (file:///.../@modelcontextprotocol/inspector/server/build/index.js:520:33)
    at PassThrough.emit (node:events:508:28)
    ...

Expected Behavior

The inspector should handle multiple connection requests gracefully, either:

  • Rejecting duplicate connections cleanly
  • Properly closing the old SSE connection before establishing a new one
  • Queuing or debouncing rapid connection attempts

Actual Behavior

The SSE transport attempts to send on a disconnected/replaced connection, causing an unhandled exception that crashes the entire inspector process.

Environment

  • Inspector version: 0.18.0
  • Node.js version: v25.2.1
  • OS: macOS Darwin 25.2.0 (arm64)
  • MCP SDK: @modelcontextprotocol/sdk (bundled with inspector)

Workaround

Using fastmcp run server.py (without the inspector) works correctly. The issue is specific to the inspector's SSE connection handling.

Analysis

The issue appears to be in sse.js:145 where SSEServerTransport.send() throws when this.res is null/undefined. This happens when:

  1. A first SSE connection is established
  2. A second connection request comes in (browser prefetch, refresh, multiple tabs)
  3. The old connection's response object gets invalidated
  4. Code still tries to send data through the old transport

A potential fix would be to check connection state before sending, or implement proper connection lifecycle management that handles replacement scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp1-highHigh priority - should be addressed soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions