What Is MCP? One Plug Between AI Apps and Tools: Host, Client, Server and the Three Messages
MCP is one standard plug between AI apps and tools: four apps and four tools need 8 connections instead of 16. A tiny Python server named github offers one tool, one resource and one prompt; a client starts it, lists what it offers and calls create_issue, and a raw wire script shows the same three steps as JSON lines.
What you will learn
- Explain why MCP turns N times M custom connectors into N plus M
- Name the three roles, host, client and server, and what a server offers: tools, resources and prompts
- Read the three steps of an MCP session: initialize, tools/list and tools/call
- Treat a server as a program that acts with your permissions: trust, scope, secrets and audit
Before you start
- Basic Python
- Claude Tool Use: How tool_use and tool_result Work
MCP, the Model Context Protocol, is one plug shape that lets any AI app use any tool. Think of USB-C: phones, laptops and monitors all share one port, so you stop buying a new cable for every pair. In this article we see why that matters, meet the three roles (host, client and server), and run a tiny server and client in Python so you can watch the actual messages go back and forth.
Everything here runs locally with the official mcp Python package (version 2.3.0 in the project). No API key and no model call are needed.
A drawer full of chargers
Say you use three AI apps: Claude Desktop (a chat app on your computer), an assistant inside your code editor, and a small agent you built yourself. All three need the same two things: GitHub, to look at issues and pull requests, and your database, to look up rows.
Without a standard, every app and tool pair needs its own custom connector. That's six already, each with a different plug. It's the drawer full of chargers, one for every device.
One plug, fewer wires
Now make it four apps and four tools. Wired by hand, every app needs a line to every tool: 4 × 4 = 16 custom connectors. Put one shared standard in the middle, and each app plugs into it once and each tool plugs into it once: 4 + 4 = 8 connections.
Each app learns MCP once, each tool learns it once, and they all fit together. With N apps and M tools, that's N + M instead of N × M.
Host, client, server
Picture a laptop with two USB-C ports and two devices plugged in.
- The laptop is the host. That's the app you actually use, like Claude Desktop or your editor.
- Each port is an MCP client. A client is the part inside the host that speaks MCP, and it talks to exactly one server.
- Each device is an MCP server: a small program that offers something, like a GitHub server or a database server.
So a host holds one client for each server it connects to. Two servers, two clients.
What a server offers
Here's a tiny server, server.py, named github. Think of it as a small shop with three shelves.
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("github")
ISSUES = ["Login button is slow"]
@mcp.tool()
def create_issue(title: str) -> str:
"""Open a new issue with the given title."""
ISSUES.append(title)
return f"Created issue #{len(ISSUES)}: {title}"
@mcp.resource("repo://readme")
def readme() -> str:
"""The README of the repository."""
return "Shop app. Run with: python app.py"
@mcp.prompt()
def review_pr(number: int) -> str:
"""A ready-made message for reviewing a pull request."""
return f"Review pull request #{number} for bugs and style."
if __name__ == "__main__":
mcp.run(transport="stdio")
- Tools are things you can do. A tool is an action the AI can ask for, like
create_issue, which takes a title. - Resources are things you can read: pieces of data the app can read, each at its own address, like
repo://readme. - Prompts are ready-made recipes: starting messages the user can pick, like
review_pr.
In practice most servers start with tools. Resources and prompts are extras that make a server nicer to use. In older versions of the SDK, MCPServer was called FastMCP, so you may still see that name.
The client side
Now the other side, client.py. This is the part a host runs. It says how to start the server (python server.py, on this computer), then asks questions in order.
import asyncio
import sys
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
server = StdioServerParameters(
command=sys.executable, args=["server.py"])
async with stdio_client(server) as (read, write):
async with ClientSession(read, write) as session:
hello = await session.initialize()
print("server:", hello.server_info.name)
tools = await session.list_tools()
print("tools:", [t.name for t in tools.tools])
res = await session.list_resources()
print("resources:", [str(r.uri) for r in res.resources])
prompts = await session.list_prompts()
print("prompts:", [p.name for p in prompts.prompts])
args = {"title": "Add dark mode"}
result = await session.call_tool("create_issue", args)
print("result:", result.content[0].text)
asyncio.run(main())
server: github
tools: ['create_issue']
resources: ['repo://readme']
prompts: ['review_pr']
result: Created issue #2: Add dark mode
The first call is initialize, and the server says hello with its name. Then the client asks what's on offer: one tool, one resource, one prompt. Then it calls create_issue with the title "Add dark mode", and the result says issue #2, because the server already had one issue. The host never needs to know how GitHub works inside. The client asks, and the server answers.
Two ways to connect
The messages are the same either way. Only the road is different.
| stdio | Streamable HTTP | |
|---|---|---|
| Where the server runs | On your machine; the host starts it | Somewhere else, at a web address |
| How messages travel | Standard input and output | HTTP requests |
| Where the secret goes | An environment variable, like an API key | An OAuth token the client carries |
| Feels like | A colleague at the next desk | A phone call to another office |
Pick stdio for tools on your own machine, and Streamable HTTP for a server that many people share. The transport choice has its own details, covered in MCP transports: stdio or Streamable HTTP.
Telling the host about servers
A host learns about its servers from a config file. This one is .vscode/mcp.json, the file the VS Code editor reads. Each entry under servers is one server.
{
"inputs": [
{"type": "promptString", "id": "github-token", "password": true}
],
"servers": {
"github": {
"type": "stdio",
"command": "python",
"args": ["server.py"],
"env": { "GITHUB_TOKEN": "${input:github-token}" }
},
"team-db": {
"type": "http",
"url": "https://mcp.example.com/mcp"
}
}
}
The github entry is stdio: the host runs python server.py itself. Its token goes into an environment variable, and the input line means the editor asks you for it, so the secret never sits in the file. The team-db entry is http, with just a web address. Same list, two roads. Other hosts use a different file name, but the shape is similar.
What the conversation looks like
To see what the SDK does for us, wire.py starts the same server and writes the messages by hand. Each message is one line of JSON-RPC: a request with a method name and an id.
import json
import subprocess
import sys
server = subprocess.Popen([sys.executable, "server.py"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, text=True)
INIT = {"protocolVersion": "2025-06-18", "capabilities": {},
"clientInfo": {"name": "my-agent", "version": "1.0"}}
CALL = {"name": "create_issue", "arguments": {"title": "Add dark mode"}}
def send(method, params, id=None):
msg = {"jsonrpc": "2.0", "method": method, "params": params}
if id:
msg["id"] = id
print(json.dumps(msg), file=server.stdin, flush=True)
if id:
print("->", method)
return json.loads(server.stdout.readline())["result"]
hello = send("initialize", INIT, id=1)
caps = sorted(hello["capabilities"])
print("<-", hello["serverInfo"]["name"], "offers", caps)
send("notifications/initialized", {})
tool = send("tools/list", {}, id=2)["tools"][0]
print("<-", tool["name"], "needs", tool["inputSchema"]["required"])
call = send("tools/call", CALL, id=3)
print("<-", call["content"][0]["text"])
server.terminate()
-> initialize
<- github offers ['prompts', 'resources', 'tools']
-> tools/list
<- create_issue needs ['title']
-> tools/call
<- Created issue #2: Add dark mode
Step one, initialize: the server answers with who it is and what it offers. The client sends a short notifications/initialized note (no id, so no reply), and the session is ready. Step two, tools/list: the server sends each tool and the inputs it needs. Step three, tools/call, with the tool name and arguments, and the server sends back the result.
A server acts as you
A local server runs with your permissions, so treat it like any other program you install. Four habits:
- Trust. Install servers only from sources you trust.
- Scope. Give the smallest access that works: a read-only database user, or one folder, not the whole disk.
- Secrets. With stdio the secret sits in an environment variable. With HTTP it's an OAuth token, and a good token has a narrow scope and an expiry date.
- Audit. Keep a log of which tool ran, when and for whom, and ask a person to confirm risky actions, like deleting data.
MCP makes connecting easy, but you still decide what each server may touch. The same thinking about how much one tool can do, if the agent is tricked, is the subject of the agent attack surface and blast radius.
Common mistakes
- Mixing up client and host. The host is the app. The client is one connection inside it, and it talks to one server.
- Thinking the model talks to the server. The host's client does. The model sees the tool list and the results, nothing else.
- Putting a token in the config file. Use an input prompt or an environment variable, so the secret isn't committed with the file.
- Installing any server you find. It runs as you. Check where it comes from and what it can reach.
Quick recap
| Idea | In one line |
|---|---|
| Why MCP | N + M connections instead of N × M custom connectors |
| Roles | Host (the app), client (one per server), server (offers things) |
| What a server offers | Tools to do, resources to read, prompts to start from |
| The session | initialize, tools/list, tools/call |
| Transports | stdio for local servers, Streamable HTTP for shared ones |
| Safety | Trust, scope, secrets and audit, because a server acts as you |
To turn an API of your own into a server, the next step is building an MCP server with tools, resources and prompts.
Try it yourself
Add a second tool to server.py, say list_issues that returns the titles in ISSUES. Run wire.py again and change it to print every tool from tools/list, not just the first. Then call list_issues and check that "Add dark mode" is in the answer.
Related course on Udemy
Become an AI Engineer: LLMs, RAG, Agents and MCP
Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)Related posts
Context Engineering for a Long-Running Agent: Clear, Compact, Take Notes, Prove It
A support agent forgets the customer's name, order and contact choice after twenty turns and fails 0 of 4 checks. Measure the window, clear old tool output, compact old turns and keep a notes file, and the same chat passes 4 of 4 with 470 tokens instead of 2,945.
What LangChain Is For, and When to Skip It: Five Standard Parts, One Pipe, and a Decision Table
LangChain is a box of standard parts (models, prompts, retrievers, tools, parsers) that snap together with a pipe. The same refund question through the plain Anthropic SDK (1 import, 13 lines) and a chain (3 imports, 14 lines) gives the same answer word for word. It pays off when the bot grows; for one call, the SDK is simpler, with 16 packages instead of 38.
Why Chains Break: No Branch, No Retry, No Pause, and the Same Refund Assistant as a LangGraph Graph
A refund assistant built three ways. The chain runs classify, retrieve, reply once: it answers an opening-hours question with the billing line, misses the 30-day window, and sends a $150 refund with approved False. Plain if/while fixes it but hides the flow; a LangGraph StateGraph puts the branch, the retry loop and the approval stop in the arrows.
LangGraph Nodes, Edges and State: Build Your First Graph, Route With a Conditional Edge, and Read the Run Three Ways
Two small graphs. A refund skeleton: SupportState, a classify node, a route function on a conditional edge, and an Annotated log that appends instead of overwriting. A help desk: classify and answer call a scripted test model, spam goes straight to END after one model call instead of two, and the same run read with invoke, stream values and stream updates.