fix(mcp): use colon separator for tool keys to prevent underscore collisions#33354
Open
MeloMei wants to merge 1 commit into
Open
fix(mcp): use colon separator for tool keys to prevent underscore collisions#33354MeloMei wants to merge 1 commit into
MeloMei wants to merge 1 commit into
Conversation
…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
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.
Issue for this PR
Closes #33306
Type of change
What does this PR do?
MCP tool keys are constructed as
sanitize(server) + "_" + sanitize(tool). Sincesanitize()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":"inpackages/opencode/src/mcp/index.ts:646. This is consistent withcatalog.ts:103which already uses":"for prompts and resources (where:is rejected bysanitize, making it unambiguous).Test assertions in
lifecycle.test.tsare updated to match the new key format.How did you verify your code works?
Verified by reading the source code:
sanitize()atcatalog.ts:110preserves_but rejects:catalog.ts:103(prompts/resources) already uses:separator without issues_to extract server/tool namesScreenshots / recordings
N/A — no UI changes.
Checklist