You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MCP remote connections silently die after idle periods - no onclose/onerror handling, no reconnection, no heartbeat #29190
After being idle for a while, remote (HTTP/SSE) MCP connections silently drop, making all subsequent MCP tool calls fail with "Not connected" error. The status still shows "connected" even though the underlying transport is dead.
Root Cause
In packages/opencode/src/mcp/index.ts:
No onclose/onerror handlers registered on MCP Client — When the SSE/HTTP transport disconnects, the SDK fires transport.onclose()/transport.onerror(), but opencode never sets client.onclose or client.onerror. The connection state (s.status[key]) stays "connected" while client._transport becomes undefined.
No automatic reconnection — Once the transport dies, there is no code to attempt reconnect. The connection is permanently broken until opencode restart.
No keep-alive/heartbeat — The SDK Client class has a ping() method, but opencode never calls it. Idle SSE streams are terminated by servers/proxies (typically after 60-120s), and there is no mechanism to detect or prevent this.
StreamableHTTP reconnection too limited — The SDK defaults maxRetries: 2 for reconnection, and opencode does not pass custom reconnectionOptions to StreamableHTTPClientTransport. Brief glitches may recover, but longer outages won't.
SSE transport has no reconnection at all — The deprecated SSEClientTransport fallback has zero reconnection logic.
Typical Failure Scenario
opencode connects to remote MCP -> opens SSE GET stream -> idle period ->
server/proxy closes idle SSE connection -> SDK transport dies ->
onclose/onerror silently ignored -> status still "connected" ->
next tool call -> "Not connected" error
Suggested Fixes
Register client.onclose / client.onerror handlers to update s.status[key] from "connected" to "failed"
This issue might be a duplicate of several existing open issues that cover the same root cause — silent MCP connection failures, stale status, and lack of reconnection logic. Please check:
If your issue is a strict superset that combines all of these (adding the heartbeat/ping angle), it may be worth referencing them and noting what's not covered. Otherwise, consider whether one of the above is the right place to add details.
Activity
github-actions commentedon May 25, 2026
This issue might be a duplicate of several existing open issues that cover the same root cause — silent MCP connection failures, stale status, and lack of reconnection logic. Please check:
convertMcpToolonclosehandling and no session re-initializationIf your issue is a strict superset that combines all of these (adding the heartbeat/ping angle), it may be worth referencing them and noting what's not covered. Otherwise, consider whether one of the above is the right place to add details.
bob-dawson commentedon May 25, 2026
Duplicate of #23997 — same root cause (MCP remote connections drop after idle, no onclose/reconnect handling)