Repository navigation
feat: bound connect attempts with a 30 s default connectionTimeout - #2362
Conversation
…2320) connectionTimeout defaulted to 0, which InspectorClient.connect() read as "no bound at all" — so out of the box nothing the Inspector owns bounded a connect attempt, and the only thing ending a hung handshake was the SDK's 60 s per-request timeout on initialize, reporting "Request timed out". - Add DEFAULT_CONNECTION_TIMEOUT_MS (30000) to core/mcp/types.ts. An absent value resolves to it on the client, on disk read, in the web form draft, and in the CLI's header-only settings shell. An explicit 0 keeps its documented meaning (no timeout; --connect-timeout 0) and is now persisted so the opt-out round-trips; the default is the omit-sentinel, as for taskTtl. - Key the post-timeout transport teardown to the timer actually firing, not to connectionTimeout > 0 — otherwise a non-zero default would tear down every failed connect, including a recoverable 401 whose transport the auth recovery holds open. - The timeout message names the bound and where to raise it: "Connection timed out after N ms. To accommodate a slower server, you may increase the timeout value in Server Settings." - The CLI's UNREACHABLE classifier now matches that message. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01M4h8Xa6Ed9zwtv5ojX35MT Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Documentation remains contradictory, one changed default path lacks a direct assertion, and new tests use unsafe double casts.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds a 30-second default connection timeout across shared MCP settings and all clients while preserving explicit 0 as unlimited.
Changes:
- Applies and persists the new default consistently.
- Improves timeout teardown, messaging, and CLI classification.
- Expands timeout and settings round-trip tests and documentation.
File summaries
| File | Description |
|---|---|
docs/mcp-server-configuration.md |
Documents timeout defaults. |
core/mcp/types.ts |
Defines the shared default. |
core/mcp/serverList.ts |
Handles read/write defaults. |
core/mcp/node/servers.ts |
Defaults header-only settings. |
core/mcp/inspectorClient.ts |
Enforces timeout and teardown. |
clients/web/src/utils/serverSettingsDefaults.ts |
Updates web draft defaults. |
clients/web/src/utils/serverSettingsDefaults.test.ts |
Verifies web defaults. |
clients/web/src/test/integration/mcp/remote/servers-route.test.ts |
Tests route persistence. |
clients/web/src/test/integration/mcp/inspectorClient.test.ts |
Tests timeout behavior. |
clients/web/src/test/core/react/useServers.test.tsx |
Tests hook materialization. |
clients/web/src/test/core/mcp/serverList.test.ts |
Tests settings round-trips. |
clients/cli/src/error-handler.ts |
Classifies connection timeouts. |
clients/cli/README.md |
Documents CLI behavior. |
clients/cli/__tests__/error-handler.test.ts |
Tests CLI classification. |
Review details
Suppressed comments (3)
clients/web/src/test/integration/mcp/inspectorClient.test.ts:478
- This new
as unknown as Transportbypasses structural checking of the fake transport, so SDK interface changes will not be caught. Type the test double asTransportwhen it is declared (or usesatisfies Transport) instead of using an unjustified double cast.
transport:
hangingTransport as unknown as import("@modelcontextprotocol/client").Transport,
clients/web/src/test/integration/mcp/inspectorClient.test.ts:518
- This new
as unknown as Transportbypasses structural checking of the fake transport, so SDK interface changes will not be caught. Type the test double asTransportwhen it is declared (or usesatisfies Transport) instead of using an unjustified double cast.
transport:
hangingTransport as unknown as import("@modelcontextprotocol/client").Transport,
clients/web/src/test/integration/mcp/inspectorClient.test.ts:602
- This new
as unknown as Transportbypasses structural checking of the fake transport, so SDK interface changes will not be caught. Type the test double asTransportwhen it is declared (or usesatisfies Transport) instead of using an unjustified double cast.
transport:
unauthorizedTransport as unknown as import("@modelcontextprotocol/client").Transport,
- Files reviewed: 14/14 changed files
- Comments generated: 3
- Review effort level: Balanced
- Assert headersToServerSettings carries DEFAULT_CONNECTION_TIMEOUT_MS. - Type the fake transports in inspectorClient.test.ts as the SDK's Transport via two helpers instead of an as-unknown-as double cast; the two pre-existing copies of the same fakes in that describe block use the helpers too. - Bring serverList.ts's converter comments and specification/v2_servers_file.md in line with the new contract: 30 s default, explicit 0 persisted, and requestTimeout's 0 unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01M4h8Xa6Ed9zwtv5ojX35MT Signed-off-by: cliffhall <[email protected]>
Copilot review round 1 — responsesAll three findings addressed in 1673811 (each answered in its own thread as well):
The three "Suppressed comments" are the same double-cast finding at the other three sites and are covered by the same change. |
There was a problem hiding this comment.
🟢 Approval recommended
The timeout contract is applied consistently across runtime paths, persistence, clients, documentation, and focused regression tests.
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Closes #2320
connectionTimeoutdefaulted to0, whichInspectorClient.connect()read as "no bound at all" — so out of the box nothing the Inspector owns bounded a connect attempt. The only thing ending a hung handshake was the SDK's 60 s per-request timeout oninitialize, which covers nothing outside that request (transport.start()for one) and reportsRequest timed out: a sentence about a JSON-RPC request, not a connection. Per the decision on the issue, the default is now 30 s and the message says where to raise it.What changed
DEFAULT_CONNECTION_TIMEOUT_MS = 30000incore/mcp/types.ts. An absent value resolves to it everywhere one is materialized:connect()whenserverSettingsis undefined,storedFieldsToInspectorSettingson disk read, the web form'sEMPTY_SETTINGSdraft, and the CLI's header-only settings shell. It follows thetaskTtlpattern — the default is the omit-sentinel on write, so a file that never named a timeout stays byte-stable.0keeps its documented meaning ("no timeout" — the CLI's--connect-timeout 0, a cleared field) and is now persisted, since a suppressed0would silently read back as 30 s on the next load. This is the one on-disk behavior change: a file that carriedconnectionTimeout: 30000verbatim has that key dropped on the next write, exactly astaskTtl: 60000already is.connectionTimeout > 0. That gate was an approximation of "on timeout" that happened to hold while the default was0; with a real default it would have torn down every failed connect — including a recoverable 401, whose transport the auth recovery holds open and whose status has to stay atconnecting. A new integration case (holds status at connecting on a recoverable 401 even with a connect timeout armed) pins that.connectionTimeoutMessage(ms): Connection timed out after 30000 ms. To accommodate a slower server, you may increase the timeout value in Server Settings. All three clients surfaceerr.messageas-is.UNREACHABLEclassifier now matchesConnection timed out— itsconnect timed outalternation never matched the core's text, so the one timeout the Inspector owns fell through to the generic exit code.docs/mcp-server-configuration.md(the field table now states the default and what0means) and the CLI README's--connect-timeoutrow.Tests
inspectorClient.test.ts(integration): default bound fires at exactly 30 s with no settings (fake timers, asserts stillconnectingat 29 999 ms); explicit0stays unbounded past 60 s; the message text; the 401-hold with a timeout armed.serverList.test.ts: absent reads back as 30000; the default is omitted on write; an explicit0round-trips.servers-route.test.ts/useServers.test.tsx/serverSettingsDefaults.test.ts: the same three facts through the route, the hook and the form draft.error-handler.test.ts(cli): the core message classifies asUNREACHABLE.Screenshots
Measured against a server that accepts the TCP connection and never answers
initialize(a barenode:httpserver that never writes), connected through theautoConnectdeep link.Request timed out0 ms30000 ms🤖 Generated with Claude Code
https://claude.ai/code/session_01M4h8Xa6Ed9zwtv5ojX35MT