Model Context Protocol
MCP is the shared plug between an agent and its tools. One client talks to any server that speaks the standard, so tools, files and data arrive in the same typed shape instead of one custom wrapper each.
Why Does This Exist?
Say you want your agent to search issues on GitHub, run read-only queries on Postgres, and read files from disk. The obvious route is custom work per tool: read the API docs, write a function, write the JSON Schema the model must follow, wire up execution, and format the result back into the chat. Done once, it feels fine. Done for every tool times every app, it stops being fine.
Write for the number of tools and for the number of agent apps. Bespoke wiring costs about integrations, because each app repeats each tool. Say and : that is wrappers to write, test, and keep working every time any API changes. The failure is not one bug. It is the multiplication.
Model Context Protocol (MCP) is an open standard that turns the multiplication into an addition. Each tool ships one server that describes itself in a fixed typed shape, each app ships one client that speaks that shape, and the two meet over JSON-RPC. The same tools and apps then need pieces, and adding a sixth tool costs one server instead of four new wrappers.
This page covers that wire: the roles, the three things a server can offer, and the message flow from handshake to tool call. The raw mechanism of a single call, where the model writes structured arguments and outside code runs them, lives in tool use and function calling. The loop the client plugs into, model plus tools plus memory retrying until the job lands, is AI agent architecture.
Think of It Like This
The hotel bedside port
You have landed late with a dying phone and three gadgets to charge. In a bad hotel, the nightstand holds a tangle of country-specific adapters and each gadget needs its own brick, so you spend the evening matching plugs to sockets. In a good hotel, the nightstand has one row of USB-C ports. You carry one cable, every gadget charges, and nobody asks which country wired the building.
The mapping is direct. Your cable is the MCP client: one shape on your side. Each wall port is an MCP server: one fixed shape on the tool side. The USB-C spec itself is the protocol: voltages, handshakes, and pin layouts agreed up front, like JSON-RPC plus the tool schemas. The hotel wiring and breakers are the host app: it decides which ports are live and how much current each may draw, the way the host sets permissions and scopes.
Where it stops: a wall port never lies about what it is, and it cannot rewire the room while you sleep. A server is software written by strangers. It can misdescribe a tool, rename an argument, or hide a side effect the schema never mentions. The plug shape guarantees delivery, not honesty. Permissions and schema checks still belong to you.
How It Actually Works
The three roles
A host is the app you run, such as a desktop assistant or an editor agent. It owns the model, the interface, and the safety policy. Inside the host, one client holds one conversation with one server and keeps it alive: sending requests, matching replies, handling cancellations and progress notes. A server is a small program fronting real stuff: a database, a file tree, an issue tracker. One host can hold many clients, one per server it uses, and one server can serve many clients at once.
Transport is deliberately boring. Local servers usually talk over standard input and output, the same pipes shell tools have used for decades. Remote servers use HTTP with a streaming reply. Either way the bytes carry JSON-RPC: small envelopes with a method name, parameters, and an id so each reply finds its request. You never hand-roll this framing. The client and server libraries do it, which is the point.
The three primitives
Every server describes itself with up to three kinds of entries, all carrying JSON Schema wherever arguments appear:
- Tools are things the model can call:
query_databasetaking asqlstring,read_filetaking apath. Each tool lists its name, its arguments, and what it returns. Tools are the only primitive that acts on the world. - Resources are things the model can read: files, rows, or documents addressed by URI, such as
db://orders/2026-10. The model asks and the server answers. This primitive never rewrites anything. - Prompts are reusable instruction templates the server offers, like a code-review checklist with a slot for the file under review. They keep wording steady across apps without pasting text around.
Discovery is the whole trick. The client asks one question, tools/list (and likewise for resources and prompts), and gets back the full typed menu. Those schemas enter the model's context on the next turn, so the model picks from what exists instead of guessing names. If you have read tool use and function calling, this is the same call shape, except the menu arrives over the wire instead of living in your codebase.
The conversation, step by step
- Handshake. Client and server swap versions and capability flags: which primitives each side supports, nothing more. If they cannot agree, they stop here instead of failing mid-task.
- Discovery. The client lists tools, resources, and prompts. The host decides which entries the model may see. A read-only demo might show
query_databaseand hidedrop_tableentirely. - Selection. The model reads the user request plus the visible schemas and emits one structured call: a name plus arguments, nothing else. It does not touch the database. It writes the order slip.
- Execution. The client checks the call against the schema, checks it against policy, forwards it to the server, and streams the result back into context. Then the model continues with fresh facts.
Servers can also tap the client on the shoulder: a notification says the menu changed, and the client re-lists instead of calling a tool that no longer exists.
Worked example: counting the saving
Take the picture's setup first. One host with one client faces three servers: GitHub, Postgres, and files. Bespoke wiring there is wrappers, one per tool, each useful to exactly one app. The MCP version is pieces: three reusable servers plus one client. Same count today, but the next app reuses all three servers for free.
Now scale it. Your team has tools and apps: a desktop assistant, an editor agent, a test runner, and a support bot. Write for the bespoke count and for the standard count:
wrappers before, against
pieces after. The saving is integrations you never write, and tool number six costs one server instead of four wrappers. That is the number in the diagram caption, and the snippet below recomputes it.
One concrete call inside that setup keeps it honest. Discovery returns three tools. The model picks query_database with {"sql": "select status, count(*) from orders group by status"}. The server answers with two grouped rows plus their columns. Two rows in, one short summary out. Small, checkable, and the same shape on every server.
The price is real, so name it. You pay one more process or network hop per call, the tool schemas burn context on every turn until you prune them, and each new server deserves a trust review. That buys reuse plus typed discovery. Skip the standard when there is nothing to reuse: one script, one stable API, no second app in sight. Call it directly and pocket the simplicity.
The design assumes servers tell the truth about their menus: names steady, arguments accurate, side effects declared. When that breaks, the model obeys a stale schema with full confidence: right shape, wrong effect. Pin server versions, re-list on every reconnect, and log the raw request, so a bad call arrives as evidence instead of mystery. The sibling problem, agents talking to each other rather than to tools, gets its own envelope in agent-to-agent protocols.
Code
This snippet checks the two things the page claims: the discovery menu has no duplicate names for the model to trip over, and the setup really drops from to .
from typing import Any
def count_tools(reply: dict[str, Any]) -> int: tools: list[dict[str, Any]] = reply.get("tools", []) names: list[str] = [t["name"] for t in tools] assert len(names) == len(set(names)) # duplicate names would confuse the model return len(names)
def pieces_after(n_tools: int, n_apps: int) -> int: return n_tools + n_apps
reply: dict[str, Any] = { "tools": [{"name": "query_database"}, {"name": "read_file"}, {"name": "search_issues"}]}print(count_tools(reply)) # -> 3print(5 * 4, pieces_after(5, 4), 5 * 4 - pieces_after(5, 4)) # -> 20 9 11Three tools discovered, twenty wrappers down to nine pieces, eleven saved. Those are the worked example's numbers, recomputed instead of quoted.
Watch Out For
A write tool hiding in a read-only job
You connect a server so the model can look things up, and the menu quietly includes delete_table with a cheerful description. One vague instruction later, the model calls it with confident, valid arguments. Nothing crashes. The rows are just gone, and the transcript shows a perfectly well-formed call.
Scope the job before you connect it. Run the server on least-privilege credentials, mount paths read-only, hide mutating tools from the model for lookup work, and require a human tap before anything that writes. Never hand a lookup job a credential that can delete. The scoping rules live in tool permissions.
Believing the menu
A server ships an update: an argument is renamed, a default flips, a new side effect appears that the old description never mentioned. Your calls now fail with unknown-argument errors, or worse, succeed with a changed meaning, while the model keeps retrying the stale shape sitting in its context. The schema in context has become fiction.
Treat the menu as a versioned contract. Pin the server version, re-list on every reconnect, contract-test tools/list where you test the rest of the app, and log the raw JSON-RPC request. Then the first bad call names its cause instead of starting a ghost hunt.
The Quick Version
- MCP is one standard wire between agent apps and tools: hosts hold clients, servers front data and actions, JSON-RPC carries the messages.
- Servers describe themselves with typed tools, readable resources, and reusable prompts, so the model picks from a real menu instead of guessing names.
- Discovery replaces hand-written wrappers: 5 tools across 4 apps need 9 pieces instead of 20, and each new tool costs one server.
- The model never touches the world directly. It emits a named call with arguments, and outside code checks it, runs it, and returns the result.
- A standard shape is not standard honesty. Scope credentials, hide mutating tools from lookup jobs, and re-list the menu on every reconnect.