Commit Graph
1 Commits
Author SHA1 Message Date
yetone fce0d84756 library: OpenCode 2's mcp.servers is read, written and emptied as servers, not taken for one
liam_8829 (Discord #feedback, 10-27) turned every MCP server off and found
opencode.json still holding a "servers" node with no type and no enabled.
That node is OpenCode 2's own container: 2.x writes servers to
mcp.servers.<name> (opencode mcp add --global does), still reads V1
mcp.<name> beside it, and V2 wins a name clash. magpie read every child of
mcp as a server, so it listed "servers" as a typeless server, never saw the
servers inside it (so it could not turn them off), and wrote its own as V1
mcp.<name> beside them.

Now, for the OpenCode format (opencode.json, a project's opencode.json,
and the targets sharing that format):
- mcp.servers is read as the container when it has no type/command/url of
  its own, and its entries are servers;
- a server is written where it already is, or to mcp.servers when the file
  uses that layout; a V2 entry gets no "enabled" (OpenCode 2 drops it; the
  field there is "disabled");
- removing a server removes it from where it is, V1 or V2, never the
  container. Turning everything off leaves {"mcp":{"servers":{}}} plus the
  user's own entries, byte for byte.

Run:
- TestOpenCode2Servers (new): red on the old code ("found [mine]"); red
  with del's fix taken out ("ctx7 ... still in"); red with the enabled drop
  taken out ("an OpenCode 2 server has no enabled"); green with the fix.
- Real OpenCode 2.0.25 in a sandbox XDG_CONFIG_HOME, `opencode debug
  config`: the written file (V1 mine + servers{gh, own}) resolves every
  server; {"mcp":{"servers":{}}} resolves to no mcp, no error.
- go test -count=1 -timeout 45m ./internal/library ./internal/proc
  ./internal/provider:
  library ok (312s), proc ok (40s) at b67c7eaa0 (rebased on origin/main
  14e4d8040). provider red only in tests already filed: with
  -skip TestUnreadLoginsWriteErrorsKeepCredentials (the synctest crash in
  filememo.Forget, #3632, on main since 091153bf), its only reds are
  TestFetchAsksOneListOnceForTwoBasesOfIt, TestFetchUnionsProtocolLists-
  WithoutChat and TestFetchAsksASharedBaseOnce (#3854, on main since
  6eb510f78). Neither touches this change.
- gofmt -l internal/ clean; go vet darwin, GOOS=linux -tags nogui,
  GOOS=windows on library, proc and provider.

Siblings: Codex config.toml and Claude .claude.json emptied correctly in
the same repro; ZCode already writes mcp.servers; Crush is V1 mcp.

Not tried: a real OpenCode TUI session; the project opencode.json and the
deveco/mimocode targets were not tested on their own (they share the same
entries/put/del); the full ./... suite was not run.
2026-10-27 18:52:15 +08:00