GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MCP remote connections silently die after idle periods - no onclose/onerror handling, no reconnection, no heartbeat · Issue #29190 · anomalyco/opencode

MCP remote connections silently die after idle periods - no onclose/onerror handling, no reconnection, no heartbeat #29190

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
MCP remote connections silently die after idle periods - no onclose/onerror handling, no reconnection, no heartbeat#29190
Copy link
Assignees
StarpTech

Description

@bob-dawson
bob-dawson
opened on May 25, 2026
Issue body actions

Problem

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:

  1. 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.

  2. No automatic reconnection — Once the transport dies, there is no code to attempt reconnect. The connection is permanently broken until opencode restart.

  3. 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.

  4. 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.

  5. 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

  1. Register client.onclose / client.onerror handlers to update s.status[key] from "connected" to "failed"
  2. Implement automatic reconnection in onclose handler (exponential backoff, reuse existing create() logic)
  3. Add periodic health check using client.ping() to proactively detect dead connections
  4. Pass reconnectionOptions: { maxRetries: 5 } (or higher) to StreamableHTTPClientTransport
  5. Handle session expiry — when POST returns 404/410, re-initialize the connection

Environment

  • opencode version: latest (built from source)
  • MCP SDK: @modelcontextprotocol/sdk 1.27.1
  • Affected config type: mcp.*.type = "remote" (HTTP/SSE-based MCP servers)
  • Not affected: mcp.*.type = "local" (stdio-based) since those are process-local and don't have idle connection issues

Activity

  1. github-actions
    assigned
    StarpTech
    on May 25, 2026
  2. github-actions commented on May 25, 2026

    @github-actions
    github-actionsBot
    on May 25, 2026 – with GitHub Actions
    Contributor
    More actions

    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:

    • MCP remote client has no transport-level retry on socket/connection errors #25287: MCP remote client has no transport-level retry on socket/connection errors — covers the same missing reconnect-on-transport-error path in convertMcpTool
    • MCP streamable-HTTP transport: 'Session not found' from server permanently breaks tool calls (no auto-reconnect) #25137: MCP streamable-HTTP transport: 'Session not found' permanently breaks tool calls — overlaps on missing onclose handling and no session re-initialization
    • fix(mcp): MCP status shows connected green after server reconnect even though server is down #24855: MCP status shows connected green after server reconnect even though server is down — same stale status problem you describe
    • MCP client connection status goes stale after initial connect #25682: MCP client connection status goes stale after initial connect — covers the same absence of health checks and silent failure detection

    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.

  3. bob-dawson commented on May 25, 2026

    @bob-dawson
    bob-dawson
    on May 25, 2026
    Author
    More actions

    Duplicate of #23997 — same root cause (MCP remote connections drop after idle, no onclose/reconnect handling)

  4. bob-dawson
    closed this as not plannedon May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @StarpTech
    StarpTech

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.