The Model Context Protocol (MCP) is an open standard — announced November 2024, built on JSON-RPC 2.0 — for connecting AI applications to tools, data, and prompts. It solves the N×M integration problem: instead of every AI host writing custom glue for every data source, each side speaks one protocol. Hosts implement the client half; you implement the server half.
This article is a flows-and-diagrams tour: the components, the lifecycle of a connection, the tool-call loop, the reverse flows (sampling, elicitation), and the transports that carry the messages.
The big picture
MCP follows a client–host–server architecture. A host is the AI application (Claude Code, Claude Desktop, an IDE, your own agent runtime). The host runs one MCP client per server it connects to, and each server exposes capabilities over the wire.
┌──────────────────────────────────────────────────────────────────────────┐
│ MCP Host │
│ (Claude Code, an IDE, a chat app, your agent runtime) │
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ MCP client │ │ MCP client │ │ MCP client │ │
└───────┼─────────────────────────┼─────────────────────────┼──────────────┘
│ │ │
stdio HTTP HTTP
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Local │ │ Remote │ │ Remote │
│ Server │ │ Server │ │ Server │
│ (spawn) │ │ /mcp │ │ /mcp │
└─────┬────┘ └─────┬────┘ └─────┬────┘
│ │ │
┌──────────┐ ┌──────────┐ ┌──────────┐
│ files, │ │ your │ │ third- │
│ shell, │ │ SaaS / │ │ party │
│ local │ │ APIs │ │ APIs │
│ DB │ │ │ │ │
└──────────┘ └──────────┘ └──────────┘
Why one client per server? Isolation. Each connection carries its own capabilities and security boundary — a sketchy filesystem server can’t touch the connection to your database server.
Who owns what: the primitives
Every primitive is exposed through a JSON-RPC request/response pair, but the control varies — this is the most important design distinction in MCP:
| Primitive | Exposed by | Controlled by | Flow |
|---|---|---|---|
| Tools | server | the model (autonomous) | tools/list → tools/call |
| Resources | server | the host app / user | resources/list → resources/read |
| Prompts | server | the user (slash-menu) | prompts/list → prompts/get |
| Sampling | client API | server requests it | sampling/createMessage |
| Elicitation | client API | server requests it | elicitation/create |
| Roots | client API | server requests them | roots/list |
Tools are model-controlled: the model decides to call them. Resources are app-controlled: the application reads and attaches them as context. Prompts are user-controlled: the human picks the template. This split is why MCP is more than just “function calling over HTTP”.
Flow 1 — lifecycle: initialize and discovery
Classic connections (spec revisions through 2025-11-25) open with a handshake that negotiates a protocol version and each side’s capabilities. After that, the client discovers what the server offers:
MCP client MCP server
│ │
initialize
─────────────────────────────────────────────────────────────────▶
· 1. protocolVersion, capabilities, clientInfo {name, version}
│ │
initialize result
◀─────────────────────────────────────────────────────────────────
· 2. agreed version + server capabilities, serverInfo, and the
│ instructions the model should always see │
notifications/initialized
─────────────────────────────────────────────────────────────────▶
· 3. the session is now open
│ │
tools/list · resources/list · prompts/list
─────────────────────────────────────────────────────────────────▶
│ │
the catalogs (JSON Schemas + descriptions)
◀─────────────────────────────────────────────────────────────────
· 4. the client caches these — they become the model's menu
The catalogs are more than lists: each tool comes with a JSON Schema of its arguments and a description. That metadata is injected into the model’s context — it is quite literally the menu the model chooses from.
Flow 2 — the tool-call loop (the core event)
This is the flow everything else exists for. The model never talks to the server directly: it decides, the client relays, the server executes, and the loop feeds the result back into the model:
MCP host + LLM MCP client MCP server
│ │ │
· The client holds the tool catalog from startup and injects
· the schemas into the model prompt alongside the question.
model requests one tool
───────────────────────────────────────────▶
│ │ │
· LLM emits: { "name": "get_forecast",
· "arguments": { "city": "Miami" } }
tools/call
───────────────────────────────────────────────────▶
│ │ │
· server runs the real work —
· HTTP API, database, filesystem…
CallToolResult
◀───────────────────────────────────────────────────
│ │ │
· content: [text blocks], isError: false
tool result
◀───────────────────────────────────────────
│ │ │
· the LLM reads the data and writes the answer in natural
· language. The loop repeats while more calls would help.
Design notes that matter in practice:
- Errors are data, not exceptions. A tool that can’t complete returns
isError: truewith a readable message so the model can correct course. Protocol errors (-32602invalid params and friends) are for malformed JSON-RPC — use them for malformed messages, not unhappy tool runs. - Validation errors should surface as tool errors too — the model reads the message and retries with corrected arguments.
- Long operations stream back
notifications/progressand log messages on the same response stream; the result can arrive much later (or as a durable task handle — see the evolution table). - The same loop covers resources (
resources/readreturns contents for URIs, with URI templates likenotes://{name}for dynamic data) and prompts (prompts/getreturns a ready-to-send message list the user picked).
Flow 3 — reverse flows: the server reaches into the host
The flow direction flips when the server needs host resources: the client’s model to draft text (sampling), the user for missing input (elicitation), and the workspace for filesystem boundaries (roots):
MCP client (host) MCP server
│ │
│ · During one tool call the server can reach back into │
│ · the host (sampling for its model, the user, its workspace)│
sampling/createMessage
◀────────────────────────────────────────────────────────────────
│ │
│ · the host's own LLM drafts │
│ · a completion for the server's │
│ · prompt — no API key needed │
result
────────────────────────────────────────────────────────────────▶
│ │
elicitation/create
◀────────────────────────────────────────────────────────────────
│ │
│ · the user is asked: confirm │
│ · an action, pick a value, or │
│ · enter a URL — ElicitResult goes back │
ElicitResult
────────────────────────────────────────────────────────────────▶
│ │
Use sampling to delegate small generation steps without the server owning an API key; use elicitation when a tool needs human confirmation or a choice the model shouldn’t invent. Both ride the same wire in the opposite direction as ordinary requests — which is what makes MCP feel like a symmetric protocol rather than a plain function-calling API.
Transport flows
Transports are how the JSON-RPC bytes move. Two standard ones:
stdio — local servers
┌───────────────────────┐ ┌───────────────────────┐
│ MCP host + client │ │ MCP server process │
│ │───────────────────────▶│ (your code) │
│ │ spawn + pipes │ │
│ │◀───────────────────────│ (logs go to stderr) │
└───────────────────────┘ └───────────────────────┘
JSON-RPC messages travel on stdin (→) and stdout (←);
keep stdout clean — your own logs belong on stderr.
The host launches your program as a child process. There’s no network layer to secure — the trust boundary is “the user chose to install this”. Constraint: stdout is the wire, so your code must keep it clean and log to stderr.
Streamable HTTP — remote servers
┌───────────────────────┐ ┌──────────────────────┐
│ MCP host + client │ HTTPS POST /mcp │ MCP endpoint │
│ │──────────────────────▶│ │
│ │ │ auth: OAuth 2.1 │
│ │◀──────────────────────│ your code behind it │
└───────────────────────┘ └──────────────────────┘
response: one JSON body, or an SSE stream carrying the
result plus progress, logs, and other server→client traffic
for the call in flight
| stdio | Streamable HTTP | |
|---|---|---|
| Deployment | Local machine | Local, cloud, anywhere |
| Lifecycle | Host spawns the process | Long-running server on a port |
| Security | User trust | OAuth 2.1, bearer tokens |
| Streaming | stdin/stdout pipes | SSE on the response stream |
| When | Personal tooling, dev | Shared, hosted, multi-user |
Both transports send identical JSON-RPC messages — swapping transport never changes what a server does.
The flows as of 2026-07-28 — stateless core
Protocol revisions keep arriving. The current one (2026-07-28) reworks the flow model: no handshake, no sessions. Every request is self-describing, so servers can be stateless like any other web API:
MCP client MCP server
│ │
server/discover (optional)
────────────────────────────────────────────────────────────────▶
│ │
· versions + capabilities + serverInfo — one shot
tools/list
────────────────────────────────────────────────────────────────▶
│ │
· _meta carries protocolVersion + clientCapabilities
tools (cacheable)
◀────────────────────────────────────────────────────────────────
│ │
tools/call
────────────────────────────────────────────────────────────────▶
│ │
result
◀────────────────────────────────────────────────────────────────
│ │
· sampling, elicitation, and roots travel as Multi-Round-
· Trip Requests: a result can return an InputRequiredResult
· that keeps the call alive for the next round
What changed and why it matters:
- No
initializehandshake, noMcp-Session-Id. Each request carries its protocol version and client capabilities in_meta; servers identify themselves in each result.server/discoveris an optional up-front probe. tools/listetc. are cacheable — catalogs can’t vary per connection anymore, and clients may cache them.- Multi-Round-Trip Requests (MRTR) replace server-initiated requests: sampling, elicitation, and roots travel as
InputRequiredResult— a tool result that keeps the call alive until the client supplies the next round. subscriptions/listenreplaces the GET stream and resource subscribe/unsubscribe with one opted-in notification stream.- Tasks for long-running operations became an official extension (
io.modelcontextprotocol/tasks), with polling instead of blocking result calls.
Protocol evolution
| Revision | What changed |
|---|---|
| 2024-11-05 | Initial: stdio + HTTP/SSE, tools/resources/prompts, sampling |
| 2025-03-26 | Streamable HTTP replaces the HTTP+SSE transport |
| 2025-06-18 | OAuth 2.1 authorization, elicitation, structured tool output |
| 2025-11-25 | Tasks for durable requests, richer elicitation + tool calling in sampling, icons |
| 2026-07-28 | Stateless core, MRTR, cacheable lists, subscriptions/listen, extensions framework |
SDKs keep serving older revisions on the same connection, so a server written yesterday still works with hosts from both eras — that’s what the version negotiation is for.
Design rules for MCP flows
- Prefer stateless tools. With the stateless core, cross-call state belongs in explicit handles the server mints and passes back as ordinary arguments.
- Make errors readable. The model is your error handler — text it can act on beats stack traces.
- Keep catalogs small and descriptions sharp. Every tool schema lands in the model’s context; overlapping tools are a mis-selection risk.
- Human approval for risky tools. Sampling and elicitation exist precisely so a server can ask before acting.
- Secure remote servers like any web API — OAuth 2.1, TLS at the proxy, and scope tokens as narrowly as the tools require.
Related
- How to build an MCP server — implement these flows behind the official Python or TypeScript SDKs.
- Connect MCP servers to your AI tools — register local and remote servers with Claude Desktop, Claude Code, Cursor, and VS Code.