Skip to content

fix(mcp): reconnect remote servers after connection loss - #43558

Open
wang-kaopu wants to merge 1 commit into
anomalyco:devfrom
wang-kaopu:remote-mcp-reconnect
Open

fix(mcp): reconnect remote servers after connection loss#43558
wang-kaopu wants to merge 1 commit into
anomalyco:devfrom
wang-kaopu:remote-mcp-reconnect

Conversation

@wang-kaopu

Copy link
Copy Markdown

Issue for this PR

Closes #43444

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Remote MCP clients can remain unusable after sleep or temporary network loss because transport errors do not always trigger onclose.

This makes remote MCP connection loss recover automatically:

  • handle both transport onerror and unexpected onclose
  • reconnect with capped exponential backoff
  • keep reconnects single-flight per client generation
  • stop retrying when disabled or when authentication requires user action
  • preserve manual disconnects and client replacements

This addresses the MCP recovery path in #43444. Provider authentication behavior is intentionally unchanged.

How did you verify your code works?

  • MCP lifecycle and reconnect tests
  • bun typecheck from packages/opencode
  • Prettier
  • Oxlint
  • git diff --check

Tests cover transport errors without onclose, transient failures, repeated reconnect generations, manual disconnects, disabled servers, client replacement, and JSON-RPC application errors.

Screenshots / recordings

N/A — backend-only change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

server: auth and MCP connections fail after idle period

1 participant