Follow-ups for OpenCode MCP tool filter key sanitization (PR #3693)
Background
PR #3693 (fix(mcp): sanitize OpenCode tool filter keys) makes the OpenCode MCP adapter (OpenCode V1, V2 and MiMo Code share the code path) generate and import tool filter keys in the sanitized form that OpenCode itself uses, reusing the helpers shared with Kilo. It addresses the remaining MCP tools-map item in #2592. The review found no high or critical issues, so the PR was merged. The low-severity findings below are tracked here as follow-ups.
Details
All locations are in src/features/mcp/opencode-mcp.ts and src/features/mcp/opencode-mcp.test.ts.
- Key collisions can flip a deny into an allow. In
convertToOpencodeFormat, servera.bwithdisabledTools: ["x"]and servera_bwithenabledTools: ["x"]both producea_b_x, and the later entry overwrites the earlier one. Within a single server (read.filevsread_file) deny wins, which is the safe direction. - Per-call allocation.
findOpencodeToolOwnercreatesbuiltinKeys: new Set<string>()on every call. It should be a module-level constant with a comment explaining why built-ins are intentionally empty (the OpenCodetoolsmap only holds MCP toggles, unlike Kilo). - Duplicated orphan filtering.
convertFromOpencodeFormatpre-filterstoolswithfindOpencodeToolOwner, whileorphanMcpToolFiltersToRulesyncinmcp-transport.tshas its own raw-prefix check. The latter is redundant for this caller but still needed by Kilo. - Lossy normalisation on round trip.
read.filebecomesread_fileafter import, so it no longer matches the real tool name on other targets (e.g. Claude Code). This matches OpenCode behaviour but is not documented. - Colliding sanitized server names. For servers
a.banda_b,findOpencodeMcpToolKeyOwnerkeeps the first server, so the second server'sdisabledToolsare re-attributed on import. First-wins behaviour is neither tested nor documented. - Test gaps.
- Orphan server names containing
.or-. - An explicit V2 (
mcp.serversenvelope) case with sanitized keys. - Regeneration over an existing file that still has legacy raw keys such as
my.server_delete.file(confirmapplySharedConfigPatchreplacestoolswholesale). - Use
toEqualinstead oftoMatchObjectfor the imported filter fields.
- Orphan server names containing
Solution / Next Steps
- (1) Merge colliding keys with "false wins" semantics, or emit a warning when two entries collapse to one key.
- (2) Hoist the empty set to a module-level
ReadonlySetconstant and add the explanatory comment. - (3) Add a comment on the two-layer filtering, or let the shared helper take an owner predicate so the logic lives in one place.
- (4) Document the dot-to-underscore normalisation under
docs/reference, or record it as known behaviour. - (5) Add a test or comment that documents first-wins ownership for colliding server names.
- (6) Add the missing tests listed above and tighten the assertions.
Status (2026-10-31, autonomous run): item 1 (colliding keys flipping a deny into an allow) is covered by the external PR #3699, which is waiting for a maintainer review. Items 2–6 touch the same two files (src/features/mcp/opencode-mcp.ts and its test), so this run leaves them until #3699 lands rather than racing a conflicting PR against it.
Status (2026-10-31): item 1 landed with #3699 (an existing deny now survives a later allow when server names sanitize to the same key). Items 2–6 are still open and no longer blocked.
I'd like to pick up items 2–6 in one PR on top of #3699. I'll open it shortly.