MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / execute

Method execute

src/core/tools/UseMcpToolTool.ts:30–96  ·  view source on GitHub ↗
(params: UseMcpToolParams, task: Task, callbacks: ToolCallbacks)

Source from the content-addressed store, hash-verified

28 readonly name = "use_mcp_tool" as const
29
30 async execute(params: UseMcpToolParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
31 const { askApproval, handleError, pushToolResult } = callbacks
32
33 try {
34 // Validate parameters
35 const validation = await this.validateParams(task, params, pushToolResult)
36 if (!validation.isValid) {
37 return
38 }
39
40 const { serverName, toolName, parsedArguments } = validation
41
42 // Validate that the tool exists on the server
43 const toolValidation = await this.validateToolExists(task, serverName, toolName, pushToolResult)
44 if (!toolValidation.isValid) {
45 return
46 }
47
48 // Execution-time defense: reject invocation of a server not permitted by the mode's
49 // allowedMcpServers allowlist, even if the model referenced it from history. This runs
50 // before approval/execution so a disallowed server can never be reached.
51 const serverAllowed = await ensureMcpServerAllowed(
52 task,
53 "use_mcp_tool",
54 serverName,
55 pushToolResult,
56 formatResponse.toolError,
57 )
58 if (!serverAllowed) {
59 return
60 }
61
62 // Use the resolved tool name (original name from the server) for MCP calls
63 // This handles cases where models mangle hyphens to underscores
64 const resolvedToolName = toolValidation.resolvedToolName ?? toolName
65
66 // Reset mistake count on successful validation
67 task.consecutiveMistakeCount = 0
68
69 // Get user approval
70 const completeMessage = JSON.stringify({
71 type: "use_mcp_tool",
72 serverName,
73 toolName: resolvedToolName,
74 arguments: params.arguments ? JSON.stringify(params.arguments) : undefined,
75 } satisfies ClineAskUseMcpServer)
76
77 const executionId = task.lastMessageTs?.toString() ?? Date.now().toString()
78 const didApprove = await askApproval("use_mcp_server", completeMessage)
79
80 if (!didApprove) {
81 return
82 }
83
84 // Execute the tool and process results
85 await this.executeToolAndProcessResult(
86 task,
87 serverName,

Callers

nothing calls this directly

Calls 7

validateParamsMethod · 0.95
validateToolExistsMethod · 0.95
ensureMcpServerAllowedFunction · 0.90
askApprovalFunction · 0.85
handleErrorFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected