esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

AI engineering / Advanced / 03.02

MCP hosts, clients and servers

The three roles in MCP: the app you run, the connector it keeps for each server, and the server that offers tools, data and prompts.

13 min readFree

Who does what

The last lesson, Agent SDKs, ended by saying that next comes MCP hosts, clients and servers, and who does what. Here it is.

The beginner MCP lesson introduced the idea: one standard plug between AI apps and tools. It named three roles in one line each. This lesson slows down. You will see what each role owns, what a server can offer, what a client can offer back, and how a connection starts and ends.

At the end you will run a small Python program that models the roles. It is a teaching model, not the official SDK, so nothing in it talks to a real MCP server.

Key words

Host
The AI application the person runs, such as a chat app or a code editor.
Client
A connector the host creates. It keeps one connection to one server.
Server
A program that offers tools, data or prompts to the AI app. It can run on your computer or somewhere else.
Capability
A feature a side says it supports, like "I have tools". Each side declares its own.
Handshake
The first exchange when two programs meet, where they agree on how to talk.
Revision
A dated version of the MCP specification. This lesson names the two it reads: 2025-11-25 and the latest, 2026-07-28.

The three roles, in the spec's words

The specification overview gives each role one short line. It says Hosts are "LLM applications that initiate connections", Clients are "Connectors within the host application", and Servers are "Services that provide context and capabilities".

The official architecture guide words it a little differently. It says an MCP host is an AI application that coordinates and manages one or multiple MCP clients. An MCP client is a component that maintains a connection to an MCP server and obtains context from it for the host to use. An MCP server is a program that provides context to MCP clients.

Think of a travel desk. The host is the person at the desk. Each client is one phone line, and each line rings exactly one shop: the hotel, the train station, the museum. Each server is a shop at the far end of a line. The person at the desk decides which lines to open and what may be asked. The shops only answer what is asked of them.

  • Host

    The app in front of the person. It opens and closes the lines.

  • Client

    One line. It is created by the host and talks to exactly one server.

  • Server

    The shop at the other end. It offers what it has, and nothing more.

A real example, and where servers run

The official guide gives an example. Visual Studio Code acts as an MCP host. When it connects to an MCP server such as the Sentry server, the runtime creates an MCP client object that keeps that connection. When it later connects to another server, such as the local filesystem server, it creates one more client object.

So two servers mean two clients, inside one host. The guide also says an MCP server is the program that serves context, wherever it runs. A server can run on your own machine, called local, or on someone else's, called remote. It notes that local servers using the STDIO transport typically serve a single client, while remote servers using Streamable HTTP will typically serve many clients. A transport is the way the messages travel. The next lesson covers transports.

The host in depth

The specification calls the host "the container and coordinator". The architecture page lists what it does. It creates and manages multiple client instances. It controls client connection permissions and lifecycle. It enforces security policies and consent requirements, and it handles user authorization decisions. It also coordinates AI and LLM integration, and manages context aggregation across clients.

Context aggregation just means collecting what the different servers gave, and deciding what the model gets to see. The host is the only role that sees the whole picture.

That matters for safety. One of the design principles says servers should not be able to read the whole conversation, nor "see into" other servers. The full conversation history stays with the host, and cross-server interactions are controlled by the host. If your travel desk calls the hotel, the hotel does not hear what the museum said.

Tip

When you build a product with MCP, you are usually building the host. Plan the permission and consent screens first, because the specification gives them to you.

The client in depth

A client is small and has one job. The specification says each client is created by the host and communicates with exactly one server. A host application creates and manages multiple clients, with each client having a 1:1 relationship with a particular server.

In the 2025-11-25 revision, the client establishes one stateful session per server and handles protocol negotiation and capability exchange. In the latest revision, the client attaches the protocol version and capabilities to every request. Both revisions say the client routes protocol messages bidirectionally, manages subscriptions and notifications, and maintains security boundaries between servers. Bidirectionally means messages can flow both ways: the client asks, and sometimes the server asks back.

Why one client per server? It keeps a bad or broken server from touching the others. If the museum line drops, the hotel line still works.

The server in depth

The specification says servers provide specialized context and capabilities. They expose resources, tools and prompts through what it calls MCP primitives. They operate independently with focused responsibilities, must respect security constraints, and can be local processes or remote services.

A server offers any of three features. The specification gives each a short definition, and each page also says who is meant to be in charge of using it.

  • Tools

    "Functions for the AI model to execute". Tools are designed to be model-controlled: the model can discover and invoke them based on the conversation. Example: "add a note".

  • Resources

    "Context and data, for the user or the AI model to use". Resources are designed to be application-driven: the host decides how to bring them in. Each one is identified by a URI, which is just an address such as notes://today.

  • Prompts

    "Templated messages and workflows for users". Prompts are designed to be user-controlled: a person picks them, for example as a slash command. The server writes the content, but the user decides when it is used.

The guide adds how a client uses them. Each kind has a way to list what exists (tools/list, resources/list, prompts/list). To use one, a client calls resources/read, prompts/get or tools/call. Because a client lists them each time, a server can change what it offers.

Tip

A server does not need all three. A server that only has tools is normal.

Quick check

Who is meant to decide when an MCP tool is used?

What a client can offer back

Offers do not only flow from servers. The 2025-11-25 revision lists three features a client can offer to a server: roots, sampling and elicitation. A client says which ones it supports when the connection starts.

  • Roots

    The folders and files the client thinks are relevant. The specification calls them informational guidance rather than an access-control mechanism, and says the protocol does not enforce that servers stay within them.

  • Sampling

    A server asks the client to get a reply from the AI model, so the server needs no model keys of its own. The specification says there should always be a human in the loop who can deny these requests.

  • Elicitation

    A server asks the person for more information. It has two modes: a form for structured answers, and a URL for sensitive steps that must not pass through the client.

Elicitation has a firm safety rule. Servers must not use form mode to ask for passwords, API keys, access tokens or payment credentials. For those, they must use URL mode.

Now the change. The latest revision, 2026-07-28, marks roots and sampling as deprecated. Deprecated means still in the specification, but new projects should not start using it. The pages say they stay for at least twelve months after the revision before they could be removed. For roots, the pages suggest passing directories or files through tool parameters, resource URIs or server configuration. For sampling, they suggest integrating directly with model provider APIs. Elicitation is not deprecated, and is the one client feature the latest overview lists.

The life of a connection

The 2025-11-25 lifecycle page describes a connection in three phases: initialization, operation and shutdown. Here is how it goes, written out as steps.

  1. 1

    Initialise

    The client sends an initialize request with the protocol version it supports, its capabilities and information about itself. It must be the first thing that happens.

  2. 2

    Negotiate

    The server replies with its own capabilities and information. If it cannot use the client's version, it answers with another it supports. The client then sends a notifications/initialized message to say it is ready.

  3. 3

    Operate

    Both sides send messages, and both must use only the capabilities that were agreed. A server that did not declare tools cannot be asked for tools.

  4. 4

    Shut down

    The page says no specific shutdown messages are defined. The transport ends the connection instead. For stdio, the client closes the input stream to the server and waits for it to exit. For HTTP, closing the connection is the signal.

Capability declarations are how each side tells the other what to expect. The page's table lists client capabilities (roots, sampling, elicitation, tasks) and server capabilities (prompts, resources, tools, logging, completions, tasks).

What changed in the latest revision

The latest revision, 2026-07-28, changes the opening. Its architecture page says MCP is a stateless protocol: every request is self-contained and carries its own protocol version and capabilities. The versioning page puts it plainly: there is no negotiation handshake.

Instead of an initialize request, each request carries the version, who the client is, and its capabilities as extra data called metadata. A server tells the client what it supports in answer to a server/discover request. The page says servers must implement server/discover, and clients may call it first but do not have to.

The same page calls versions that open with an initialize handshake legacy (2025-11-25 and earlier), and the newer ones modern. A server can support both. This is why the code below follows the older, legacy shape: the handshake makes the steps easy to see. Check the current revision before you build against a real server.

Quick check

In the 2025-11-25 revision, what must be the first thing that happens between a client and a server?

Model the roles in Python

Let's build the roles as small Python classes. A Host holds two Client objects. Each Client is connected to one Server object that offers one tool and one resource. The servers run inside the same program, so no network is used.

This models the roles and the shape of the messages, using the 2025-11-25 handshake. It is not the official SDK, and it skips most of the rules: no transport, no checking of capabilities before use, no shutdown.

Python
class Server:
    """A stand-in server: one tool and one resource, answered in-process."""

    def __init__(self, name, tool, resource):
        self.name = name
        self.tool = tool          # (tool name, description)
        self.resource = resource  # (uri, text)

    def handle(self, request):
        method = request["method"]
        if method == "initialize":
            result = {
                "protocolVersion": "2025-11-25",
                "capabilities": {"tools": {}, "resources": {}},
                "serverInfo": {"name": self.name, "version": "1.0.0"},
            }
        elif method == "tools/list":
            name, description = self.tool
            result = {"tools": [{"name": name, "description": description}]}
        elif method == "resources/list":
            uri, _ = self.resource
            result = {"resources": [{"uri": uri, "name": uri.split("/")[-1]}]}
        else:
            return {"jsonrpc": "2.0", "id": request["id"],
                    "error": {"code": -32601, "message": "Method not found"}}
        return {"jsonrpc": "2.0", "id": request["id"], "result": result}


class Client:
    """One connection, to exactly one server."""

    def __init__(self, server):
        self.server = server
        self.next_id = 1
        self.server_capabilities = {}

    def ask(self, method, params=None):
        request = {"jsonrpc": "2.0", "id": self.next_id, "method": method}
        if params:
            request["params"] = params
        self.next_id += 1
        return self.server.handle(request)["result"]

    def initialize(self):
        result = self.ask("initialize", {
            "protocolVersion": "2025-11-25",
            "capabilities": {},
            "clientInfo": {"name": "TinyHost", "version": "0.1"},
        })
        self.server_capabilities = result["capabilities"]
        return result["serverInfo"]["name"]


class Host:
    """The app the user runs. It keeps one client per server."""

    def __init__(self, servers):
        self.clients = [Client(server) for server in servers]

    def start(self):
        for client in self.clients:
            name = client.initialize()
            print("connected to", name, "| it offers:", sorted(client.server_capabilities))

    def everything_visible(self):
        seen = []
        for client in self.clients:
            if "tools" in client.server_capabilities:
                for tool in client.ask("tools/list")["tools"]:
                    seen.append(("tool", tool["name"], tool["description"]))
            if "resources" in client.server_capabilities:
                for res in client.ask("resources/list")["resources"]:
                    seen.append(("resource", res["name"], res["uri"]))
        return seen


notes = Server("NotesServer", ("add_note", "Save a new note"),
               ("notes://today", "Buy milk"))
calendar = Server("CalendarServer", ("add_event", "Put an event on the calendar"),
                  ("calendar://week", "Mon: team call"))

host = Host([notes, calendar])
print("clients held by the host:", len(host.clients))
host.start()
print()
for kind, name, detail in host.everything_visible():
    print(f"{kind:8} {name:10} {detail}")

Output

clients held by the host: 2
connected to NotesServer | it offers: ['resources', 'tools']
connected to CalendarServer | it offers: ['resources', 'tools']

tool     add_note   Save a new note
resource today      notes://today
tool     add_event  Put an event on the calendar
resource week       calendar://week

Read it from the top. The host holds 2 clients, one per server. When it starts, each client sends an initialize request, and each server answers with its capabilities. Both servers say they offer resources and tools, so the host knows it may ask them for both.

Then everything_visible asks each client for its tools and resources. Four things show up: two tools and two resources. The host puts them together, so the person, or the model, sees one list, even though they came from two separate servers.

Notice what the code does not do. The notes server never learns that the calendar server exists. Only the host sees both, which is the isolation the specification asks for.

What to remember

  • The roles

    The host is the app the person runs. It creates one client per server. A server offers tools, resources and prompts.

  • The offers

    Tools are for the model, resources are for the app, prompts are for the user. A client can offer roots, sampling and elicitation back.

  • The life

    In 2025-11-25: initialise, negotiate, operate, shut down. In 2026-07-28, there is no handshake, and each request carries its own version and capabilities.

Quick check

How many servers does one MCP client talk to?

Next: MCP's data and transport layers, what is said and how it travels.

Sources

How is this lesson?

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.