Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Model Context ProtocolThe USB-C for AI tools.
After this you can
About this handbook
Every agent needs to reach the outside world — files, APIs, databases, other apps. MCP is the open standard that lets any model talk to any tool through one common port, instead of a snarl of one-off integrations. Here's what it is, how it works, and when to reach for it.
The M×N integration problem
Give a model tools and it becomes an agent — it can search, read a file, query a database, send a message. But every one of those connections used to be bespoke glue: this model's tool-calling format, that API's auth, a custom adapter in between. With M AI apps and N tools, you're on the hook for M × N integrations, each maintained by hand.
MCP turns M × N into M + N. Each app learns to speak MCP once; each tool exposes an MCP server once; everything interoperates. It's the same move USB made for peripherals — a common port, so the laptop doesn't need a driver for every device.
Announced by Anthropic in late 2024 and adopted broadly since, MCP is an open protocol: not tied to one model vendor, one language, or one product. That neutrality is the whole point — an ecosystem only forms if the standard belongs to everyone.
Host, client, and server
MCP has three roles. The host is the AI application the user interacts with (a chat app, an IDE agent, a desktop assistant). Inside it, an MCP client manages a connection to each MCP server — a separate process or service that exposes some capability. One host can hold many clients, each wired to a different server.
Under the hood it's JSON-RPC 2.0 messages over a transport — typically stdio for a local server the host launches, or Streamable HTTP for a remote one (it replaced the original HTTP + Server-Sent Events transport in the 2025-03-26 spec, and can still stream responses as SSE; since the 2026-07-28 revision it carries no session id at all). The wire format is deliberately boring; the value is in the shared vocabulary on top.
The three primitives
Every MCP server exposes some mix of three capability types — the nouns of the protocol.
Tools
- Functions the model can call
- Take actions with side effects
- e.g. create a file, send an email
- Model-controlled
Resources
- Read-only data the app can load
- Files, rows, API responses
- Addressed by URI
- App-controlled
Prompts are the third: reusable, parameterized prompt templates a server publishes and the user can invoke (a "/summarize" command, a code-review template). The split matters — tools are chosen by the model, resources are supplied by the app, and prompts are triggered by the user. Keeping those lines clear is also a security boundary.
A tool is a verb the model may use; a resource is a noun the app may read; a prompt is a shortcut the user may run. Same server, three different kinds of capability, three different controllers.
How a session works
The lifecycle is short and predictable. First the two sides agree on a protocol version and capabilities, so each knows what the other supports. Up to the 2025-11-25 spec that was an initialize handshake at the start of a connection. Since 2026-07-28 MCP is stateless: there is no handshake, every request carries its protocol version and client capabilities in _meta, and a client that wants to check first calls server/discover (see What changed in the spec). Then the client discovers what's on offer (tools/list, resources/list, prompts/list) and presents the tools to the model.
Because discovery happens at runtime, tools can appear and disappear without redeploying the host — plug in a new server and its capabilities show up. That dynamic quality is what makes MCP feel less like an API client and more like plugging in a device.
The wire format is just JSON-RPC 2.0
There is no mystery under the hood. Every MCP message is a JSON-RPC 2.0 envelope: a request carries an id and a method (plus optional params); the response echoes the same id and returns either a result or an error. The whole protocol is a handful of method names over that envelope:
| Method | Sent by | Does | Returns |
|---|---|---|---|
| server/discover | Client | Optional up-front check of supported versions and capabilities (2026-07-28) | versions, capabilities, server identity |
| initialize | Client | The handshake in revisions up to 2025-11-25: agree protocol version, exchange capabilities | serverInfo, capabilities |
| notifications/initialized | Client | Up to 2025-11-25: signal the handshake is done (a notification — no id, no reply) | — |
| tools/list | Client | Discover tools and their JSON schemas | array of tool defs |
| tools/call | Client | Invoke one tool with arguments | content blocks |
| resources/list, prompts/list | Client | Same discovery pattern for the other two primitives | arrays |
A notification (like notifications/initialized) is a request with no id — the server must not reply to it. That's the one wrinkle in an otherwise request/response protocol. Here is a real tools/call round-trip, byte for byte:
The result is a list of typed content blocks, not a bare value — so a tool can return text, images, or embedded resources through the same shape.
Call a method the server doesn't implement and you get the standard JSON-RPC error, code -32601 ("Method not found") — same code you'd see from any JSON-RPC service, because MCP is one. That's the whole point: MCP didn't invent a transport, it standardized a small vocabulary on top of a boring, proven one.
When to use it — and the sharp edges
Reach for MCP when you want your agent to use tools that others can build and share, or to reuse a growing ecosystem of servers instead of writing every integration yourself. For a single hard-coded tool in one app, a direct function-calling schema is simpler; MCP earns its keep once integrations multiply or need to be swapped without a redeploy.
MCP is a transport, not a safety layer. A server can expose dangerous tools, and any content it returns is untrusted input that can carry a prompt injection. The usual defenses still apply: least-privilege tools, human approval for risky actions, sandboxed execution, and treating a third-party server as you would any external dependency you didn't write.
MCP is one station in building a real agent runtime — the connective tissue between the model and the world. The rest of that runtime (the loop, context, memory, evals, cost) is the AI Harness roadmap.
What changed in the spec (updated 2026-11-28)
MCP is versioned by date, and a revision is a contract: client and server agree on one, and both are held to that revision's rules. As of November 2026 the current revision is 2026-07-28. It is the biggest change since launch, because it removes the connection-level state the earlier revisions relied on. The project itself moved too. Anthropic donated MCP to the Agentic AI Foundation, a Linux Foundation directed fund, in December 2025. Here is what each recent revision changed, taken from the spec's own changelogs.
| Revision | What it changed |
|---|---|
| 2025-03-26 | Streamable HTTP replaced the original HTTP + SSE transport, and the first authorization framework, based on OAuth 2.1, was added. |
| 2025-06-18 | Structured tool output (a tool can return typed JSON alongside its content blocks). MCP servers became OAuth resource servers that publish protected-resource metadata pointing at their authorization server, and clients must send RFC 8707 resource indicators so a token minted for one server can't be replayed at another. Also added: elicitation (a server can ask the user for missing input mid-call), resource links in tool results, and a required MCP-Protocol-Version header on HTTP. JSON-RPC batching was removed. |
| 2025-11-25 | Client ID Metadata Documents became the recommended way for a client to register with an authorization server. Also added: OpenID Connect discovery, incremental scope consent through WWW-Authenticate, URL-mode elicitation (send the user to a web page, for example to sign in), tool calling inside sampling, icons, and experimental tasks for durable, pollable requests. JSON Schema 2020-12 became the default dialect, and input-validation failures are now returned as tool execution errors so the model can correct itself. |
| 2026-07-28 (current) | Stateless. The initialize handshake and the Mcp-Session-Id header are gone. Every request carries its protocol version and client capabilities in _meta. A new server/discover call, which every server must implement, advertises supported versions, capabilities and identity. Server-initiated requests (elicitation, sampling, roots) are replaced by multi round-trip requests: the server returns an input_required result and the client retries with the answers. Also: one subscriptions/listen stream replaces the GET endpoint and resource subscriptions, ping is removed, tasks move into an official extension, cacheable list results carry ttlMs, and OpenTelemetry trace-context keys are documented. Roots, Sampling and Logging are deprecated, and so is Dynamic Client Registration (in favour of Client ID Metadata Documents). |
What it means for a server you run
The stateless change is the one that reaches production. Before it, a remote server that issued a session id had to route each client back to state created at its initialize, which made load balancing a sticky-session or shared-session-store problem. Now any replica can answer any request, and a server that really does need state across calls mints an explicit handle and has the client pass it back as an ordinary tool argument. The second change is that the server can no longer interrupt to ask the client something; it has to return "input required" and wait for a retry, which is simpler to reason about and survives a dropped connection. The deprecations follow a new feature-lifecycle policy with a minimum twelve-month window, so a server using Sampling keeps working for now, but new code shouldn't adopt it. The changelog's suggested migrations: call the model provider's API directly instead of Sampling, and log to stderr or OpenTelemetry instead of Logging.
Most MCP tutorials, including this page's runnable, show the initialize handshake, because that's how every revision up to 2025-11-25 worked. When you build against MCP, read the revision your client and server actually negotiate. Each one has its own changelog, linked above, and the differences decide whether a server can sit behind a plain load balancer.
An MCP server in 50 lines
The protocol is small enough to hold in your head — so build the whole thing. This is a real MCP-style server: a single handle(request) function that speaks JSON-RPC 2.0. Run it and watch a full session on the wire — initialize, tools/list, tools/call, and an unknown method returning the standard -32601 error. There is no framework here and none is hiding: this is the protocol. Add a tool to TOOLS and it shows up in discovery on the next run. It speaks the 2025-06-18 revision, handshake included, because that lifecycle is the easiest to watch; what the 2026-07-28 revision changes is in the section above.
Worked example: a host wiring up three servers
A coding assistant (the host) connects to three MCP servers: GitHub, the local filesystem and a Postgres database. Count the messages and the context the connection costs before the user has typed a word. The tool counts and the size of a tool definition are illustrative.
| Step | What happens | Arithmetic | Running total |
|---|---|---|---|
| 1 | One client per server | 3 servers | 3 connections |
| 2 | Version check: one server/discover request and response per server (2026-07-28 spec). Older revisions sent initialize, its response and notifications/initialized: 3 messages, not 2 | 2 messages × 3 servers | 6 messages |
| 3 | Discovery: tools/list request and response | 2 × 3 | 12 messages, no tool called yet |
| 4 | Tools found: 20 from GitHub, 10 from the filesystem, 8 from Postgres | 20 + 10 + 8 | 38 tool definitions |
| 5 | Definitions sent to the model, at about 150 tokens each (name, description, JSON schema) | 38 × 150 | 5,700 tokens on every model request |
| 6 | The user asks for open bugs; the model picks one tool; the client sends tools/call to the server that owns it | 1 request + 1 response | 14 messages |
| 7 | The same three servers, reused by four different hosts | 4 + 3 implementations instead of 4 × 3 | 7 instead of 12 |
Steps 2 and 3 are cheap and happen once per server (under the older handshake the totals were 9, 15 and 17). Since 2026-07-28 even step 2 is optional, because every request carries its protocol version in _meta. Step 5 is the cost that keeps coming back. Every connected tool’s definition rides along with every model request, whether or not it is used, so the context cost grows with the number of tools, not the number of calls. That is why hosts let users switch servers or single tools off, and why a server with 20 narrow tools is often worse than one with 5 well-named ones. Step 6 needs routing: the client has to know which server owns a tool name, which gets awkward when two servers both export search. Step 7 is the page’s M + N argument at a small scale. It grows fast: 10 hosts and 30 servers would be 40 implementations instead of 300.
Cost and trade-offs: transports and integration choices
Here Time is latency or setup effort, and Space is what the choice occupies: processes, context or operational surface.
| Case | Time | Space | Why |
|---|---|---|---|
| Plain function calling, no MCP | No extra hop: the tool runs in your process | Schemas in context, the same as MCP | Simplest for one app with a few fixed tools. Every other app has to re-implement them. |
| MCP over stdio (local) | One process spawn at start-up, then a local pipe | One server process per server per host | The server runs with the user’s own permissions. Whatever the user can do, a tool can do. |
| MCP over Streamable HTTP (remote) | A network round trip per call | One deployment serves many clients | Needs real auth; the spec’s HTTP authorization is based on OAuth 2.1, with the server acting as an OAuth resource server. Streamable HTTP replaced the older HTTP + SSE transport in the 2025-03-26 spec revision, and can still stream responses as SSE. Since 2026-07-28 it carries no session id, so any replica can answer any request. |
| Expose every tool from every server | Discovery once per connection | Every definition on every request (5,700 tokens above) | More near-duplicate tools for the model to choose between, and a larger attack surface. |
| Serve read-only data as resources, not tools | The app decides when to load it | Only what the app attaches | Keeps reads out of the model’s tool loop and gives the app control over what enters context. |
| Return big results unfiltered | One call | The whole payload lands in context | Paginate or filter on the server. A 5,000-row query result can crowd out the conversation it was meant to help. |
MCP adds very little at runtime; the JSON-RPC envelope costs next to nothing. The real costs are the ones a common port makes easy to ignore: definitions that ride along on every request, and the permissions of every server you plug in.
Common mistakes
- Logging to stdout on a stdio server
Over stdio, stdout is the protocol: the spec says a server must not write anything there that is not a valid MCP message. A stray
print("starting...")corrupts the stream and the host reports a parse error. Log to stderr. - Reporting tool failures as protocol errors
An unknown method or invalid arguments is a JSON-RPC error. But when the tool runs and the API it calls fails (a 404, a rate limit, a bad query), return a normal result with
"isError": trueand a readable message. That way the model sees what went wrong and can try again. A protocol error is handled by the client, and the model may never see it. - Vague or colliding tool names
The model chooses tools from their names and descriptions alone.
run,queryandsearchon three servers leave it guessing, and the host has to disambiguate names that collide. Use specific names (github_search_issues), say in the description when to use the tool and when not to, and keep the argument schema tight. - Trusting a server’s tool descriptions
Descriptions go into the model’s context just as tool results do, so a malicious or compromised server can put instructions there. A server can also change its tool list after you approved it. Pin the servers you use, review what they expose, and treat a changed tool list as a new approval.
- Forwarding the client’s token downstream
A remote server that receives a user’s access token and passes it straight on to another API breaks the audience boundary. The spec forbids this token passthrough. The server should accept only tokens issued for itself, and get its own credentials for anything it calls downstream.
Check yourself
Five AI apps each need eight tools. How many integrations without MCP, and how many with it?
Without MCP, every app wires up every tool: 5 × 8 = 40. With MCP, each app implements a client once and each tool ships a server once: 5 + 8 = 13. The gap widens as either number grows.
Your new stdio server works in a test script, but the host shows a JSON parse error as soon as it launches. What is the likeliest cause?
Something besides MCP messages is going to stdout: a start-up banner, a debug print, or a library’s warning. On stdio, stdout is the message channel, so the host tries to parse your log line as JSON-RPC. Send logs to stderr.
A get_repo tool calls an API that returns 404 for a misspelled repo name. JSON-RPC error or isError result?
An isError result. The protocol worked and the tool ran; the failure is in the tool’s domain. Returned as content, “repo not found: vibe-engins” lets the model notice the typo and call again. A JSON-RPC error is for protocol problems, like the page’s -32601 for an unknown method.
Which primitive fits each: a /release-notes command, creating a GitHub issue, attaching a schema file to the conversation?
Prompt, tool, resource. The user triggers the command, so it is a prompt. Creating an issue is an action with a side effect that the model chooses, so it is a tool. The schema file is read-only data the app attaches, so it is a resource. The split is also who is in control, which is the security boundary the page describes.
Quick answers
What is the Model Context Protocol?
An open standard for how an AI app connects to external tools, data, and prompts. A host connects to MCP servers that expose capabilities through one uniform interface, so any MCP-compatible model can use any MCP server.
What problem does MCP solve?
It turns M×N bespoke integrations into M+N: each app speaks MCP once, each tool exposes a server once, and they interoperate — decoupling the model from the integrations like a common port decouples a laptop from its peripherals.
What are the primitives?
Tools (functions the model can call), Resources (read-only data the app can load), and Prompts (reusable templates the user can invoke). The client discovers them at connection time and offers the tools to the model.
Is MCP a security risk?
MCP is transport, not a safety guarantee. Servers can expose powerful tools and return content that carries a prompt injection, so least-privilege tools, human approval, sandboxing, and treating server output as untrusted all still apply.
This idea in other formats
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Agentic AI Interview HandbookTwenty topics every senior AI engineer should be able to reason about live — from eval pipelines to reliability patterns for generative systems.Read →
- The Agent Evaluations HandbookA self-contained handbook on evaluating AI agents — theory, interactive widgets, and practical guidance. Trajectory evals, tool-use scoring, LLM-as-judge, observability, and reliability for PMs, engineers, and founders.Read →
- The Agent Patterns HandbookThe design patterns behind every LLM agent — the ReAct Thought–Action–Observation loop, tool/function calling, plan-and-execute, reflection, memory, multi-agent orchestration, and the failure modes (loops, hallucinated tools, recovery, human-in-the-loop) that break agents in production.Read →
- The Loop Engineering HandbookStop prompting your agents — design the system that prompts them for you. The inner vs outer loop, the four loop types (heartbeat, cron, hook, goal), the six building blocks (automations, worktrees, skills, MCP connectors, subagents, external memory), stopping conditions and the verification split, state across runs, cost engineering, and the six failure modes that burn tokens at 3am.Read →
- The Context Engineering HandbookThe discipline that replaced prompt-tweaking: curating everything the model sees under a finite attention budget. The anatomy of a production context window, the three taxes on an overstuffed one (context rot, cost, behavioral drift), the four operations (write, select, compress, isolate), agent-specific patterns like compaction and just-in-time retrieval, six production habits, and where it sits in the prompt → context → loop → harness stack.Read →
- The Agent Skills HandbookPackaged, on-demand expertise for AI agents: what a skill folder actually is (SKILL.md + scripts + resources), progressive disclosure and why the system prompt couldn't do it, the skills vs tools vs MCP vs fine-tuning decision table, six habits of skills that actually trigger, and why third-party skills are supply-chain dependencies to review like code.Read →