inspector icon indicating copy to clipboard operation
inspector copied to clipboard

Inspector should disconnect when server shuts down and/or refuses connections

Open odrobnik opened this issue 6 months ago • 3 comments

After a connection has been established, I shut down the server. The UI doesn't recognize the disconnection.

You still see the Reconnect and Disconnect buttons.

In the console you see tons of messages like this:

Error from MCP server: SseError: SSE error: TypeError: fetch failed: connect ECONNREFUSED ::1:8080, connect ECONNREFUSED 127.0.0.1:8080, connect EHOSTUNREACH fe80::1:8080 - Local (:::55056), connect ECONNREFUSED 192.168.1.142:8080, connect EHOSTUNREACH fe80::479:f5e1:f09e:ee06:8080 - Local (:::55059), connect EHOSTUNREACH fe80::16:546c:57d:64cb:8080 - Local (:::55061), connect EHOSTUNREACH fe80::5cff:b3ff:fe65:8cdf:8080 - Local (:::55062), connect ECONNREFUSED fda0:15a6:9edc:444e:10da:5b53:d2a6:2bac:8080
    at _eventSource.onerror (file:///Users/oliver/.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js:85:31)
    at EventSource.scheduleReconnect_fn (file:///Users/oliver/.npm/_npx/5a9d879542beca3a/node_modules/eventsource/dist/index.js:248:53)
    at file:///Users/oliver/.npm/_npx/5a9d879542beca3a/node_modules/eventsource/dist/index.js:98:174
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: undefined,
  event: {
    type: 'error',
    message: 'TypeError: fetch failed: connect ECONNREFUSED ::1:8080, connect ECONNREFUSED 127.0.0.1:8080, connect EHOSTUNREACH fe80::1:8080 - Local (:::55056), connect ECONNREFUSED 192.168.1.142:8080, connect EHOSTUNREACH fe80::479:f5e1:f09e:ee06:8080 - Local (:::55059), connect EHOSTUNREACH fe80::16:546c:57d:64cb:8080 - Local (:::55061), connect EHOSTUNREACH fe80::5cff:b3ff:fe65:8cdf:8080 - Local (:::55062), connect ECONNREFUSED fda0:15a6:9edc:444e:10da:5b53:d2a6:2bac:8080',
    code: undefined,
    defaultPrevented: false,
    cancelable: false,
    timeStamp: 502389.422084
  }
}

I would expect for the UI to show the connection has having been disconnected.

When the server comes back up again, then the connection gets reestablished, but the problem with this is that since this is a new session, there is no information about client capabilities from the initialized notification. So I don't know on the server if the client has sampling, roots or elicitation support.

odrobnik avatar Jul 10 '25 13:07 odrobnik

An alternative would be that upon reconnection to re-send the initialize request. Right now I only see

GET /mcp HTTP/1.1
host: mac-studio.local:8080
connection: keep-alive
Accept: text/event-stream
accept-language: *
sec-fetch-mode: cors
user-agent: node
pragma: no-cache
cache-control: no-cache
accept-encoding: gzip, deflate

So the inspector establishes a new SSE stream but doesn't initialize it (by exchanging the capabilities)

odrobnik avatar Jul 10 '25 13:07 odrobnik

Would https://github.com/modelcontextprotocol/inspector/pull/765 fix this by having the UI show the connection was disconnected?

npolshakova avatar Sep 26 '25 15:09 npolshakova

@npolshakova I guess so, does that stop the automatic reconnection?

odrobnik avatar Oct 01 '25 10:10 odrobnik