-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: handle MCP tool names with hyphens in native tool calling #10643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle MCP tool names with hyphens in native tool calling #10643
Conversation
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
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:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| } | ||
|
|
||
| // Get all servers to find the specific one | ||
| // Use fuzzy matching to handle model-mangled names (hyphens converted to underscores) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, submitted #10644
|
Closing in favor of #10644 |
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--searchto be returned asmcp__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 bothmcp--andmcp__prefixesparseMcpToolName()handles both separator formats and returnswasMangledflag2. Server/Tool Name Recovery (via fuzzy matching)
generatePossibleOriginalNames()generates all underscore-to-hyphen combinations (2^n, limited to 8 underscores)findMatchingServerName()fuzzy matchesatlassian_jira→atlassian-jirafindMatchingToolName()same for tool namesUseMcpToolTool.validateToolExists()integrates fuzzy matchingFiles Modified
src/utils/mcp-name.ts- Separator constants, parsing, fuzzy matching functionssrc/core/assistant-message/NativeToolCallParser.ts- UseisMcpTool()for detectionsrc/core/tools/UseMcpToolTool.ts- Integrate fuzzy matching for name resolutionsrc/utils/__tests__/mcp-name.spec.ts- 56 tests including end-to-end issue scenariosTest 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.
isMcpTool()inmcp-name.tsnow recognizes bothmcp--andmcp__prefixes.parseMcpToolName()handles both separator formats and returnswasMangledflag.generatePossibleOriginalNames()creates combinations of underscore-to-hyphen replacements.findMatchingServerName()andfindMatchingToolName()perform fuzzy matching.UseMcpToolTool.validateToolExists()integrates fuzzy matching.mcp-name.ts: Added separator constants, parsing, and fuzzy matching functions.NativeToolCallParser.ts: UsesisMcpTool()for detection.UseMcpToolTool.ts: Integrates fuzzy matching for name resolution.mcp-name.spec.ts: 56 tests including end-to-end issue scenarios.This description was created by
for d1ad5a7. You can customize this summary. It will automatically update as commits are pushed.