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

Method validateParams

src/core/tools/UseMcpToolTool.ts:110–160  ·  view source on GitHub ↗
(
		task: Task,
		params: UseMcpToolParams,
		pushToolResult: (content: string) => void,
	)

Source from the content-addressed store, hash-verified

108 }
109
110 private async validateParams(
111 task: Task,
112 params: UseMcpToolParams,
113 pushToolResult: (content: string) => void,
114 ): Promise<ValidationResult> {
115 if (!params.server_name) {
116 task.consecutiveMistakeCount++
117 task.recordToolError("use_mcp_tool")
118 pushToolResult(await task.sayAndCreateMissingParamError("use_mcp_tool", "server_name"))
119 return { isValid: false }
120 }
121
122 if (!params.tool_name) {
123 task.consecutiveMistakeCount++
124 task.recordToolError("use_mcp_tool")
125 pushToolResult(await task.sayAndCreateMissingParamError("use_mcp_tool", "tool_name"))
126 return { isValid: false }
127 }
128
129 // Some LLMs emit arguments as JSON-encoded strings rather than objects.
130 // Parse them early so the type check below sees the unwrapped object.
131 if (typeof params.arguments === "string") {
132 try {
133 params.arguments = JSON.parse(params.arguments)
134 } catch {}
135 }
136
137 let parsedArguments: Record<string, unknown> | undefined
138 if (params.arguments !== undefined) {
139 if (typeof params.arguments !== "object" || params.arguments === null || Array.isArray(params.arguments)) {
140 task.consecutiveMistakeCount++
141 task.recordToolError("use_mcp_tool")
142 await task.say("error", t("mcp:errors.invalidJsonArgument", { toolName: params.tool_name }))
143 task.didToolFailInCurrentTurn = true
144 pushToolResult(
145 formatResponse.toolError(
146 formatResponse.invalidMcpToolArgumentError(params.server_name, params.tool_name),
147 ),
148 )
149 return { isValid: false }
150 }
151 parsedArguments = params.arguments
152 }
153
154 return {
155 isValid: true,
156 serverName: params.server_name,
157 toolName: params.tool_name,
158 parsedArguments,
159 }
160 }
161
162 private async validateToolExists(
163 task: Task,

Callers 1

executeMethod · 0.95

Calls 6

tFunction · 0.90
pushToolResultFunction · 0.85
recordToolErrorMethod · 0.80
parseMethod · 0.80
sayMethod · 0.80

Tested by

no test coverage detected