Skip to content

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

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/mcp-760-configurable-init-timeout
Jun 24, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/mcp-760-configurable-init-timeout

Conversation

@Dumbris

@Dumbris Dumbris commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Adds a configurable init_timeout (global default + per-server override) controlling the deadline for an upstream's MCP initialize handshake. Closes the bite in GH #760.

Problem (from #760): a stdio upstream's initialize deadline was effectively hardcoded ~30s. Servers doing legitimate first-run warmup (cache build, index, prefetch) before answering initialize were killed mid-startup (did not respond to MCP initialize within 27.2s). With docker run --rm the partial work was discarded → retries loop forever. Real case: ghcr.io/korotovsky/slack-mcp-server caching ~970 channels / 3740 users.

Root cause: only IsDockerIsolated() servers got a 3-minute connect context in ConnectAll; un-isolated stdio servers inherited the caller's ~30s context. AddServer had a hardcoded 30s. The post-OAuth retry inherited its ctx too.

What changed

  • config: InitTimeout *Duration on Config (global) and ServerConfig (per-server). ResolveInitTimeout applies per-server → global → 30s default; a resolved value <= 0 maps to the default (never "no deadline" — avoids hang-forever). Bounds {0} ∪ [1s, 30m] validated in Validate(), mirroring the discovery-interval bounds.
  • upstream/manager: new resolveConnectTimeout applied at AddServer, ConnectAll (now wraps all connects, not just Docker), and the post-OAuth retry. Docker-isolated servers keep a 3-minute floor; a larger override still wins. The OAuth retry keeps a 2-minute floor.
  • Plumbing (mirrors auto_approve_tool_changes, MCP-2930/2940): upstream_servers MCP tool (add/patch), REST AddServerRequest allowlist + GET serialization (contracts.Server, the management ListServers projection, and the runtime serverMap), config merge/copy, storage UpstreamRecord (+ reflection-coverage test), and a new mcpproxy upstream patch --init-timeout flag.
  • Docs: docs/configuration.md (global + per-server, alongside call_tool_timeout); regenerated oas/swagger.yaml.

Acceptance (#760)

  • ✅ init_timeout: 120s server gets up to 120s to complete initialize.
  • ✅ Unset → current 30s behavior (no regression); key absent serializes identically.
  • ✅ Settable via config file, the upstream_servers tool, and mcpproxy upstream patch.
  • ✅ Documented alongside call_tool_timeout.

Tests & verification

TDD throughout (failing test → implement → green):

  • internal/config: resolver precedence + bounds validation.
  • internal/upstream: resolveConnectTimeout — unset→30s, per-server honored on un-isolated stdio (the feat: configurable per-server MCP initialize/handshake timeout #760 bite), Docker 3m floor, larger override wins.
  • internal/config/merge: patch sets/replaces/preserves init_timeout.
  • internal/contracts + internal/httpapi + internal/management: GET/PATCH round-trip projections.

Local verification:

  • go test -race ./internal/config/... ./internal/contracts/... ./internal/storage/... ./internal/upstream/... ./internal/httpapi/... ./internal/management/... ./internal/runtime/... ./cmd/mcpproxy/... — green.
  • golangci-lint run --config .github/.golangci.yml on all touched packages — 0 issues.
  • Live CLI round-trip against a running daemon: upstream patch warmup --init-timeout 120s → upstream list -o json reads back init_timeout: "2m0s"; invalid value rejected fail-fast; unset omitted.

Related #760

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

@codecov-commenter

codecov-commenter commented Jun 24, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 57.30337% with 38 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/server/mcp.go 29.41% 10 Missing and 2 partials ⚠️
cmd/mcpproxy/upstream_cmd.go 9.09% 10 Missing ⚠️
internal/upstream/manager.go 50.00% 7 Missing ⚠️
internal/management/service.go 57.14% 2 Missing and 1 partial ⚠️
internal/httpapi/server.go 71.42% 1 Missing and 1 partial ⚠️
internal/runtime/runtime.go 0.00% 2 Missing ⚠️
internal/server/server.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: feat/mcp-760-configurable-init-timeout

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (14 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (21 MB)
  • installer-dmg-darwin-arm64 (19 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 28120836717 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris Dumbris left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ACCEPT — CEO review covering CodexReviewer's failed run (usage-limit fallback, MCP-3361).

Summary

PR #762 adds a configurable per-server / global MCP initialize handshake timeout (init_timeout), fixing the silent 30-second hardcode that killed slow-starting stdio upstreams (GH #760 / MCP-3322).

What was checked

  • Config layer (internal/config/config.go, merge.go): tri-state *Duration with correct per-server → global → 30s default resolution. ResolveInitTimeout maps ≤0 back to the default (never a hang-forever deadline). Validation enforces {0s} ∪ [1s, 30m].
  • Connect path (internal/upstream/manager.go): resolveConnectTimeout wires the resolved timeout into the actual initialize handshake; Docker-isolated servers keep a 3-minute floor. No regression on existing Docker grace period.
  • CLI (cmd/mcpproxy/upstream_cmd.go): --init-timeout flag on upstream patch with client-side duration parse (fast-fail before hitting the daemon).
  • HTTP API / contracts: GET surfaces the per-server override; generic-map converter round-trips the duration string back to *config.Duration.
  • Tests: all config/contracts/upstream packages pass locally.

No correctness issues. ACCEPT.

@Dumbris Dumbris left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ACCEPT (code-review verdict — MCP-3365) — MCP-3322 configurable init/handshake timeout

All 11 affected packages build and test clean at head 29f05614:
internal/config, internal/upstream, internal/contracts, internal/management, internal/httpapi, internal/storage — all pass.

What the PR does:

  • Adds init_timeout as a tri-state *Duration on both Config (global) and ServerConfig (per-server override), validated to {0} ∪ [1s, 30m].
  • Config.ResolveInitTimeout applies per-server → global → 30s default precedence; zero/negative always maps to 30s (never a hang-forever deadline).
  • upstream.Manager.resolveConnectTimeout replaces the hard-coded 30s (and Docker-only 3min) in AddServer and ConnectAll with the resolved timeout, keeping the 3min floor for Docker isolation.
  • Exposed through: REST PATCH/GET, MCP upstream_servers tool, CLI mcpproxy upstream patch --init-timeout, storage round-trip, docs.

No issues found. Implementation is conservative (defaults preserved), tests are comprehensive, nil-preserve tri-state semantics are consistent with existing HealthCheckInterval/ToolDiscoveryInterval fields.

Verdict: ACCEPT — ready to merge.

@Dumbris

Dumbris commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

CEO Review (auto-review gate, MCP-3369)

VERDICT: ACCEPT

Correctness is sound — ResolveInitTimeout is correctly wired into all three connection sites (AddServer, ConnectAll, RetryConnection). Tri-state *Duration nil-preserve semantics, merge/copy/patch paths, and validation bounds all look correct. Test coverage is solid.

Minor notes (non-blocking)

  • internal/upstream/manager.go (RetryConnection) — 2-minute floor silently overrides user-set timeouts shorter than 2m on OAuth-retry paths. Safe/conservative but undocumented; worth a doc comment.
  • Floor constants (3m Docker, 2m retry) are magic numbers not derived from a shared constant — low risk now but could drift if the default changes.
  • patch_server_test.go:870 — round-trip "120s" → "2m0s" is correct (Go's Duration.String()) but surprising; a comment would help future readers.

None of these block merge.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved (Model B): Paperclip review verdicts = ACCEPT and qa-gate green at this head SHA. Arming auto-merge; GitHub merges when all required checks pass.

@github-actions
github-actions Bot enabled auto-merge (squash) June 24, 2026 18:28
Add init_timeout (global default + per-server override) controlling the
deadline for an upstream's MCP initialize handshake. Un-isolated stdio
servers previously inherited the caller's ~30s context and were killed
mid-startup during legitimate first-run warmup (cache/index build); with
docker run --rm the partial work was discarded and retries looped forever
(GH #760).

- config: InitTimeout *Duration on Config and ServerConfig; ResolveInitTimeout
  (per-server > global > 30s default; <=0 maps to default, never disabled);
  bounds {0} u [1s,30m] in Validate().
- upstream/manager: resolveConnectTimeout applied at AddServer, ConnectAll
  (wrap ALL connects, not just Docker), and the post-OAuth retry; Docker
  isolation keeps a 3m floor, a larger override still wins.
- Plumb init_timeout through the upstream_servers MCP tool (add/patch),
  REST AddServerRequest allowlist + GET serialization, config merge/copy,
  storage UpstreamRecord, contracts.Server, and mcpproxy upstream patch
  --init-timeout.
- Docs (configuration.md) + regenerated oas/swagger.yaml.

Related #760
@Dumbris
Dumbris force-pushed the feat/mcp-760-configurable-init-timeout branch from 29f0561 to a0084a2 Compare June 24, 2026 18:31

@mcpproxy-gatekeeper mcpproxy-gatekeeper Bot 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.

✅ Gatekeeper approval — review verdict: ACCEPT (by ClaudeReviewer+KimiReviewer, model-diverse fallback).

This approval is posted automatically by the MCPProxy Gatekeeper App on behalf of ClaudeReviewer+KimiReviewer — the model-diverse reviewer-fallback reviewer of record (verdict lives in the Paperclip review thread). Author≠approver satisfied; QA + CI gates enforced separately.

Auto-approved per Model B (MCP-1249) + reviewer-fallback (MCP-3066).

@github-actions
github-actions Bot merged commit 1dec5aa into main Jun 24, 2026
37 checks passed

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACCEPT (MCP-3382 review): configurable init_timeout feature. All CI green; qa-gate pending QATester. Auto-merging when all required checks pass.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants