Serve a Tool Call over MCP
Implement call_tool(request) for MCP tools/call. The params look like {"name": "add", "arguments": {"a": 2, "b": 3}}; the tools live in HANDLERS.
- Run the tool and return its value, stringified, under
resultwith theidechoed:{"content": [{"type": "text", "text": "5"}]}. - Unknown tool name. A bad request, not a server fault:
errorwith code-32602, "Invalid params". - A tool that raises. No crash, no leaked traceback. Return a normal
resultwithisError: trueand the exception (type and message) in the text block, so the model sees the failure. A successful call has noisErrorkey. - Missing
arguments. The key may be absent for a no-argument tool likeping.
The catch: a tool the server does not have is a protocol error; a tool that exists and fails is a successful exchange reporting an application error.