Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
The Model Context Protocol,
the USB-C for AI tools.
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). 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. The client and server first initialize, exchanging protocol versions and capabilities — a negotiation so each side knows what the other supports. 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 |
|---|---|---|---|
| initialize | Client | Agree protocol version, exchange capabilities | serverInfo, capabilities |
| notifications/initialized | Client | 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.
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.
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 | Handshake: initialize request and response, then notifications/initialized | 3 messages × 3 servers | 9 messages |
| 3 | Discovery: tools/list request and response | 2 × 3 | 15 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 | 17 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 connection. 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. Streamable HTTP replaced the older HTTP + SSE transport in the 2025-03-26 spec revision, and can still stream responses as SSE. |
| 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 →