feat(opencode): MCP call counts per server - #36
Merged
Conversation
OpenCode 1.18.15 writes an MCP call as an ordinary tool part named <server>_<tool>, both halves sanitised to [a-zA-Z0-9_-], with no prefix and nothing else marking it. The name alone cannot say where the server ends, so the server names come from OpenCode's own config: the mcp key names in the global config.json, opencode.json and opencode.jsonc, and in the project's opencode.json[c] and .opencode/ files from the session directory up to the repository root. Only key names are read. A tool part counts when its name starts with a configured server's sanitised name and "_", longest name winning; with no configured server nothing is guessed. A server set only through OPENCODE_CONFIG in the agent's own shell cannot be seen. Verified against a live OpenCode session with a filesystem MCP server: one completed call and one the server refused read back as 2 calls, 1 error.
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.
What
OpenCode rows get per-server MCP rows (calls, errors, last call), closing the last harness without them.
How OpenCode names MCP tools
Verified on OpenCode 1.18.15 from its own code and a live session: an MCP call is a normal
toolpart named<server>_<tool>, sanitised to[a-zA-Z0-9_-], with no prefix. Nothing in the part marks it as MCP, so a name cannot be split on its own.So the adapter reads the
mcpkey names only from OpenCode's config, global and project, walking up to the repository root. It matches a tool whose name starts with a sanitised server name plus_, and the longest name wins. With no configured server, nothing is guessed. A server set only viaOPENCODE_CONFIGin the agent's own shell is not visible and not counted.Verified
my.api), a subagent's call, a config above the repository root ignored, JSONC comments and trailing commas.agent-top --jsonshowsscratch_fswith 2 calls and 1 error.