GeezerVison is showing github.com — Direct MCP tools (codemode: false) are nondeterministically missing from the session toolset; opencode run can hang forever after a session error · Issue #56240 · anomalyco/opencode
Direct MCP tools (codemode: false) are nondeterministically missing from the session toolset; opencode run can hang forever after a session error #56240DescriptionDirect MCP tools (codemode: false) are nondeterministically missing from the session toolset; opencode run can hang forever after a session error
Versions
@opencode/[email protected] (also reproduced on @opencode/[email protected]) — Linux x64
- Config decoded in the V2 shape (servers under
mcp.servers), codemode: false, oauth: false, no timeout key (a server whose timeout is a V1-style integer is skipped as malformed — noted in passing)
Setup
A minimal streamable-HTTP MCP server (plain http.server, ~60 lines) serving one tool, jam_assessment, over tools/list / tools/call:
{
"mcp": {
"servers": {
"jam": {
"type": "remote",
"url": "http://127.0.0.1:39778/mcp",
"codemode": false,
"oauth": false
}
}
}
}
Then, repeatedly, with a fresh HOME/data dir each run:
opencode run --format json --model <provider/model> --auto --standalone \
"Call the jam_assessment tool once with no arguments, then reply done."
Observed
-
The server's tools are missing from the session's toolset on most runs. The CLI logs mcp connected server=jam tools=1 before the model's request, the model still reports "no jam_assessment tool available" (and with some configs literally answers: "My available tools are: file operations … shell …"), and a direct call is refused client-side with:
{"error":{"type":"tool.execution","message":"No tool named \"jam_assessment\" is currently available. Please use a tool from the available tool list."}}
The refusal shape flaps across identical configs and fully fresh state directories (same command, same config: run 1 calls the tool, run 2 refuses). Under machine load (several concurrent spawns) the refusal is near-deterministic — dozens of consecutive runs all refuse.
-
Any tools map in the config makes it worse. With no tools key the tool sometimes registers; with tools: {"jam_assessment": true, …} present the refusal rate goes to ~100% under load. Naming the offered tool true is necessary but not sufficient — a 130-key map that names the tool true still refuses under load.
-
When the session then dies (the scripted model returns an error for the follow-up request), opencode run does not exit. The log records Failed to drain Session, the stdout stream goes silent, and the process sits indefinitely — the caller sees no exit and burns the whole turn timeout (we run turns with a 2700 s budget; the whole budget is lost). Expected: the process exits non-zero promptly after the session fails.
-
The CLI's own recovery attempts are visible in the log and the streamed events: after the refused call the CLI re-asks the model repeatedly (step_start events ~10–20 times), injects the error JSON as the tool result, asks again, and eventually surfaces Failed to drain Session. Nothing in that loop can succeed — the toolset snapshot the session was created with is final.
Expected
- With
codemode: false, the server's tools are on the session's native tool list deterministically — the session's toolset either waits for the server's tools/list to land or is derived from it after registration.
- A session that fails to drain terminates its
opencode run process with a non-zero exit promptly.
Why this matters in practice
An operator pinning codemode: false (per the docs) cannot rely on the server's tools being callable: the same spawn succeeds on a quiet machine and fails under load, and the failed turn costs the full timeout instead of a fast failure. Activityopencode-agent commented on Oct 16, 2026 Thanks for the detailed write-up and the minimal MCP server setup.
I think this is a duplicate of #51812. On a fresh opencode run --standalone, the session's tool list is built before the MCP server's tools are registered, so a one-shot run can miss them entirely. The comments there also cover what you saw: a server can already show as connected (mcp connected … tools=1) and still be missing from the first turn. In the current code the session only waits for the initial discovery, and later tool updates are applied after a 100 ms debounce. That race fits the flapping between identical runs and the near-certain failure under load.
The hang after Failed to drain Session is tracked separately in #49740. Drain failures are only logged and never sent to the client as an error, so opencode run gets no signal to exit.
Possible duplicates and related issues, ordered by likelihood:
The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different. For example, if the tools config map effect turns out to be a separate issue.
PolarTango commented on Oct 17, 2026 Ping @obra @arittr — confirmed on v2.0.31 Linux x64. MCP servers connect successfully logs show tools=26 tools=1 etc, but opencode api get /api/mcp returns tools=0 for all servers. The tools never make it to the model session. This makes all MCP integration useless. Any workaround or ETA for fix? opencode-agent commented on Oct 17, 2026 We haven't heard back in a day, so I'm closing this as a duplicate of #51812, as mentioned above. Thanks again for the detailed report.
Follow these for updates:
If part of this turns out to be a separate problem, such as the tools config map making refusals more likely, please reply here or open a new issue that links this one.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|