MCPcopy Create free account
hub / github.com/Louisym/MiniCC / execute

Method execute

tutorials/03_tool_system.py:284–306  ·  view source on GitHub ↗

执行一个工具。 参数: tool_name: 工具名称 input_json: 参数(JSON 字符串) 返回: (输出结果, 是否出错)

(self, tool_name: str, input_json: str)

Source from the content-addressed store, hash-verified

282 return self # 返回自身,这样可以连续调用 .register().register()
283
284 def execute(self, tool_name: str, input_json: str) -> tuple[str, bool]:
285 """
286 执行一个工具。
287
288 参数:
289 tool_name: 工具名称
290 input_json: 参数(JSON 字符串)
291 返回:
292 (输出结果, 是否出错)
293 """
294 if tool_name not in self._handlers:
295 return (f"Unknown tool: {tool_name}", True)
296
297 try:
298 params = json.loads(input_json) if input_json else {}
299 except json.JSONDecodeError:
300 return (f"Invalid JSON input: {input_json}", True)
301
302 try:
303 result = self._handlers[tool_name](params)
304 return (result, False)
305 except Exception as e:
306 return (f"Tool execution error: {e}", True)
307
308 def get_specs(self) -> list[ToolSpec]:
309 """获取所有已注册工具的说明书"""

Callers 2

mainFunction · 0.45

Calls

no outgoing calls

Tested by 1