Skip to content

feat(opencode): MCP call counts per server - #36

Merged
kannandreams merged 1 commit into
mainfrom
feat/opencode-mcp-counts
Sep 13, 2026
Merged

feat(opencode): MCP call counts per server#36
kannandreams merged 1 commit into
mainfrom
feat/opencode-mcp-counts

Conversation

@kannandreams

Copy link
Copy Markdown
Owner

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 tool part 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 mcp key 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 via OPENCODE_CONFIG in the agent's own shell is not visible and not counted.

Verified

  • Unit tests built on the real part values: prefix-overlapping server names, a sanitised name (my.api), a subagent's call, a config above the repository root ignored, JSONC comments and trailing commas.
  • Live: an OpenCode session with a filesystem MCP server made one completed call and one refused call. agent-top --json shows scratch_fs with 2 calls and 1 error.
  • fmt, clippy with warnings denied, and all tests pass.

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.
@kannandreams
kannandreams merged commit 79b9064 into main Sep 13, 2026
6 checks passed
@kannandreams
kannandreams deleted the feat/opencode-mcp-counts branch September 13, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant