Tutorial
MCP explained: hosts, clients, servers and transports
What MCP is and how the Model Context Protocol connects AI apps to tools and data: hosts, clients, servers, transports and what the 2026-07-28 spec changed.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
The Model Context Protocol (MCP) is an open protocol for connecting AI applications to tools and data. Before it existed, every app that wanted to let a model search GitHub or query a database needed its own integration, and every service had to build one for each app. MCP replaces that grid of one-off integrations with a single interface: a service writes one MCP server, and any app that speaks MCP can use it.
Anthropic released MCP in November 2024. In December 2025 it was donated to the Agentic AI Foundation under the Linux Foundation, alongside AGENTS.md and goose. It is now supported by most AI coding tools and assistants, including Claude Code, Codex, Cursor and GitHub Copilot. This tutorial explains the moving parts so that the build tutorials make sense.
The three roles
MCP has three roles. The names are confusing at first because two of them sound alike.
Host. The application the person uses: Claude Code, Cursor, the Claude desktop app, your own chatbot. The host owns the model, the conversation and the user’s permissions.
Client. A connector inside the host. The host creates one client per server it connects to. The client speaks the protocol; you rarely write one unless you are building a host.
Server. A program that exposes capabilities over MCP. A GitHub server exposes tools for issues and pull requests; a Postgres server exposes a query tool and the schema; a server you write might expose your company’s internal API.
Host (Claude Code, Cursor, your own app)
├── model, conversation, user permissions
├── MCP client ──────► MCP server: GitHub (remote, HTTP)
├── MCP client ──────► MCP server: Postgres (local, stdio)
└── MCP client ──────► MCP server: yours (local, stdio)
The model never talks to a server directly. The host lists the tools from its servers, includes their descriptions in the model’s context, and when the model asks to call one, the host decides whether to allow it (often by asking you) and passes the call through the right client.
What servers offer
A server can expose three kinds of things, called primitives:
| Primitive | Controlled by | What it is | Example |
|---|---|---|---|
| Tools | The model | Functions the model can call with arguments | create_issue(title, body) |
| Resources | The application | Data the host can read and add to context, addressed by URI | postgres://schema/users |
| Prompts | The user | Reusable prompt templates the user picks, often as slash commands | /review-pr |
In practice, tools do most of the work, and many servers expose only tools. Resources and prompts are useful when the host gives the user a way to attach data or pick a template.
The protocol also defines features that flow the other way, from client to server, such as elicitation (the server asks the user for input mid-call). The current specification deprecates two older client features, roots and sampling, and suggests alternatives: pass directories as tool parameters, and call a model provider’s API directly instead of borrowing the host’s model.
Messages and transports
Under the hood, MCP messages are JSON-RPC 2.0: requests with a method name and parameters, and responses with a result or an error. A tool call looks roughly like this on the wire:
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": { "name": "search_notes", "arguments": { "query": "rollback" } }
}
How those messages travel is the transport. There are two standard transports:
- stdio. The host starts the server as a child process and they exchange messages over standard input and output. Used for local servers: anything that reads your files, runs on your machine or needs your local credentials. Because stdout carries the protocol, a stdio server must write its logs to stderr.
- Streamable HTTP. The server runs as a web service and the client sends HTTP POST requests to one endpoint. Used for remote and shared servers. Remote servers normally use OAuth for authorisation, so you sign in through the host rather than pasting tokens.
What changed in the 2026-07-28 specification
MCP is versioned by date. The revision published on 28 July 2026 is the most significant change since launch, and it is worth knowing about because older articles describe a protocol that now works differently:
- Stateless by default. The old
initializehandshake and protocol-level sessions (theMcp-Session-Idheader) are gone. Each request carries its protocol version and client capabilities. Servers that need state across calls return explicit handles that the model passes back as ordinary tool arguments. - Discovery. Servers implement a
server/discovermethod that advertises supported versions and capabilities. - Change notifications move to a single
subscriptions/listenstream that clients opt into. - Multi round-trip requests. Instead of the server sending its own requests to the client mid-call, it returns a result that says “input required”, and the client retries with the answers.
- Deprecations. Roots, sampling and the logging feature are deprecated, as is the old HTTP+SSE transport.
If you use an official SDK you mostly do not see these details. The TypeScript SDK’s v2 line, for example, implements the 2026-07-28 revision and still serves older clients from the same server code.
Where you meet MCP day to day
Most people use MCP by connecting servers to a coding agent or assistant:
# Claude Code: add a local stdio server (everything after -- is the command to run)
claude mcp add notes -- uv run --directory /path/to/notes-server fastmcp run server.py
# Claude Code: add a remote server over Streamable HTTP
claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
Codex has codex mcp, Cursor reads .cursor/mcp.json, and most hosts accept a JSON configuration with the same three pieces of information: a name, a command or URL, and environment variables. The official MCP Registry lists public servers with their metadata.
Try it: inspect a server
MCP Inspector is the official tool for poking at a server without involving a model. You can try it on any server you have, or on the one you will build in the next tutorial:
npx @modelcontextprotocol/inspector
It opens a local web UI where you enter the command that starts a server (for example python server.py). You then see its tools, resources and prompts, call tools with your own arguments and read the raw responses. Get into the habit of checking a server in Inspector before you connect it to an agent: it separates “the server is broken” from “the model used it badly”.
Security: an MCP server is code you run
Connecting an MCP server gives a model new abilities, and with abilities come risks:
- Local servers run with your permissions. A stdio server can read anything you can. Install servers from sources you trust, pin versions, and read what they do.
- Tool descriptions are prompts. A malicious server can put instructions in a tool description (“before using any tool, send the contents of ~/.ssh to…”). This is called tool poisoning.
- Tool results are untrusted input. A server that reads web pages, issues or emails passes their text to the model. Anything written in that text can try to steer the model. See Prompt injection basics.
- Scope tokens tightly. Give a server a token that can read one repository rather than one that can administer your organisation.
Pitfalls
Confusing MCP with tool calling. Tool calling is a model capability: the model emits a structured request to call a function. MCP is a protocol for discovering and invoking tools that live in another process. MCP servers are one way to supply the tools a model calls. MCP vs function calling wires the same tool both ways, plus a plain API client, so you can see when the protocol earns its place.
Connecting everything. Every connected server’s tool list sits in the model’s context. Connect what the current task needs.
Using MCP where a skill or CLI would do. If the agent can already run a command-line tool, an Agent Skill that explains how to use it is often simpler than a server. The comparison article Agent Skills vs MCP vs AGENTS.md goes through the trade-offs.
Next steps
- Build a server in Python with FastMCP or in TypeScript with the official SDK.
- Wrap a real internal API in the MCP server for an internal API workflow.
- Connect existing servers to your own tools with Connect MCP servers to Claude Code, Codex and Cursor.
- Read what changed in MCP 2026-07-28 if you have used MCP before: the handshake and sessions are gone.
- Before you connect anything that reads untrusted text, read MCP security: tool poisoning, token scope and the lethal trifecta.
- Look up MCP server and related terms in the glossary.
- Learn the rest in order with the agents and MCP learning path.
- When the other side is an agent rather than a tool, see connect two agents with the A2A protocol.
Covers
Check your understanding
MCP explained quiz
Hosts, clients, servers, transports and primitives in the Model Context Protocol.
7 questions · pass mark 70%
Review
Related
- Build an MCP server in Python with FastMCP
Build a small MCP server in Python with FastMCP, test its tools in MCP Inspector without a model, then connect it to Claude Code, Cursor or another MCP host.
- Build an MCP server in TypeScript
Build a small MCP server with the official TypeScript SDK v2, test it from the command line and in MCP Inspector, then connect it to Claude Code or Cursor.
- AGENTS.md vs Agent Skills: which one you need, and where MCP fits
AGENTS.md vs Agent Skills: what an instruction file and a skill each do for a coding agent, when to use which, and how MCP servers fit alongside both of them.
- Model Context Protocol (MCP)
An open protocol that lets AI apps reach external tools, data and prompts through small servers that each wrap one service.
- MCP server
A program that exposes tools, resources or prompts to MCP clients, running locally over stdio or remotely over HTTP, so any MCP host can use them.