Writing a tiny MCP server — registries, dispatch, and the response shape — step 9 of 9
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
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 withunknown tool: <name>. Missing required arg → error envelope withmissing 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
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
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 withunknown tool: <name>. Missing required arg → error envelope withmissing 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
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.