Version / environment
- OpenCode 2.2.4 (
@opencode/cli-linux-x64), Linux x64, Node-free binary.
- Also seen on 2.0.26 (one-shot
run).
- Fresh isolated
HOME / XDG_* / OPENCODE_DB, OPENCODE_DISABLE_AUTOUPDATE=1.
What happens
With a remote Streamable HTTP MCP server configured with codemode: false, a one-shot opencode run --standalone sends its first main-agent request without the server's tools. The MCP server receives initialize and tools/list, and OpenCode logs the server as connected, but the tool list in the first request has 13 tools and none from the MCP server (edit, experimental_image_generate, glob, grep, question, read, shell, skill, subagent, webfetch, websearch, write, execute). On the one request in the run the tools never appear, and a later request in the same run (after a tool call) also had none in an earlier test.
In opencode serve mode the same server's tools do appear (four tools, named <server>_<tool>, 17 tools total), but only if the session is created some seconds after server start. If the session is created and prompted immediately, or right after GET /api/mcp reports the server connected, the first request again has 13 tools. POST /api/experimental/mcp/<name>/connect returns 404 McpServerNotFoundError during that window.
So connected is reported before the server's tools are part of the tool set a new session uses.
Minimal reproduction (no secrets, local only)
- A small HTTP server on
127.0.0.1:18999 implementing MCP Streamable HTTP with initialize, notifications/initialized (202) and tools/list returning one tool (echo), tools/call echoing arguments. No auth.
- A second local server on
127.0.0.1:19000 implementing POST /v1/chat/completions as an SSE stream that logs each request body's tools[].function.name and answers "ok" with finish_reason: "stop".
$XDG_CONFIG_HOME/opencode/opencode.json:
{
"provider": { "fx": { "npm": "@ai-sdk/openai-compatible", "name": "fx",
"options": { "apiKey": "k", "baseURL": "http://127.0.0.1:19000/v1" },
"models": { "m1": { "name": "m1" } } } },
"permissions": [{ "action": "*", "resource": "*", "effect": "allow" }],
"mcp": { "servers": { "demo": { "type": "remote", "url": "http://127.0.0.1:18999/mcp", "codemode": false } } }
}
- Run:
opencode run --standalone --format json -m fx/m1 "say hi" with an empty isolated home.
- Inspect the logged first non-title request: no
demo_echo tool.
- Compare:
opencode serve --hostname 127.0.0.1 --port 18998 (with OPENCODE_SERVER_PASSWORD set), wait for GET /api/mcp to show demo as connected, then POST /api/session and POST /api/session/{id}/prompt immediately: no demo_echo. Repeat after a 3 s pause: demo_echo present.
Observed timeline (2.2.4, one-shot run): MCP initialize at t=0, title request at t≈28 ms, main request at t≈35 ms, tools/list at t≈58 ms.
Expected
Before the first main-agent request of a session, OpenCode should wait for configured, enabled MCP servers to finish connecting and listing tools (bounded by the server's timeout), so that codemode: false tools are in that request. Alternatively connected in GET /api/mcp should only be reported once tools are available, or a documented readiness signal should exist for headless callers.
Impact
Headless automation that runs one opencode run per task cannot rely on MCP tools being available to the model on the first step. Docs say "Servers connect automatically", which this contradicts for one-shot use.
Related: #59315 (Code Mode tools exposed directly when execute is denied) makes this visible only for codemode: false; with Code Mode on, tools sit behind execute.