Sub topic 2
Hosts, clients, and servers: who does what
This chapter assumes you know basic JSON, how LLM tool calling works, and how client-server communication works. It names the three roles in the Model Context Protocol (MCP) and shows how they connect. Later chapters cover the messages and the handshake in detail.
The three roles
MCP splits an AI application into three parts.
- Host: the application the user runs, such as a desktop chat app or an IDE. It owns the model conversation, the user interface, and the decisions about what is allowed.
- Client: a connector object inside the host. Each client holds one connection to one server and speaks the protocol on the host's behalf.
- Server: a program that exposes tools, resources, or prompts to a client. It can run on the user's machine or on a remote host.
The host is the only role the user sees. Clients and servers are plumbing.
One client per server
A host that uses three servers creates three clients. Each client keeps its own session, its own negotiated capabilities, and its own state. This isolation matters. A server sees only what its own client sends it. It cannot read the conversation or talk to other servers directly. The host decides what crosses between them.
What each role does
| Role | Responsibilities | Does not do |
|---|---|---|
| Host | Starts clients, talks to the model, shows results, asks the user for consent | Implement each server's logic |
| Client | Opens a session, negotiates capabilities, sends requests, relays responses | Decide policy on its own |
| Server | Declares features and handles requests for them | See the full conversation or other servers |
A request, step by step
Suppose a user asks a chat app, "What is 2 plus 3?" and an add tool is available.
- The host sends the user's message and the tool list to the model.
- The model asks to call
addwitha=2andb=3. - The host checks policy. It may ask the user to approve the call.
- The host tells the matching client to send the call.
- The client sends a request to the server, and the server runs
add. - The server's result returns through the client to the host.
- The host gives the result to the model, which writes the final answer.
The model never talks to a server. The host mediates every step, and that is where consent checks happen.
Roles are not fixed to programs
A role describes behavior on one connection, not a kind of program. One program can be a server on one connection and a client on another. For example, a server that wraps a search service can itself connect as a client to a database server. Servers can also ask things of clients. Later chapters cover those client features: sampling, roots, and elicitation.
Common errors
- Treating the host and the client as the same thing. The host is the whole application. A client is one connection inside it. Policy and consent belong to the host.
- Assuming one client can talk to many servers. The protocol pairs one client with one server. Connecting to ten servers means ten clients.
- Assuming the model connects to servers. The model only produces text and tool-call requests. The host decides whether to act on them.
- Assuming a server can see the whole chat. It sees only what the host chooses to send it.
Exercise
A host is configured with a filesystem server and a calendar server. How many clients does it create, and can the calendar server read the filesystem server's results directly?
Show answer
It creates two clients, one for each server. The calendar server cannot read the filesystem server's results. Each server only talks to its own client, and only the host decides what information moves between them.
Exercise
In the tool call example, which role decides whether to ask the user for approval before the call is sent, and why that role?
Show answer
The host decides. It owns the user interface and the policy, and it sits between the model and every client. The client only relays messages, and the server only handles requests it receives.