Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

AI Engineering~11 min readIntermediate
Deep Dive

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.

01

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.

→ The core idea

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.

02

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.

One host, many servers
HostThe AI app the user sees — owns the model and the conversation.
ClientA connector inside the host, one per server, speaking MCP.
ServerAn external provider of tools / data / prompts — a filesystem, GitHub, a database, your own service.

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.

03

The three primitives

Every MCP server exposes some mix of three capability types — the nouns of the protocol.

What a server can offer

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.

→ Mental model

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.

04

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.

Connect → discover → call
1initialize — agree on version and capabilities.
2tools/list — the client learns the available tools and their JSON schemas.
3model decides — it emits a tool call in its own format; the client maps it to MCP.
4tools/call — the server runs it and returns a result.
5observe — the result goes back into the model's context, and the loop continues.

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:

MethodSent byDoesReturns
initializeClientAgree protocol version, exchange capabilitiesserverInfo, capabilities
notifications/initializedClientSignal the handshake is done (a notification — no id, no reply)—
tools/listClientDiscover tools and their JSON schemasarray of tool defs
tools/callClientInvoke one tool with argumentscontent blocks
resources/list, prompts/listClientSame discovery pattern for the other two primitivesarrays

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:

// client → server { "jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": { "name": "add", "arguments": { "a": 2, "b": 40 } } } // server → client (note: same id: 3) { "jsonrpc": "2.0", "id": 3, "result": { "content": [ { "type": "text", "text": "42" } ], "isError": false } }

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.

05

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.

→ Security is not free

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.

RUN IT YOURSELF

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.

CPython · WebAssembly
By the numbers

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.

StepWhat happensArithmeticRunning total
1One client per server3 servers3 connections
2Handshake: initialize request and response, then notifications/initialized3 messages × 3 servers9 messages
3Discovery: tools/list request and response2 × 315 messages, no tool called yet
4Tools found: 20 from GitHub, 10 from the filesystem, 8 from Postgres20 + 10 + 838 tool definitions
5Definitions sent to the model, at about 150 tokens each (name, description, JSON schema)38 × 1505,700 tokens on every model request
6The user asks for open bugs; the model picks one tool; the client sends tools/call to the server that owns it1 request + 1 response17 messages
7The same three servers, reused by four different hosts4 + 3 implementations instead of 4 × 37 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.

Trade-offs

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.

CaseTimeSpaceWhy
Plain function calling, no MCPNo extra hop: the tool runs in your processSchemas in context, the same as MCPSimplest 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 pipeOne server process per server per hostThe 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 callOne deployment serves many clientsNeeds 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 serverDiscovery once per connectionEvery 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 toolsThe app decides when to load itOnly what the app attachesKeeps reads out of the model’s tool loop and gives the app control over what enters context.
Return big results unfilteredOne callThe whole payload lands in contextPaginate 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.

Watch for

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": true and 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, query and search on 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.

Self-check

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.

Frequently asked

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.

Model Context Protocol (MCP) · AI Engineering · Vibe Engines · 2026
Finished this one? 0 / 209 Handbooks done
NextMCP vs Function Calling Next on the “Tools, protocols and interop” ladder · rung 2 of 7

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