How It Works
Before diving into reference docs, understand the big picture.
Architectureโ
โโโโโโโโโโโโโโโโ JSON-RPC over โโโโโโโโโโโโโโโโโโโโ
โ โ โโโโ transport โโโโโโโบ โ โ
โ MCP Client โ (stdio / HTTP / โ MCP Server โ
โ (LLM host) โ Streamable HTTP) โ (your code) โ
โ โ โ โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ โ
โ "List tools?" โ "2 tools: say_hello, add"
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโบ โ
โ โ
โ "Call say_hello({name: World})" โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโบ โ
โ โ
โ "Hello, World! ๐" โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The client (Claude, ChatGPT, your own code) sends JSON-RPC requests over a transport. The server handles them and returns responses. The SDK manages the protocol layer - you write the handler methods.
Key componentsโ
| Component | What it does |
|---|---|
| Transport | How messages travel: stdio (child process), Streamable HTTP (remote), or SSE (legacy) |
| Protocol | JSON-RPC 2.0 over the transport - requests, responses, notifications, errors |
| Handler | Your code: ServerHandler / ClientHandler trait implementations |
| Macros | mcp_tool, tool_box!, mcp_elicit - generate MCP schemas from Rust structs |
| McpServer / McpClient | Traits injected into handlers - gives access to server/client capabilities |
The initialization handshakeโ
Every MCP connection starts with a two-step handshake:
initialize- client sends its identity and capabilities; server responds with its identity, capabilities, and protocol versioninitialized- client acknowledges; server'son_initialized()hook fires
After initialization, the client and server know what each other supports and can exchange requests freely.
Server vs Client rolesโ
| Server | Client | |
|---|---|---|
| Provides | Tools, resources, prompts | LLM, user interaction, filesystem roots |
| Requests | List/read resources, elicitation, sampling | Call tools, read resources, get prompts |
| Notifies | Resource/tool/prompt list changed | Logging level, cancellation, initialized |
| Implement | ServerHandler / ServerHandlerCore | ClientHandler / ClientHandlerCore |
Transports at a glanceโ
| Transport | Clients | Resumable | Health checks | Best for |
|---|---|---|---|---|
| Stdio | 1 | No | No | Local tools, desktop clients |
| Streamable HTTP | Many | Yes | Yes | Services, agents, production |
| SSE | Many | No | No | Legacy compatibility only |
Nextโ
Dive into Server Essentials or Client Essentials, or jump to the reference sections for detailed API docs.