Skip to content

mcp: mcp list reports failed while API reports connected after server reconnect #50725

Open

Description

@msamesch

Related to #36623 (closed as completed, Jul 14) — but the inverse mismatch with a different trigger: after a server reconnect, opencode mcp list reports failed: Connection closed while GET /api/mcp reports connected, and already-running session catalogs don't refresh after POST /api/experimental/mcp/<name>/connect. The session-catalog half still reproduces today.

Summary

After a local MCP server's connection drops mid-session (server process was up while its backend was down), reconnecting succeeds at the service level — mcp connected server=... tools=152 is logged — but opencode mcp list keeps reporting failed: Connection closed while GET /api/mcp reports connected, and a running session never receives the server's tools.

Environment

  • opencode version: v2.0.13
  • OS: Linux 6.1.0-53-amd64 (linux x64)
  • Terminal: TERM=xterm-256color, COLORTERM=truecolor
  • Shell: /bin/bash
  • Install/channel: latest
  • Active plugins: none found in config

Reproduction

  1. Configure a local MCP server in the global config (used: uv tool run --from git+https://github.com/... --with 'mcp<2' freecad-mcp with environment: {FREECAD_MODE: xmlrpc, FREECAD_XMLRPC_PORT: "9875"}).
  2. Start a session — server connects, tools appear in the catalog.
  3. Kill the backend the server depends on (FreeCAD bridge on port 9875) so the connection closes while the session is running.
  4. Restart the backend, then POST /api/experimental/mcp/<server>/connect — log shows mcp connected server=freecad tools=152.
  5. Compare status views, then check the running session.

Expected Behavior

  • opencode mcp list and GET /api/mcp agree on the server status.
  • After a successful service-level reconnect, running sessions either receive the server's tools, or there is a documented way to refresh them in-session.

Actual Behavior

  • opencode mcp list → ✗ freecad failed: Connection closed
  • GET /api/mcp → {"name":"freecad","status":{"status":"connected"}} (same moment)
  • Log confirms repeated successes after the failure:
    level=WARN message="mcp connect failed" server=freecad status.error="Connection closed"
    level=INFO message="mcp connected" server=freecad tools=152 connectionID=9ecf...
    level=INFO message="mcp connected" server=freecad tools=152 connectionID=0ca0...
    level=INFO message="mcp connected" server=freecad tools=152 connectionID=523f...
    
  • The running session's tool catalog still contains 0 tools for the server namespace (search({namespace:"freecad"}) → empty) even after the logged reconnects.
  • Each connect call creates a new connectionID; the session's original connection (the one that failed) appears never to be revived.

Additional Context

  • Frequency: consistent — 3 reconnect attempts, same split-brain status each time.
  • The MCP server process itself is healthy: a manual stdio handshake (initialize → tools/list) succeeds outside OpenCode.
  • Logs show directory=/home/<user> on the MCP entries while the session workspace is a subdirectory of it — possibly relevant to which status is authoritative.
  • Workaround that resolves it: starting a new session (picks up the connected service-level server on startup).
  • /mcps was attempted but arrived as plain text in this client rather than opening the panel, so in-session reconnect couldn't be tested.

Activity

  1. github-actions commented on Sep 22, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    The split-brain status between opencode mcp list and GET /api/mcp appears to be a distinct angle not covered by those issues, so this may still warrant a separate report.

  2. msamesch commented on Sep 22, 2026

    @msamesch
    Author

    catalog eventually populated later in the session; split-brain status from mcp list vs API persists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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