@@ -4,6 +4,7 @@ import { Task } from "../task/Task"
44import { formatResponse } from "../prompts/responses"
55import { t } from "../../i18n"
66import type { ToolUse } from "../../shared/tools"
7+ import { toolNamesMatch } from "../../utils/mcp-name"
78
89import { BaseTool , ToolCallbacks } from "./BaseTool"
910
@@ -43,14 +44,18 @@ export class UseMcpToolTool extends BaseTool<"use_mcp_tool"> {
4344 return
4445 }
4546
47+ // Use the resolved tool name (original name from the server) for MCP calls
48+ // This handles cases where models mangle hyphens to underscores
49+ const resolvedToolName = toolValidation . resolvedToolName ?? toolName
50+
4651 // Reset mistake count on successful validation
4752 task . consecutiveMistakeCount = 0
4853
4954 // Get user approval
5055 const completeMessage = JSON . stringify ( {
5156 type : "use_mcp_tool" ,
5257 serverName,
53- toolName,
58+ toolName : resolvedToolName ,
5459 arguments : params . arguments ? JSON . stringify ( params . arguments ) : undefined ,
5560 } satisfies ClineAskUseMcpServer )
5661
@@ -65,7 +70,7 @@ export class UseMcpToolTool extends BaseTool<"use_mcp_tool"> {
6570 await this . executeToolAndProcessResult (
6671 task ,
6772 serverName ,
68- toolName ,
73+ resolvedToolName ,
6974 parsedArguments ,
7075 executionId ,
7176 pushToolResult ,
@@ -137,7 +142,7 @@ export class UseMcpToolTool extends BaseTool<"use_mcp_tool"> {
137142 serverName : string ,
138143 toolName : string ,
139144 pushToolResult : ( content : string ) => void ,
140- ) : Promise < { isValid : boolean ; availableTools ?: string [ ] } > {
145+ ) : Promise < { isValid : boolean ; availableTools ?: string [ ] ; resolvedToolName ?: string } > {
141146 try {
142147 // Get the MCP hub to access server information
143148 const provider = task . providerRef . deref ( )
@@ -186,8 +191,8 @@ export class UseMcpToolTool extends BaseTool<"use_mcp_tool"> {
186191 return { isValid : false , availableTools : [ ] }
187192 }
188193
189- // Check if the requested tool exists
190- const tool = server . tools . find ( ( tool ) => tool . name === toolName )
194+ // Check if the requested tool exists (using fuzzy matching to handle model mangling of hyphens)
195+ const tool = server . tools . find ( ( t ) => toolNamesMatch ( t . name , toolName ) )
191196
192197 if ( ! tool ) {
193198 // Tool not found - provide list of available tools
@@ -232,8 +237,8 @@ export class UseMcpToolTool extends BaseTool<"use_mcp_tool"> {
232237 return { isValid : false , availableTools : enabledToolNames }
233238 }
234239
235- // Tool exists and is enabled
236- return { isValid : true , availableTools : server . tools . map ( ( tool ) => tool . name ) }
240+ // Tool exists and is enabled - return the original tool name for use with the MCP server
241+ return { isValid : true , availableTools : server . tools . map ( ( t ) => t . name ) , resolvedToolName : tool . name }
237242 } catch ( error ) {
238243 // If there's an error during validation, log it but don't block the tool execution
239244 // The actual tool call might still fail with a proper error
0 commit comments