Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

Problem

When models like Claude Opus 4.5 use native tool calling, they convert hyphens to underscores in function names. This causes MCP tool names like mcp--atlassian-jira--search to be returned as mcp__atlassian_jira__search, which the parser rejected as invalid.

Solution

Implemented separator normalization AND fuzzy matching for server/tool name recovery:

1. Separator Normalization

  • isMcpTool() recognizes both mcp-- and mcp__ prefixes
  • parseMcpToolName() handles both separator formats and returns wasMangled flag

2. Server/Tool Name Recovery (via fuzzy matching)

  • generatePossibleOriginalNames() generates all underscore-to-hyphen combinations (2^n, limited to 8 underscores)
  • findMatchingServerName() fuzzy matches atlassian_jiraatlassian-jira
  • findMatchingToolName() same for tool names
  • UseMcpToolTool.validateToolExists() integrates fuzzy matching

Files Modified

  • src/utils/mcp-name.ts - Separator constants, parsing, fuzzy matching functions
  • src/core/assistant-message/NativeToolCallParser.ts - Use isMcpTool() for detection
  • src/core/tools/UseMcpToolTool.ts - Integrate fuzzy matching for name resolution
  • src/utils/__tests__/mcp-name.spec.ts - 56 tests including end-to-end issue scenarios

Test Results

All tests pass: 5215 passed, 49 skipped

Fixes #10642

Linear: ROO-496


Important

Fixes MCP tool name mangling by implementing separator normalization and fuzzy matching for name recovery.

  • Behavior:
    • isMcpTool() in mcp-name.ts now recognizes both mcp-- and mcp__ prefixes.
    • parseMcpToolName() handles both separator formats and returns wasMangled flag.
    • generatePossibleOriginalNames() creates combinations of underscore-to-hyphen replacements.
    • findMatchingServerName() and findMatchingToolName() perform fuzzy matching.
    • UseMcpToolTool.validateToolExists() integrates fuzzy matching.
  • Files Modified:
    • mcp-name.ts: Added separator constants, parsing, and fuzzy matching functions.
    • NativeToolCallParser.ts: Uses isMcpTool() for detection.
    • UseMcpToolTool.ts: Integrates fuzzy matching for name resolution.
    • mcp-name.spec.ts: 56 tests including end-to-end issue scenarios.
  • Test Results:
    • All tests pass: 5215 passed, 49 skipped.

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

When models like Claude Opus 4.5 use native tool calling, they convert
hyphens to underscores in function names. This causes MCP tool names
like mcp--atlassian-jira--search to be returned as mcp__atlassian_jira__search.

Changes:
- Add MCP_TOOL_SEPARATOR_MANGLED constant to recognize __ separator
- Update isMcpTool() to recognize both mcp-- and mcp__ prefixes
- Update parseMcpToolName() to handle both separator formats
- Add generatePossibleOriginalNames() for underscore-to-hyphen combinations
- Add findMatchingServerName() and findMatchingToolName() for fuzzy matching
- Integrate fuzzy matching in UseMcpToolTool.validateToolExists()

Fixes: #10642
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners January 12, 2026 18:46
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jan 12, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 12, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly handles MCP tool names with hyphens when models convert them to underscores in native tool calling. The fix includes:

  • Recognition of both mcp-- and mcp__ prefixes
  • Parsing of both separator formats with wasMangled flag
  • Fuzzy matching to resolve mangled server/tool names back to originals
  • Integration in both XML and native MCP tool execution paths
  • Comprehensive test coverage (56 tests)

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

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 12, 2026
}

// Get all servers to find the specific one
// Use fuzzy matching to handle model-mangled names (hyphens converted to underscores)
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't like the fuzzy option Claude proposed me at first, so I proposed to encode the hyphens, see pdecat#1

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, I did not submit the PR as I was waiting for my issue to be accepted.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can submit it if you'd like

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, submitted #10644

@daniel-lxs daniel-lxs closed this Jan 12, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 12, 2026
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jan 12, 2026
@daniel-lxs
Copy link
Member Author

Closing in favor of #10644

@daniel-lxs daniel-lxs deleted the feature/roo-496-fix-mcp-tool-names-with-hyphens-failing-in-native-tool branch January 12, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] MCP tool names with hyphens fail when using native tool calling

4 participants