Register the OpenCode MCP server at user scope - #587
Merged
Conversation
gortex install gave OpenCode 21 skills, 20 slash commands and an enforcement plugin — every one of which tells the model to reach for the Gortex tools — and registered no MCP server at that scope. The reasoning, written into the code, was that gortex init would put a server in each repo. A user who runs only the documented machine-wide step therefore got an OpenCode taught to ask for tools that were not mounted, and the sole symptom was the agent reporting a Gortex integration failure. Global mode now merges the same mcp.gortex entry into ~/.config/opencode/opencode.json, preferring an existing .jsonc for the reason the per-repo path already does: writing the sibling .json would leave two configs and register the server in the one OpenCode does not read. Project and user scope share one mutator so the two entries cannot drift. Inspect had the same blind spot from the other side — it hardcoded opencode.json and parsed it without stripping comments, so on a hand-authored config doctor reported no server on a machine that had one. It now resolves through the same helper the writer uses. The invariant is now a test: if global mode installs guidance, it installs the server that guidance depends on. Removing the fix fails four tests, one of which prints the user's exact situation — 21 skills, 20 commands, a plugin, no server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #586, found by running it on a real machine.
The bug
gortex installgave OpenCode 21 skills, 20 slash commands and the enforcement plugin — every one of which tells the model to reach for the Gortex tools — and registered no MCP server at that scope. The reasoning was written into the code:That is wrong for OpenCode, which reads a user-level config for every project. A user who runs only
gortex install— the documented machine-wide step — got an OpenCode that had been taught to ask for tools that were not mounted.Reproduced on a real install:
~/.config/opencode/{skills,commands,plugin}fully populated,~/.config/opencode/opencode.jsonccontaining nothing but$schema. The only visible symptom was the agent reporting a Gortex integration failure and stopping, exactly as the profile instructs it to.The fix
Global mode merges the same
mcp.gortexentry into~/.config/opencode/opencode.json, preferring an existing.jsoncfor the reason the per-repo path already does: writing the sibling.jsonwould leave two configs and register the server in the one OpenCode does not read. Project and user scope now share one mutator, so the two entries cannot drift.RemoveGlobaltakes the entry back out — only that key, leaving the user's own servers and every other key in place — andGlobalArtifactslists the config only when our entry is really in it, so the uninstall preview cannot promise a deletion it will not make.A second blind spot, from the other side
opencode.Inspecthardcodedopencode.jsonand parsed it with a barejson.Unmarshal. On a hand-authored.jsoncconfig — which is what the affected machine had —gortex doctorwould have reported "no MCP server" on a machine that had one, hiding the fix as effectively as the bug. It now resolves through the same helper the writer uses and strips comments before parsing.agents.StripJSONCommentsis exported for that.The invariant, as a test
Removing the fix fails four tests. One of them prints the affected machine's exact situation before failing:
That mutation check was run, not assumed. Also covered: the
.jsoncpreference end-to-end, the user-config merge, andPlan()naming the path (doctor and--print-configreadPlan, so a pathApplywrites butPlanomits is invisible).One stale assertion in #586 was corrected rather than worked around:
doctor_runtime_test.goassertedMCPServer = falsefor OpenCode, encoding the old behaviour as intent.Verification
go build ./...,go vet ./...,golangci-lint,gofmt— clean.go test ./...— 146 packages, zero failures, exit 0.Verified on the affected machine: after this change
gortex install --agents=opencodereports1 merged · 42 skipped(the 41 existing artifacts unchanged, the server entry added) and the config gains themcp.gortexstanza.