Remote MCP: transient 5xx (e.g. 502) on `initialize` marks server failed for the whole session with no retry/backoff
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Shell
- Star
- 11.2k
- Fork
- 1.9k
- Merge trung bình
- 14 giờ 16 phút
- Pull request đã merge (30 ngày)
- 6
Mô tả
Describe the bug
When a remote (type: http) MCP server returns a transient HTTP 5xx (observed: 502 Bad Gateway) on the initialize request at session startup, the CLI records a hard, per-session failure for that server and never retries it for the remaining lifetime of the session. The server then shows as unavailable for the whole run, even though the endpoint recovers seconds later.
This is especially damaging for headless / autopilot workflow (automation) sessions, which cold-start a fresh MCP client on every run: a single unlucky 502 at startup silently disables a required connector for that entire run, with no self-heal. A long-lived interactive session that already completed initialize is unaffected, which makes the failure look inconsistent ("it's green in the app but unavailable in automation").
Observed log (one automation run; server names generic):
[ERROR] rmcp::transport::worker: worker quit with fatal:
UnexpectedServerResponse("HTTP 502 Bad Gateway")
[DEBUG] native_host: Recorded failure for server <Remote Server>: failed to initialize MCP client …
[ERROR] Failed to start MCP client for <Remote Server>: … unexpected server response:
HTTP 502 Bad Gateway, when send initialize request
The endpoint returned a normal 401 auth challenge (healthy) on direct probes seconds later — i.e. the 502 was transient/cold-start, not a real outage.
Affected version
1.0.79-9 (bundled SDK; buildMetadata.gitCommit 65f2c0f). Windows x64. Logic lives in the Rust MCP transport / native_host, so expected to be platform-independent.
Steps to reproduce the behavior
- Configure a
type: httpremote MCP server whose upstream occasionally returns a transient5xxoninitialize(e.g. a scale-to-zero / cold-start backend behind a gateway). - Start a session (or let a scheduled/autopilot workflow run) so the CLI cold-starts the MCP client and sends
initialize. - When
initializehappens to hit the transient502, observe:Recorded failure for server <name>andFailed to start MCP client for <name> … HTTP 502 Bad Gateway.- The server stays unavailable for the entire session — no retry, no backoff, no re-
initialize.
- Probe the same endpoint directly a few seconds later → it responds normally (e.g.
401auth challenge), confirming the 5xx was transient.
Expected behavior
Transient 5xx responses during MCP initialize should be retried with bounded exponential backoff (a few attempts over several seconds) before the server is marked failed. Ideally also allow a later lazy re-initialize/reconnect within the session rather than latching "failed" for the whole run. Distinguish transient transport/gateway 5xx (retryable) from 401/OAuth challenges (handled by the auth flow) and from 4xx config errors (not retryable).
Additional context
- Impact is amplified for scheduled/autopilot automation sessions: they re-cold-start MCP clients every run, so a single startup 502 disables a required connector for that run with no recovery, producing intermittent "connector unavailable" failures that are hard to diagnose.
- A long-lived interactive session that already completed
initializekeeps working, so the same server can appear "connected (green)" in the interactive UI while every fresh automation session reports it unavailable. - Suggested scope: retry policy on the
initializesend path in the streamable-http MCP client worker; treat5xx/transport-closed as retryable with capped attempts + jittered backoff. - Related: the OAuth silent-refresh scope bug tracked in #4464 (a separate failure mode on the same class of remote servers). This retry issue is independent — it fires before auth, on the transport layer.
- OS: Windows x64.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách lần theo đường dẫn gửi initialize của worker MCP client streamable-http trong Rust MCP transport và việc ghi nhận lỗi của native_host. Tái hiện lỗi 502 tạm thời, sau đó xác minh các lần thử lại có giới hạn với backoff, đồng thời giữ nguyên cách xử lý hiện tại đối với các challenge 401/OAuth và các phản hồi 4xx không thể thử lại. Hoàn tất có nghĩa là một endpoint đã khôi phục có thể initialize trong cùng một session thay vì tiếp tục bị giữ ở trạng thái failed.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- rust
- Lĩnh vực
- networking
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 52/100