Replace hyphen encoding with fuzzy matching for MCP tool names #10775
+358
−159
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.
Problem
The current approach to handling MCP tool names with hyphens encodes them as triple underscores (
___), causing tool names to become excessively long. For example,resolve-library-idbecomesresolve___library___id. This bloats tool names and can cause truncation issues with the 64-character limit imposed by some providers.Related to: #10766
Linear: https://linear.app/roocode/issue/COM-501/replace-hyphen-encoding-with-fuzzy-matching-for-mcp-tool-names
Solution
Replace the encoding approach with fuzzy matching that treats hyphens and underscores as equivalent when comparing tool names. This way:
Changes
src/utils/mcp-name.ts: RemovedHYPHEN_ENCODINGanddecodeMcpName(). AddednormalizeForComparison()andtoolNamesMatch()for fuzzy matching.src/services/mcp/McpHub.ts: EnhancedfindServerNameBySanitizedName()with a fuzzy matching fallback.Example
Before (encoding):
resolve-library-id→mcp--context7--resolve___library___idAfter (fuzzy matching):
resolve-library-id→mcp--context7--resolve-library-idmcp__context7__resolve_library_id→ fuzzy match finds itImportant
Replaces hyphen encoding with fuzzy matching for MCP tool names, preserving hyphens and simplifying name handling.
mcp-name.ts, treating hyphens and underscores as equivalent.UseMcpToolTool.tsto usetoolNamesMatch()for tool validation.normalizeForComparison()andtoolNamesMatch()inmcp-name.tsfor fuzzy matching.HYPHEN_ENCODINGanddecodeMcpName()frommcp-name.ts.McpHub.tsto use fuzzy matching infindServerNameBySanitizedName().useMcpToolTool.spec.tsandmcp-name.spec.tsto reflect new behavior.This description was created by
for ce45c97. You can customize this summary. It will automatically update as commits are pushed.