Skip to content

fix(mcp): use colon separator for tool keys to prevent underscore collisions#33354

Open
MeloMei wants to merge 1 commit into
anomalyco:devfrom
MeloMei:mcp-tool-key
Open

fix(mcp): use colon separator for tool keys to prevent underscore collisions#33354
MeloMei wants to merge 1 commit into
anomalyco:devfrom
MeloMei:mcp-tool-key

Conversation

@MeloMei

@MeloMei MeloMei commented Jun 22, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #33306

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

MCP tool keys are constructed as sanitize(server) + "_" + sanitize(tool). Since sanitize() preserves underscores ([^a-zA-Z0-9_-]), the _ separator is ambiguous. Different (server, tool) pairs can produce identical keys — e.g. server "foo" + tool "bar_baz" and server "foo_bar" + tool "baz" both yield "foo_bar_baz". The later tool silently overwrites the earlier one.

The fix changes the separator from "_" to ":" in packages/opencode/src/mcp/index.ts:646. This is consistent with catalog.ts:103 which already uses ":" for prompts and resources (where : is rejected by sanitize, making it unambiguous).

Test assertions in lifecycle.test.ts are updated to match the new key format.

How did you verify your code works?

Verified by reading the source code:

  • Confirmed sanitize() at catalog.ts:110 preserves _ but rejects :
  • Confirmed catalog.ts:103 (prompts/resources) already uses : separator without issues
  • Confirmed no code in the codebase splits tool keys on _ to extract server/tool names
  • Updated the 3 existing test assertions that check tool key format

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…sions

Tool keys were built as sanitize(server) + "_" + sanitize(tool), but
sanitize() preserves underscores. Different (server, tool) pairs could
produce identical keys, silently overwriting each other. The prompts and
resources path in catalog.ts already uses ":" as separator — apply the
same pattern for tool registration.

Fixes anomalyco#33306
Copilot AI review requested due to automatic review settings June 22, 2026 11:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

fix(mcp): tool key collision when server or tool names contain underscores

2 participants