Skip to content

< all problems18 · Level 06, MCP

Answer an MCP Handshake

easy · implement · MCP

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:

  1. initialize: result is the SERVER_CAPABILITIES dict defined for you.
  2. tools/list: result holds the TOOLS list defined for you under a tools key.
  3. Anything else: carry error instead of result, 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.