Week 14 • Day 1Week 14

Day 1:Week 14, Day 1: `MCP` Architecture (`Host`, `Client`, `Server`) & Wire-Level `JSON-RPC 2.0` Protocol

Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz

Week 14, Day 1: MCP Architecture (Host, Client, Server) & Wire-Level JSON-RPC 2.0 Protocol


1. Why MCP Solved the M×NM \times N Integration Bottleneck

Before the Model Context Protocol (MCP) (introduced by Anthropic and adopted across IDEs, agents, and cloud platforms), connecting MM AI applications (Claude Desktop, Cursor, Antigravity, custom FastAPI agents) to NN data sources (Postgres, GitHub, Kubernetes, Slack, Jira) required writing M×NM \times N bespoke connectors! MCP acts as the "USB-C Port for AI Applications", reducing M×NM \times N to M+NM + N:

code
┌─────────────────────────────────────────────────────────────────────────┐ │ MCP HOST (e.g., AI IDE, FastAPI Agent Backend) │ │ ├── MCP Client 1 ◄══ JSON-RPC 2.0 (stdio / HTTP) ══► MCP Server: GitHub│ │ ├── MCP Client 2 ◄══ JSON-RPC 2.0 (stdio / HTTP) ══► MCP Server: K8s │ │ └── MCP Client 3 ◄══ JSON-RPC 2.0 (stdio / HTTP) ══► MCP Server: SQLite│ └─────────────────────────────────────────────────────────────────────────┘

2. Wire-Level JSON-RPC 2.0 Specification in MCP

Every message exchanged between an MCP Client and MCP Server is a valid JSON-RPC 2.0 packet:

  1. Request (Requires id):
    json
    {"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}
  2. Notification (No id field — one-way event):
    json
    {"jsonrpc": "2.0", "method": "notifications/initialized"}
  3. Success Response (Echoes matching id):
    json
    {"jsonrpc": "2.0", "id": 1, "result": {"tools": [...]}}
  4. Error Response (Standard JSON-RPC 2.0 Error Codes):
    • -32700: Parse error (Invalid JSON)
    • -32600: Invalid Request (Missing "jsonrpc": "2.0")
    • -32601: Method not found (Unknown MCP method)
    • -32602: Invalid params (Missing or malformed tool/resource parameters)
    • -32603: Internal error

In Simple English: MCP = The USB-C Port for AI Agents

Before USB-C, every phone needed a separate custom charger. Before MCP (Model Context Protocol), connecting 5 AI apps (Claude, Cursor, Windsurf, Custom Agent, Chat UI) to 10 tools (Postgres, GitHub, Slack, Jira...) required writing $5 \times 10 = 50$ fragile custom adapters! With MCP:

  • Build 1 MCP Server once for your Postgres database or Runbook folder.
  • ANY MCP Host/Client snaps right into it cleanly over standard JSON-RPC 2.0 messages (initialize, tools/list, tools/call) — turning M×NM \times N chaos into simple M+NM + N plug-and-play!