MCP HTTP handlers read an empty registry on cold locations
Description
MCP HTTP handlers can read the registry before config plugins register servers for a cold directory. On macOS, the first opencode mcp list says No MCP servers configured; the same command then lists the configured servers. This is a cold-location race, distinct from the persistent warm-service symptoms in #50710.
Source regression tests also reproduce cold connect, disconnect, and remove returning 404 for a configured server. Waiting for plugin activation makes those requests succeed. Proposed fix: #54191.
Plugins
The source reproduction uses built-in config plugins only.
OpenCode version
Installed 2.0.21; reproduced with current v2 source using Bun 1.4.2.
Steps to reproduce
- Configure an MCP server in the global config.
- Create a new directory and change into it.
- Run
opencode mcp list: it may report no configured servers. - Repeat from the same directory after initialization: the server appears.
Expected: the first request waits for config registration and lists the configured server.
The regression in #54191 uses an in-memory server and a disabled local MCP server, so it needs no remote authentication. Without the readiness wait, the first /api/mcp response is HTTP 200 with data: [].
Screenshot and/or share link
Reproduction and regression tests: #54191.
Operating System
macOS 26.5, Apple Silicon.
Thanks for the detailed report. I can reproduce this.
I set up an isolated home whose global config has one disabled local MCP server, then ran opencode mcp list twice in each of three new directories:
- 2.0.21: five of the six calls printed
No MCP servers configured. - 2.0.26 (the latest release): the first call in every new directory printed
No MCP servers configured. The second call listed○ demo disabledin two of the three directories, so even a repeat call can still come back empty.
I couldn't run current v2 source here, so the latest check used the 2.0.26 release. On the latest v2 commit (d2905b8), the MCP HTTP handlers still don't wait for plugins to finish loading before reading the registry, so I'd expect the same result from source. I only tested mcp list, not the connect, disconnect and remove 404s.
The script below reproduces it.
Related: #50710, a Windows report where the service registers no MCP servers at all and the problem doesn't go away on a later run, and your PR #54191, which adds the wait to mcp.list.
Reproduction script (repro.sh)
#!/usr/bin/env bash
# Reproduce: first `opencode mcp list` in a cold directory reports no servers.
# Usage: OC="opencode" bash repro.sh (or OC="bun ... packages/cli/src/index.ts")
set -u
OC=${OC:-opencode}
ROOT=$(mktemp -d /tmp/opencode/mcp-cold-XXXX)
export HOME=$ROOT/home XDG_CONFIG_HOME=$ROOT/home/.config XDG_DATA_HOME=$ROOT/home/.local/share \
XDG_STATE_HOME=$ROOT/home/.local/state XDG_CACHE_HOME=$ROOT/home/.cache
mkdir -p "$XDG_CONFIG_HOME/opencode"
cat > "$XDG_CONFIG_HOME/opencode/opencode.json" <<'J'
{ "$schema": "https://opencode.ai/config.json",
"mcp": { "demo": { "type": "local", "command": ["true"], "enabled": false } } }
J
for i in 1 2 3; do
DIR=$ROOT/project-$i; mkdir -p "$DIR"; cd "$DIR"
echo "== project-$i, run 1"; $OC mcp list 2>&1
echo "== project-$i, run 2"; $OC mcp list 2>&1
done
$OC service stop >/dev/null 2>&1 || true
Run it: bash repro.sh
Confirming this still reproduces on 2.0.32 (reported as the latest release by
https://opencode.ai/update/api/latest/cli/npm), Linux x86_64, standalone binary
install, no plugins configured. So it is not fixed by anything released since the
PR here went up.
Minimal repro (deterministic)
$ mkdir -p /tmp/mcp-repro && cd /tmp/mcp-repro
$ opencode mcp list # first invocation in a directory that was never a location
No MCP servers configured
$ opencode mcp list # ~1s later, same command, same directory
✓ context7 connected
Back-to-back invocations always print the empty message; adding a ~1s sleep before
the second one makes it succeed reliably. Repeating opencode service restart
resets every location to the cold state, so the first two invocations are empty
again and the third recovers:
$ opencode service restart
$ opencode mcp list
No MCP servers configured
$ opencode mcp list
No MCP servers configured
$ opencode mcp list
○ context7 pending
Server log ordering
The service log shows the CLI completes before the location is booted and before the MCP client connects, which matches the "reads the registry before the servers are registered" diagnosis:
level=INFO message="cli starting" args="[\"mcp\",\"list\"]" role=cli
level=INFO message="cli starting" args="[\"mcp\",\"list\"]" role=cli
level=INFO message="location services booted" directory=/tmp/opencode/e3 durationMs=30 role=server
level=INFO message="mcp connected" server=context7 tools=2 directory=/tmp/opencode/e3 role=server
level=INFO message="cli starting" args="[\"mcp\",\"list\"]" role=cli # now prints ✓ connected
Extra data points
- It is not a config discovery problem:
opencode api get "/api/config?location[directory]=<dir>"resolves the same cold directory correctly, returning the global document and the project document, both with the server declared. Only the MCP read is early. - It happens with a remote server too (
context7overhttps://mcp.context7.com/mcp, no OAuth/API key needed), not only with local stdio servers, and both with servers declared only globally and with a projectopencode.jsonfor that directory. - Related, same ordering issue with user-visible impact: restarting the service
while a session is running temporarily removes the MCP tools from that running
session until the location boots again (tools come back on their own once
mcp connectedis logged), which looks like #51812.
Confirming this on V2, with the timing measured instead of "run it twice".
Environment: opencode 2.1.1 (V2, local install under ~/.opencode/bin),
Debian 13, x86_64. Five MCP servers configured: four local stdio, one remote
Streamable HTTP. No plugins.
Server side. Fresh directory, GET /api/mcp?location[directory]=<fresh>,
polled every 250 ms:
0 ms n=0 [] <- empty registry
282 ms n=5 [pending] 564 ms n=5 [connected, pending] ~1.4 s n=5 [connected] <- stable afterwards
The first request for a cold location is not "sometimes" empty: it is empty every time, and the next request 282 ms later already returns the catalog. The registry is populated asynchronously and the handler answers before it exists.
CLI side. Same cold directory, three consecutive opencode mcp list:
1 -> No MCP servers configured
2 -> No MCP servers configured
3 -> ○ pending x5 (then connected)
Impact. No MCP servers configured is indistinguishable from a genuinely
empty configuration. It cost me a full misdiagnosis — config shape, service
environment and credential were all checked before measuring the second call.
Since #55074 was closed as a duplicate of this one, the user-facing message
still ships; when the readiness fix lands it would help to say in the release
note that the first mcp list in a new directory no longer reports an empty
catalog.
Happy to test #54191 on Debian 13 against this configuration if a build is available.
Still happens on 2.1.3 (macOS, npm install). In a project folder with four MCP servers configured, the first opencode mcp list prints No MCP servers configured; the second and third list all four. I run a workshop where one step checks the connection with opencode mcp list, so participants would get the wrong message on their first try. We now tell them to check with /mcps in the TUI instead, which shows the servers correctly.
Still reproduces on 2.2.5 (latest release), Linux x86_64, ~/.opencode/bin install, shared background service. In my runs the empty result does not clear on its own: three consecutive mcp list calls and --standalone all printed it, until something requested the location through the API.
Minimal repro in a fresh directory whose opencode.json defines one local server:
{ "mcp": { "servers": { "repro-local": { "type": "local", "command": ["npx", "-y", "@modelcontextprotocol/server-everything"] } } } }
$ opencode mcp list # tries 1, 2 and 3
No MCP servers configured
$ opencode mcp list --standalone
No MCP servers configured
$ opencode api get "/api/mcp?location[directory]=<dir>" # run from another directory
{"data":[..., {"name":"repro-local","status":{"status":"pending"}}]}
$ opencode mcp list # back in <dir>
○ repro-local pending
The same thing happened in 10 of 11 project directories with project-scoped servers. Once a location had been loaded through GET /api/mcp?location[directory]=..., mcp list worked there as well.
Still reproduces on 2.2.5 (current latest on npm), so nothing released since the reports above has fixed it. Same cold-state behaviour on both the CLI and the HTTP handler.
Environment: opencode 2.2.5 (npm @opencode/cli-linux-x64), Linux x86_64, two servers configured in ~/.config/opencode/opencode.json — one remote Streamable HTTP (keenable, auth header resolved from a file) and one local stdio (mcp-nixos). One plugin enabled.
Server side, GET /api/mcp polled every 500 ms on a fresh opencode serve:
95 ms n=0 {"location":{...},"data":[]}
618 ms n=0 {"location":{...},"data":[]}
1139 ms n=2 {"data":[{"name":"keenable","status":{"status":"connected"}},
{"name":"nixos","status":{"status":"connected"}}]}
CLI side, same instance, opencode mcp list --server http://127.0.0.1:<port>: empty at t=0, and by the time I queried again the API already reported both servers connected — i.e. the CLI gives up earlier than the registry takes to fill (~1.1 s here), not because the config is unreadable.
One extra data point that makes the false negative especially misleading: opencode mcp add <name> --url … writes the entry, and the very next opencode mcp list in that same directory still prints No MCP servers configured while the config file on disk contains exactly the shape the docs specify.
I can reproduce the user-visible discrepancy on OpenCode CLI 2.4.1 under WSL2:
- Configure MCP servers in the user-level V2
mcp.serversmap. - In a project with narrowly scoped permission for the read-only probes, run
opencode run --standalone --agent plan --format json ...and invoke an MCP tool. The captured tool event contains a successful server payload, including on both local stdio and SSH-based stdio transports. - From the same directory, run
opencode mcp list --standalone. It printsNo MCP servers configuredboth before and after the successful run.
The list invocation is a separate standalone process, so this may fit the cold-location behavior described here. The successful tool payload is the important observable difference from a missing registration.
Still reproduces on 2.4.2 (Linux) — shared service and --standalone
Same behaviour on opencode v2.4.2, Linux (x86_64). The global config
~/.config/opencode/opencode.json defines two local MCP servers in the native
V2 mcp.servers shape.
In a directory the service had never loaded:
$ opencode mcp list
No MCP servers configured
$ opencode mcp list
✓ agentmemory connected
✓ dashboard-icons connected
The service log for the same runs orders the CLI exit before the connect, which matches the cold-registry diagnosis:
level=INFO message="cli starting" args="[\"mcp\",\"list\"]" role=cli
level=INFO message="mcp connected server=agentmemory tools=54"
level=INFO message="mcp connected server=dashboard-icons tools=6"
The empty line appeared at 03:47 and 03:51 on 2.4.2, and a repeat call lists both as connected.
--standalone takes the same cold path, and it still reads the config:
$ opencode --standalone mcp list
No MCP servers configured
$ opencode --standalone debug config
# both entries are still listed under mcp.servers
Reproduced 3 times from cwd /tmp; the standalone call exits 0. --standalone
is the escape hatch when the shared service is unhealthy, so the empty message
hides the config exactly when it is needed.
Findings Log receipt: flr_796316fe-305c-4f27-83f8-7e769b66e3a3 Findings Log receipt: flr_b92d0780-48e2-4f3f-8c11-4e25a89e3229
Cold location also omits the remote config document from debug config (2.4.2, Linux)
One more data point for this cold-state window, measured on opencode v2.4.2, Linux x86_64, with the shared background service and no plugins. The global config ~/.config/opencode/opencode.json holds two local servers under the V2 mcp.servers map.
In a directory the service had never loaded:
$ opencode mcp list
No MCP servers configured
debug config in that same directory (and state) returns only two documents:
$ opencode debug config
[
{ "type": "document", "path": "~/.config/opencode/opencode.json", "info": { "mcp": { "servers": { ... } } } },
{ "type": "directory", "path": "~/.config/opencode" }
]
The remote organization document is missing there. Once the location is warm, the same command returns three documents — the remote organization document (no path), the local document with mcp.servers, and the directory — and the list command works:
$ opencode mcp list
✓ agentmemory connected
✓ dashboard-icons connected
Counts from the same session: 15 of 15 fresh directories printed No MCP servers configured on the first call, and 20 of 20 repeat calls in a warmed directory listed both servers. The service log orders the CLI exit before the location boot and the connect, which matches the diagnosis in this thread:
message="cli starting" args=["mcp","list"] role=cli
message="location services booted" directory=... durationMs=52 role=server
message="mcp connected" server=dashboard-icons tools=6 role=server
One correction to the empty message's cause: the local document that carries mcp.servers is already present in the cold debug config output, so the missing remote organization document does not by itself explain the empty list. The per-location registry is what is still empty.
Findings Log receipt: flr_4e9b9561-ee25-4262-8fe1-0a1731edca50