Skip to content

fix(opencode): reconnect closed remote MCP clients#33724

Open
rekram1-node wants to merge 2 commits into
devfrom
mcp-reconnect
Open

fix(opencode): reconnect closed remote MCP clients#33724
rekram1-node wants to merge 2 commits into
devfrom
mcp-reconnect

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • reconnect remote MCP clients after an owned transport onclose while retaining the existing public failed status
  • use one reconnect path per server with bounded exponential backoff and generation, replacement, disconnect, and disposal fencing
  • publish a replacement only after initialization and tool catalog discovery complete
  • do not retry or replay failed tool calls; preserve the SDK patch's narrow session-bound 404 retry

Related issues

Tests

  • bun test test/mcp/reconnect.test.ts --timeout 30000
  • bun test test/mcp/lifecycle.test.ts --timeout 30000
  • bun test test/mcp/session-recovery.test.ts --timeout 30000
  • bun typecheck in packages/opencode (run once during implementation; not repeated after the resource constraint update)
  • bunx prettier --check src/mcp/index.ts test/mcp/reconnect.test.ts test/fixture/mcp-reconnect-server.ts

The new tests use a real loopback MCP endpoint in a child process with IPC/HTTP readiness signals, no mocks or fixed sleeps. They prove a single replacement initialization, no replay of an ambiguously failed call, a later request using the replacement, and intentional disconnect fencing a late reconnect.

Residual design

This first PR intentionally reacts only to definitive onclose and does not classify arbitrary request errors or replay requests. Ambiguous tool failures remain failures; recovery is available to future requests after the transport definitively closes.

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.

MCP remote client has no transport-level retry on socket/connection errors

1 participant