An AI agent without tools can only talk. MCP is the open standard (introduced by Anthropic, Nov 2024) that lets an agent like Claude Code pull live data, query databases, drive browsers, and deploy code — all over one JSON-RPC 2.0 protocol.
// click a server (or RUN) to trace a // full MCP request/response cycle
The application the user runs — Claude Code, Claude Desktop, an IDE. It owns the LLM loop, enforces permissions, and decides which servers to attach.
The connector inside the host. One client per server, maintaining a stateful 1:1 session. It speaks JSON-RPC 2.0 over stdio (local) or Streamable HTTP (remote).
A lightweight capability wrapper. It exposes a database, a browser, a filesystem, or an API as standard primitives — write it once, and every MCP host can use it.
The N x M problem: before MCP, connecting N apps to M tools needed N x M custom integrations. A shared protocol collapses that to N + M — each side implements MCP once.
Lifecycle: every session starts with an initialize handshake where client and server negotiate protocol version and exchange capability flags before any tool runs.
Discovery is dynamic: the agent calls tools/list at runtime, so servers can add or change tools without redeploying the host.
Security rule of thumb: the host mediates everything — tool calls should be permission-gated, and results are untrusted input (watch for prompt injection in returned data).
stdio: the host launches the server as a child process and pipes newline-delimited JSON-RPC over stdin/stdout. Zero network setup, ideal for local tools like filesystem or git servers.
Streamable HTTP: a single endpoint accepts POSTed JSON-RPC messages and can stream responses back via Server-Sent Events. This is how remote/hosted MCP servers work, typically secured with OAuth 2.1.
Everything is JSON-RPC 2.0: three message kinds only — requests (have an id, expect a reply), responses (carry result or error for that id), and notifications (fire-and-forget, e.g. notifications/tools/list_changed).
Sampling — the reverse direction: a server can ask the client's LLM to complete text via sampling/createMessage, letting servers embed intelligence without shipping their own API keys.