GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||
GeezerVison is showing github.com — Bug: MCP tools permanently lost mid-session after single transient listTools() failure — no retry, no reconnect · Issue #17099 · anomalyco/opencode Closed DescriptionDescriptionMCP tools from a stdio-transport server intermittently vanish mid-session (within 5-10 minutes of normal use). The server process remains running — it did not crash. Once the tools disappear, they never come back until OpenCode is restarted.
|
| # | Problem | Impact |
|---|---|---|
| 1 | delete s.clients[clientName] permanently removes the MCP client from the singleton state |
Client is gone for the lifetime of the process — tools vanish permanently |
| 2 | No retry logic | A single transient failure (timeout, pipe hiccup, GC pause) permanently evicts a healthy server |
| 3 | No reconnection and no onclose/onerror handlers on MCP clients |
Nothing ever recreates a deleted client |
Compare with create() at startup (line 509) where listTools() is wrapped with withTimeout(). The runtime tools() call has no such timeout wrapper — it relies on the MCP SDK's internal timeout, and on failure, permanently deletes rather than retrying. |
| Check | Result |
|---|---|
| MCP server process alive? | Yes — ps aux confirms the Python process is still running with the same PID hours after tools vanished |
| Crash in OpenCode logs? | No — zero error/disconnect entries for the affected MCP server in ~/.local/share/opencode/log/ |
| Other MCP server affected? | No — f5-confluence_* tools remained available in the same session |
| Restart fixes it? | Yes — restarting OpenCode re-creates the client via create() in the Instance.state() initializer |
prompt.ts:604 → resolveTools() called every LLM loop iteration
prompt.ts:836 → MCP.tools() called
mcp/index.ts:621 → client.listTools() called per-client with .catch()
mcp/index.ts:630 → catch handler: delete s.clients[clientName] ← permanent eviction
(no retry, no reconnect, no onclose handler)
Instance.state) — the deletion persists for the entire process lifetime.Option A — Minimal: Retry listTools() 2-3 times with short backoff before evicting:
const toolsResult = await retry(() => client.listTools(), { attempts: 3, delay: 1000 }) .catch((e) => { // only evict after all retries exhausted })
Option B — Robust: On failure, attempt to create() a new client for the same MCP config. Mark as "reconnecting" rather than "failed".
Option C — Defensive: Register client.onclose handlers after creating MCP clients (near line 476) to trigger automatic reconnection:
client.onclose = () => { log.warn("MCP client closed, reconnecting", { key }) // trigger reconnection }
delete s.clients[clientName] on line 630 should be removed or guarded by a retry counter — a single transient listTools() failure should not permanently kill an otherwise healthy MCP connection.opencode-beads
1.2.24
opencode.json — one fast/local and one that wraps subprocess calls (e.g. a custom FastMCP server that runs SSH commands)Model tried to call unavailable tool. The other server's tools remain available.ps aux | grep <server-name>)No response
macos Tahoe 26.3
iTerm2
A fix for this is available in PR #17651. It implements Option B from the suggested fixes: retry listTools() up to 3 times before evicting, keep successfully connected clients alive even if the initial listTools() times out during create(), and walk configured MCP entries in MCP.tools() rather than only the current client snapshot — enabling lazy re-creation of failed servers while preserving auth states and cleaning up stale connections on reconnect.
this has been fixed