AI engineering / Beginner / 01.35
MCP
A standard plug for connecting AI apps to tools and data: who does what, what a server offers, and what the messages look like.
13 min readFree
One plug for many tools
The last lesson, AI Agents, ended with a promise: next, MCP, a standard plug for connecting models to tools and data. Here it is.
An agent is only as useful as the things it can reach: your files, your calendar, a search engine, a database. Each of those needs a connection. If every AI app builds its own connection to every tool, that is a lot of repeated work. MCP is the agreement that removes it.
By the end you will know what MCP is, the three roles in it, what a server can offer, and what the messages look like. You will run a small program that makes those messages with your own hands.
Key words
- Protocol
- A set of rules two programs follow so they understand each other, like the rules of a phone call: who speaks first, what a greeting looks like.
- MCP
- Short for Model Context Protocol. A shared set of rules for connecting AI apps to tools and data.
- Host
- The AI app the person uses, such as a chat app or a code editor. It starts the connections.
- Client
- A small connector inside the host. Each client talks to exactly one server.
- Server
- A program that offers tools, data or ready-made prompts to the AI app. It can run on your computer or elsewhere.
- Tool
- An action a server offers, like "search the web" or "add up these numbers". The model decides when to use it.
- JSON-RPC
- A simple format for asking another program to run something and getting its answer back, written as JSON, a plain-text way of writing lists and labelled values.
What MCP is
The official introduction opens with one sentence. It says MCP is "an open-source standard for connecting AI applications to external systems".
Open-source means anyone can read it and use it. A standard means many people agree to do it the same way. And "external systems" means anything outside the AI app itself.
The page lists three kinds of thing an AI app can connect to: data sources, such as local files and databases; tools, such as search engines and calculators; and workflows, such as specialized prompts. The point is that the app can then reach key information and perform tasks.
The Wikipedia page adds some history. It says MCP was introduced by Anthropic in November 2024, and that the protocol was later adopted by other major AI providers.
The USB-C picture
The official site uses an everyday picture. It says to "Think of MCP like a USB-C port for AI applications." Just as USB-C gives one standard way to connect electronic devices, MCP gives one standard way to connect AI applications to external systems.
Think of the drawer of old chargers at home, one shape for each gadget. A standard port ends that. Any cable fits any device that has the port.
MCP is the same idea for software. A tool that speaks MCP can plug into any AI app that speaks MCP.
Why a standard helps
Without a standard, three AI apps and four tools mean twelve separate connections to build and keep working. With one, each app learns the standard once and each tool learns it once. That is three plus four, seven pieces of work instead of twelve. (These numbers are made up to show the idea.)
The official page says the same thing in its own words. It lists benefits by role: developers get reduced development time and complexity; AI applications get access to an ecosystem of data sources, tools and apps; end-users get more capable AI applications that can access user data and take actions on their behalf when necessary.
It also says MCP is supported across many clients and servers, which makes it "easy to build once and integrate everywhere".
For builders
Write one connector for your service and any app that speaks MCP can use it.
For AI apps
Add MCP once and a whole shelf of existing tools becomes available.
For people
Your assistant can reach your own files and tools, not only what it learned in training.
Host, client and server
The specification calls this a client-host-server architecture. There are three roles, and each has one clear job.
- 1
The host is the app
It is the program the person actually uses. The architecture page says the host creates and manages multiple client instances, controls their connection permissions, and handles user authorization decisions.
- 2
Clients are the connectors
The host creates a client for each server it wants to reach. Each client communicates with exactly one server, a one-to-one match.
- 3
Servers do the work
A server exposes resources, tools and prompts. The page says servers can be local processes or remote services.
Picture a restaurant. The host is the head waiter: he deals with you and decides what is allowed. Each client is a runner who goes to exactly one kitchen station. Each server is a station that makes one kind of thing, such as the grill or the dessert counter.
One of the design principles on that page matters for safety. Servers should not be able to read the whole conversation, nor "see into" other servers. The full conversation history stays with the host.
What a server can offer
The specification says servers offer any of three features to clients. Here they are with what the specification says about each.
Tools
Functions for the AI model to execute. Think "send this email" or "run this search".
Resources
Context and data, for the user or the AI model to use. Think a file or a database record.
Prompts
Templated messages and workflows for users. Think a ready-made "summarize this document" starter.
Notice who is in charge of each. The tools page says tools are designed to be model-controlled, meaning the language model can discover and invoke tools automatically based on its understanding of the conversation. It is the same pattern as function calling: the model asks for a tool, and the program around it runs the tool.
Tip
A server does not have to offer all three. Many servers offer only tools.
Quick check
Which MCP feature is a function the AI model can run?
The messages: JSON-RPC 2.0
Now the part that makes it concrete. The specification says MCP uses JSON-RPC 2.0 messages to establish communication between hosts, clients and servers.
JSON-RPC itself is small. Its specification calls it a stateless, light-weight remote procedure call protocol. A remote procedure call just means asking another program to run a named action and send back the answer. It is also transport agnostic: the same messages can travel within the same process, over sockets or over HTTP.
Three kinds of message
Only three shapes matter. The JSON-RPC specification defines each one.
Request
Has "jsonrpc" set to exactly "2.0", a "method" naming the action, optional "params", and an "id" the server must echo back.
Response
Has "jsonrpc", the same "id", and either a "result" on success or an "error" on failure, never both.
Notification
A request with no "id". The server must not reply to it.
The "id" is like a ticket number at a deli counter. You hand it over with your order, and your order comes back with the same number, so you know which answer belongs to which question.
A conversation, step by step
The 2025-11-25 version of the specification describes a connection in phases: initialization, operation, then shutdown. Here is the opening, using the exact method names from that specification.
- 1
initialize
The client sends an "initialize" request with the protocol version it supports, its capabilities (what it can do) and information about itself. The server answers with its own capabilities and information.
- 2
notifications/initialized
The client then sends this notification to say it is ready. The specification says the client should not send other requests, except pings, before the server has answered "initialize".
- 3
tools/list
The client asks what tools the server has. Each tool in the answer has a name, a description and an inputSchema, a description of the inputs it expects.
- 4
tools/call
The client asks the server to run one tool by name, with its arguments. The answer holds the tool's output in a "content" list, plus an "isError" flag.
A newer revision of the specification, dated 2026-07-28, is described on the official site as dropping the opening handshake: every request carries its own protocol version, and the page says there is no negotiation handshake. It calls the older versions, 2025-11-25 and earlier, legacy and says they open a session with an "initialize" handshake. This lesson shows the older shape because it makes the steps easy to see. Check the current specification before you build.
Make the messages yourself
Let's build those messages in plain Python, with only the json module. The function called server is a tiny stand-in written inside the same code block. It is not a real MCP server. It answers the messages for one tool, called echo, that sends your text back.
Be clear about what this is. It copies the shape of the messages from the specification. It is not a full MCP implementation: there is no network, no capability checking, and it skips most of the rules. The last request uses a method that does not exist, so you can see an error response.
import json
TOOLS = [{
"name": "echo",
"description": "Send back the text you give it",
"inputSchema": {
"type": "object",
"properties": {"text": {"type": "string"}},
"required": ["text"],
},
}]
def server(request):
"""A tiny in-process stand-in for an MCP server. It answers one request."""
if "id" not in request:
return None # a notification gets no reply
method = request["method"]
if method == "initialize":
result = {
"protocolVersion": "2025-11-25",
"capabilities": {"tools": {"listChanged": False}},
"serverInfo": {"name": "EchoServer", "version": "1.0.0"},
}
elif method == "tools/list":
result = {"tools": TOOLS}
elif method == "tools/call":
args = request["params"]["arguments"]
result = {"content": [{"type": "text", "text": args["text"]}], "isError": False}
else:
error = {"code": -32601, "message": "Method not found"}
return {"jsonrpc": "2.0", "id": request["id"], "error": error}
return {"jsonrpc": "2.0", "id": request["id"], "result": result}
requests = [
{"jsonrpc": "2.0", "id": 1, "method": "initialize",
"params": {"protocolVersion": "2025-11-25", "capabilities": {},
"clientInfo": {"name": "TinyClient", "version": "0.1"}}},
{"jsonrpc": "2.0", "method": "notifications/initialized"},
{"jsonrpc": "2.0", "id": 2, "method": "tools/list"},
{"jsonrpc": "2.0", "id": 3, "method": "tools/call",
"params": {"name": "echo", "arguments": {"text": "hello"}}},
{"jsonrpc": "2.0", "id": 4, "method": "tools/dance"},
]
for request in requests:
wire = json.dumps(request)
print("client ->", wire)
reply = server(json.loads(wire))
print("server ->", json.dumps(reply) if reply else "(no reply, it was a notification)")
print()Output
client -> {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-11-25", "capabilities": {}, "clientInfo": {"name": "TinyClient", "version": "0.1"}}}
server -> {"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2025-11-25", "capabilities": {"tools": {"listChanged": false}}, "serverInfo": {"name": "EchoServer", "version": "1.0.0"}}}
client -> {"jsonrpc": "2.0", "method": "notifications/initialized"}
server -> (no reply, it was a notification)
client -> {"jsonrpc": "2.0", "id": 2, "method": "tools/list"}
server -> {"jsonrpc": "2.0", "id": 2, "result": {"tools": [{"name": "echo", "description": "Send back the text you give it", "inputSchema": {"type": "object", "properties": {"text": {"type": "string"}}, "required": ["text"]}}]}}
client -> {"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "echo", "arguments": {"text": "hello"}}}
server -> {"jsonrpc": "2.0", "id": 3, "result": {"content": [{"type": "text", "text": "hello"}], "isError": false}}
client -> {"jsonrpc": "2.0", "id": 4, "method": "tools/dance"}
server -> {"jsonrpc": "2.0", "id": 4, "error": {"code": -32601, "message": "Method not found"}}Read it from the top. The first request, "initialize", got a reply with the server's name and a "tools" capability, which is how a server says it has tools.
The second line is a notification. It has no "id", so the stand-in sends nothing back, just as JSON-RPC says.
Request 2 asked "tools/list" and got one tool, echo, with its inputSchema. Request 3 called it with the text "hello" and got the same word back inside a "content" list, with isError set to false. Each reply carries the same "id" as the request it answers.
Request 4 used a method the server does not know. Its reply has an "error" in place of a "result". The JSON-RPC specification lists code -32601 as "Method not found", which is what the stand-in sent.
Tip
Real MCP libraries build and read these messages for you. Seeing the raw JSON once makes their error messages much easier to read.
Safety: trust what you plug in
A plug can carry power, and it can carry trouble. A server can do whatever its tools do. A tool that deletes files will delete files. A tool that sends email will send email. MCP does not make a tool safe. It only makes it easy to connect.
The specification is plain about this. The tools page says there should always be a human in the loop with the ability to deny tool invocations. It says apps should make clear which tools are exposed to the model, show clear signs when tools are used, and ask the user to confirm operations.
It also lists duties for servers, such as validating all tool inputs and rate limiting tool invocations, and for clients, such as showing tool inputs to the user before calling the server to avoid malicious or accidental data exfiltration. Exfiltration means data being quietly sent out.
Install only servers you trust
Treat a server like any program you install. Know who made it, and prefer ones you can read or that people you trust use.
Read the permissions
Check what each tool can reach and change before you switch it on. Say no to access it does not need.
Keep a person in the loop
For actions that spend money, send messages or delete things, make the app ask first.
The Context Security lesson in this course covers the wider risks, such as hidden instructions in text. Text that comes back from a tool is text the model reads, so treat it with the same care.
Quick check
You find a new MCP server on the internet. What should you do first?
Where this goes next
Here you met the idea and the messages. The Advanced lessons go further. They build an MCP server and an MCP client, and cover the host, local and remote connections, and security in depth. This lesson also stands in for the plan's Advanced topic called Model Context Protocol (MCP).
The official introduction points to the same next steps: build servers to expose your data and tools, and build clients that connect to servers.
What to remember
The idea
MCP is an open standard for connecting AI apps to tools and data. Build a connector once, use it in many apps.
The roles
A host app makes clients. Each client talks to one server. A server offers tools, resources and prompts.
The care
A server can do whatever its tools do. Trust the source, read the permissions, keep a person in the loop.
Quick check
In JSON-RPC, what makes a message a notification?
Next: types of models, from text-only to models that see and hear.
Sources
- Model Context Protocol: What is MCP? (introduction)
- Model Context Protocol: Architecture (specification 2025-11-25)
- Model Context Protocol: Architecture (latest)
- Model Context Protocol: Lifecycle (specification 2025-11-25)
- Model Context Protocol: Tools (specification 2025-11-25)
- Model Context Protocol: Specification overview (latest)
- Model Context Protocol: Versioning and compatibility (latest)
- JSON-RPC 2.0 Specification
- Wikipedia: Model Context Protocol
Last updated on 16 November 2026
Learn with me
Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.