promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

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

Checkpoint

One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.

Final drill. You're prototyping an MCP server before wrapping it in JSON-RPC stdio — this is the dispatch shape you'll port.

Build the whole tiny server. Two functions:

  • list_tools(registry) — returns a list of {"name": ..., "description": ...} dicts (one per tool), in registry insertion order. No handlers in the output.
  • call_tool(name, args, registry) — the dispatcher from the previous step. Unknown tool → error envelope with unknown tool: <name>. Missing required arg → error envelope with missing required arg: <key>. Success → wrap handler return value in the success envelope.

Then exercise it: list tools, call each with valid args, and call with an unregistered name.

Expected output:

[{'name': 'add', 'description': 'Add two numbers.'}, {'name': 'shout', 'description': 'Uppercase a string.'}]
5
HELLO
unknown tool: ghost

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