Skip to content

feat: configurable per-server MCP initialize/handshake timeout #760

Closed

Description

@algis-dumbris

Summary

Add a configurable per-server MCP initialize/handshake timeout (with a global default). Today the deadline for a stdio upstream to complete the MCP initialize handshake appears to be hardcoded (~30s; observed did not respond to MCP initialize within 27.2s). Servers that do legitimate first-run work before responding to initialize (cache warmup, index build, large API prefetch) get killed mid-startup and never finish — and with docker run --rm the partial work is discarded, so retries loop forever without converging.

Environment

  • MCPProxy v0.45.0 (personal), darwin/arm64
  • Upstream: ghcr.io/korotovsky/slack-mcp-server (stdio, un-isolated, run via docker run --rm -i -v slack-mcp-cache:/root/.cache ...)

Repro / real-world case

On startup the Slack server caches users, then channels, before it answers initialize. When its channel cache is expired (hardcoded 1h TTL) it refetches the full channel list. On a large workspace (~970 channels / 3740 users) that refetch takes longer than the ~27s handshake deadline:

... "Caching channels collection..."
... "Channels cache expired, will refetch" ttl=3600000000000 cache_age=...
=> failed to connect: server did not respond to MCP initialize within 27.2s
   (subprocess may have crashed or printed to stderr instead of stdout)

mcpproxy gives up at ~27s and respawns; the killed container never persists channels_cache_v2.json, so every retry repeats the slow refetch. Result: the server is stuck Connecting, retry_count climbing, never reaching Ready. It only recovered once a killed-but-still-running container happened to finish the refetch and write the cache, after which a bounce picked up the warm (<1h) cache.

Why the existing knobs don't cover this

  • call_tool_timeout (default 2m) governs tool calls after connect, not the initialize handshake.
  • docker_isolation.timeout (30s) only applies to isolated servers; this server runs un-isolated (applies_to_server: false), so it doesn't bite here — and even when it does, it's a Docker-isolation knob, not an MCP-handshake knob.
  • There is no per-server or global field that lengthens the initialize deadline.

Proposal

  1. A global default, e.g. init_timeout (or handshake_timeout) under top-level config, defaulting to the current value to preserve behavior.

  2. A per-server override on the upstream entry (and a matching parameter on the upstream_servers patch/update management tool), e.g.:

    {
      "name": "slack-gcore",
      "command": "docker",
      "args": ["run", "--rm", "-i", "..."],
      "init_timeout": "120s"
    }
  3. Apply it to the stdio connect path that currently enforces the ~27–30s deadline so slow-but-healthy first starts can complete.

Acceptance criteria

  • A server configured with init_timeout: 120s is given up to 120s to complete the MCP initialize handshake before mcpproxy declares failure / respawns.
  • Unset → current default behavior (no regression).
  • Override settable via config file and via the upstream_servers management tool (patch/update).
  • Documented alongside call_tool_timeout.

Notes

Related but distinct from #599 (which improved classification/stderr surfacing of "subprocess exited before MCP initialize"). This request is about making the deadline itself configurable so slow-warmup servers can connect at all. A configurable timeout would also let operators tune the startup-vs-fail-fast tradeoff per server instead of relying on a server happening to self-warm across retries.

Activity

  1. Dumbris commented on Jun 24, 2026

    @Dumbris
    Member

    Shipped in PR #762 (merged to main as 1dec5aa). Adds configurable per-server MCP initialize/handshake timeout with a global default: init_timeout on global + per-server config (default 30s, no regression), resolver applied at the connect path, settable via config + the upstream_servers management tool, documented alongside call_tool_timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions