Writing a tiny MCP server — registries, dispatch, and the response shape — step 8 of 9
Write call_tool(name, args, registry) — the full dispatcher.
It must:
- If
nameis not inregistry, return the MCP error envelope with textunknown tool: <name>. - Otherwise, loop over
tool["inputSchema"]["required"]and return an error envelope with textmissing required arg: <key>for the first missing required arg. - If everything validates, call
tool["handler"](args)and wrap the return value as the MCP success envelope.
All envelopes have the shape:
{"isError": bool, "content": [{"type": "text", "text": str}]}
Expected output:
ok hello alex
err missing required arg: name
err unknown tool: ghost
⌘↵ runs the editor.read, then continue.
Write call_tool(name, args, registry) — the full dispatcher.
It must:
- If
nameis not inregistry, return the MCP error envelope with textunknown tool: <name>. - Otherwise, loop over
tool["inputSchema"]["required"]and return an error envelope with textmissing required arg: <key>for the first missing required arg. - If everything validates, call
tool["handler"](args)and wrap the return value as the MCP success envelope.
All envelopes have the shape:
{"isError": bool, "content": [{"type": "text", "text": str}]}
Expected output:
ok hello alex
err missing required arg: name
err unknown tool: ghost
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.