-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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
- Create an MCP server that mounts multiple proxied servers (e.g., 20 servers)
- Run
fastmcp dev server.py - Open the inspector URL in browser
- Observe multiple "New STDIO connection request" log entries
- 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:
- A first SSE connection is established
- A second connection request comes in (browser prefetch, refresh, multiple tabs)
- The old connection's response object gets invalidated
- 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.