Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Jan 16, 2026

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-id becomes resolve___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:

  1. Hyphens are preserved in tool names (no encoding needed)
  2. Tool names stay short and readable
  3. When models convert hyphens to underscores during native tool calling, the fuzzy matcher finds the correct tool

Changes

  • src/utils/mcp-name.ts: Removed HYPHEN_ENCODING and decodeMcpName(). Added normalizeForComparison() and toolNamesMatch() for fuzzy matching.
  • src/services/mcp/McpHub.ts: Enhanced findServerNameBySanitizedName() with a fuzzy matching fallback.
  • Tests: Updated tests to reflect the new behavior.

Example

Before (encoding):

  • resolve-library-idmcp--context7--resolve___library___id

After (fuzzy matching):

  • resolve-library-idmcp--context7--resolve-library-id
  • Model mangles to mcp__context7__resolve_library_id → fuzzy match finds it

Important

Replaces hyphen encoding with fuzzy matching for MCP tool names, preserving hyphens and simplifying name handling.

  • Behavior:
    • Replaces hyphen encoding with fuzzy matching in mcp-name.ts, treating hyphens and underscores as equivalent.
    • Preserves hyphens in tool names, avoiding encoding to triple underscores.
    • Updates UseMcpToolTool.ts to use toolNamesMatch() for tool validation.
  • Functions:
    • Adds normalizeForComparison() and toolNamesMatch() in mcp-name.ts for fuzzy matching.
    • Removes HYPHEN_ENCODING and decodeMcpName() from mcp-name.ts.
  • Files:
    • Updates McpHub.ts to use fuzzy matching in findServerNameBySanitizedName().
    • Modifies tests in useMcpToolTool.spec.ts and mcp-name.spec.ts to reflect new behavior.

This description was created by Ellipsis for ce45c97. You can customize this summary. It will automatically update as commits are pushed.

Replace triple-underscore encoding (___) with fuzzy matching that treats
hyphens and underscores as equivalent. This keeps MCP tool names short
and readable while still handling model mangling of hyphens.

- Remove HYPHEN_ENCODING and decodeMcpName()
- Add normalizeForComparison() and toolNamesMatch() for fuzzy matching
- Update McpHub.findServerNameBySanitizedName() with fuzzy match fallback
- Update tests to reflect new behavior

Related to: #10766
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners January 16, 2026 15:32
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Enhancement New feature or request labels Jan 16, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 16, 2026

Rooviewer Clock   See task on Roo Cloud

Reviewed the new commits that add fuzzy matching for tool names. The previous issue has been addressed.

  • Fuzzy matching is implemented for server names but missing for tool names - when models convert hyphens to underscores in tool names, tool validation and MCP calls will fail
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

When models mangle hyphens to underscores in tool names (e.g., 'get-user-profile'
becomes 'get_user_profile'), we now use fuzzy matching to find the correct tool
and pass the original hyphenated name to the MCP server.

- Use toolNamesMatch() in validateToolExists to find tools with mangled names
- Return the resolved (original) tool name for use in MCP calls
- Add test for fuzzy matching scenario
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 16, 2026
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jan 16, 2026
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: PR [Needs Review]

Development

Successfully merging this pull request may close these issues.

2 participants