Answer an MCP Handshake
MCP is plain JSON-RPC 2.0 underneath. A request is {"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}; the response echoes the id and carries a result.
Implement handle(request) returning the response dict:
initialize:resultis theSERVER_CAPABILITIESdict defined for you.tools/list:resultholds theTOOLSlist defined for you under atoolskey.- Anything else: carry
errorinstead ofresult, never both, with code-32601:{"jsonrpc": "2.0", "id": 1, "error": {"code": -32601, "message": "Method not found"}}.
Always echo the request's id. A client can have several requests in flight, and the id is the only thing that says which reply belongs to which.