Skip to content

feat: bound connect attempts with a 30 s default connectionTimeout - #2362

Merged
cliffhall merged 2 commits into
v2/mainfrom
v2/fix/2320-connection-timeout-default
Sep 14, 2026
Merged

cliffhall merged 2 commits into
v2/mainfrom
v2/fix/2320-connection-timeout-default

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #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. The only thing ending a hung handshake was the SDK's 60 s per-request timeout on initialize, which covers nothing outside that request (transport.start() for one) and reports Request 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 = 30000 in core/mcp/types.ts. An absent value resolves to it everywhere one is materialized: connect() when serverSettings is undefined, storedFieldsToInspectorSettings on disk read, the web form's EMPTY_SETTINGS draft, and the CLI's header-only settings shell. It follows the taskTtl pattern — the default is the omit-sentinel on write, so a file that never named a timeout stays byte-stable.
  • An explicit 0 keeps its documented meaning ("no timeout" — the CLI's --connect-timeout 0, a cleared field) and is now persisted, since a suppressed 0 would silently read back as 30 s on the next load. This is the one on-disk behavior change: a file that carried connectionTimeout: 30000 verbatim has that key dropped on the next write, exactly as taskTtl: 60000 already is.
  • The post-timeout transport teardown is keyed to the timer actually firing, not to connectionTimeout > 0. That gate was an approximation of "on timeout" that happened to hold while the default was 0; 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 at connecting. A new integration case (holds status at connecting on a recoverable 401 even with a connect timeout armed) pins that.
  • The message is the one the issue asked for, built by an exported 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 surface err.message as-is.
  • The CLI's UNREACHABLE classifier now matches Connection timed out — its connect timed out alternation never matched the core's text, so the one timeout the Inspector owns fell through to the generic exit code.
  • Docs: docs/mcp-server-configuration.md (the field table now states the default and what 0 means) and the CLI README's --connect-timeout row.

Tests

  • inspectorClient.test.ts (integration): default bound fires at exactly 30 s with no settings (fake timers, asserts still connecting at 29 999 ms); explicit 0 stays 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 explicit 0 round-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 as UNREACHABLE.

Screenshots

Measured against a server that accepts the TCP connection and never answers initialize (a bare node:http server that never writes), connected through the autoConnect deep link.

Before After
Timeout toast 60.5 s, Request timed out 30.4 s, the new message
timeout toast before timeout toast after
Server Settings → Timeouts (a server with no stored timeout) 0 ms 30000 ms
settings before settings after

🤖 Generated with Claude Code

https://claude.ai/code/session_01M4h8Xa6Ed9zwtv5ojX35MT

…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]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Sep 14, 2026
@cliffhall
cliffhall requested a balanced review from Copilot September 14, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 Transport bypasses structural checking of the fake transport, so SDK interface changes will not be caught. Type the test double as Transport when it is declared (or use satisfies 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 Transport bypasses structural checking of the fake transport, so SDK interface changes will not be caught. Type the test double as Transport when it is declared (or use satisfies 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 Transport bypasses structural checking of the fake transport, so SDK interface changes will not be caught. Type the test double as Transport when it is declared (or use satisfies 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

Comment thread core/mcp/node/servers.ts Resolved
Comment thread docs/mcp-server-configuration.md Resolved
- 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]>
@cliffhall
cliffhall requested a balanced review from Copilot September 14, 2026 01:25
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review round 1 — responses

All three findings addressed in 1673811 (each answered in its own thread as well):

  • headersToServerSettings had no assertion on the new default — added expect(settings?.connectionTimeout).toBe(DEFAULT_CONNECTION_TIMEOUT_MS) to its test.
  • Double casts on the fake transports — replaced with two helpers typed as the SDK's Transport; the two pre-existing copies of the same fakes in that block use them too.
  • Docs still described the old contract — serverList.ts's converter comments and specification/v2_servers_file.md now distinguish the 30 s connection default / explicit-0 opt-out from requestTimeout's SDK-default 0.

The three "Suppressed comments" are the same double-cast finding at the other three sites and are covered by the same change.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@cliffhall
cliffhall merged commit fb36797 into v2/main Sep 14, 2026
5 checks passed
@cliffhall
cliffhall deleted the v2/fix/2320-connection-timeout-default branch September 14, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

connectionTimeout defaults to 0, so nothing we own bounds a connect attempt

2 participants