promptdojo_

Writing a tiny MCP server — registries, dispatch, and the response shape — step 7 of 9

The dispatcher below calls the handler without checking whether the required arguments are present. If a required key is missing, the handler crashes with a KeyError deep in user code — instead of returning a clean MCP error.

Fix it: before calling the handler, check each name in tool["inputSchema"]["required"] against args. If any are missing, return the MCP error envelope with text missing required arg: <name> (the first missing one is fine).

Expected output:

True
missing required arg: city
The break is on line 3 — but read the whole snippet first.

full-screen editor opens — close anytime to keep reading.