Sub topic 2
Host, client and server: who does what
This chapter assumes you have used an AI coding assistant, can read JSON, and know that a process can talk to another process over its standard input and output. It does not cover message formats, transports, or configuration files in detail. Later chapters cover those. Here the goal is to know which component does which job, so that later chapters and error messages make sense.
The three roles
The Model Context Protocol (MCP) defines three roles. People often blur them because the words "client" and "server" are used loosely, so it helps to pin each one down.
- Host. The host is the application the user interacts with. A coding assistant in a terminal or editor is a host. It owns the conversation, talks to the language model, shows output to the user, and decides what is allowed to happen.
- Client. The client is a component inside the host. It holds one connection to one server and speaks the protocol on that connection. You rarely see a client directly. It is a library object or module that the host creates for each server it connects to.
- Server. The server is a separate program that exposes capabilities, such as tools, resources, and prompts, to the client. A server might read files, query a database, or call a web API. It does not run the model and it does not see your conversation.
The key point is that "client" in MCP means the connector inside the assistant, not the assistant as a whole. The whole application is the host.
One host, many clients
A host usually connects to several servers at once, for example a filesystem server and a Git server. The host creates one client per server. Each client-server pair is an independent session with its own state.
This one-to-one pairing has practical effects:
- Servers are isolated from each other. The filesystem server cannot see what the database server returned.
- A failure is local. If the Git server crashes, its client reports an error, and the other two sessions keep working.
- The host is the only place where information from all servers meets. It combines the tool lists from every client and presents them to the model as one set of options.
What each role is responsible for
| Concern | Host | Client | Server |
|---|---|---|---|
| Talks to the language model | Yes | No | No |
| Talks to the user | Yes | No | No |
| Decides which servers to start | Yes | No | No |
| Speaks the protocol on one connection | No | Yes | Yes |
| Negotiates capabilities at startup | Through its clients | Yes | Yes |
| Implements tools, resources, prompts | No | No | Yes |
| Asks the user to approve actions | Yes | No | No |
| Touches files, databases, APIs | No | No | Yes |
The table shows how the work is divided. The host handles judgment and user interaction. The client handles protocol mechanics. The server handles real-world capability. Because the roles are separate, one server can work with many different hosts, and one host can work with many different servers. That interchangeability is the point of having a standard.
Following the responsibilities in practice
Suppose you ask your assistant, "Which files in this project mention the word timeout?" Here is who does what.
- The host receives your message and sends it to the language model, along with a description of the tools that its clients discovered earlier.
- The model replies that it wants to call a search tool with certain arguments. The model only produces text that describes the call. It does not run anything.
- The host checks whether this call is permitted. It may ask you to approve it.
- The host hands the call to the client that is connected to the server owning that tool.
- The client sends the request to the server. The server does the actual search and returns the result.
- The client passes the result back to the host. The host gives it to the model, which writes the answer you see.
A later chapter follows this flow message by message. For now, notice that the model never talks to the server directly. Everything passes through the host, which is why the host is the right place for safety decisions.
Where the boundaries matter
The model lives in the host
A server only sees the requests that the client sends it. It does not see the conversation, the system prompt, or the results of other servers unless the host chooses to include that data in a request. This limits what a server can learn about you, and it limits what a badly written server can leak. It also means a server cannot "reason". It cannot decide to call another server or rewrite the model's plan.
The host is the policy point
The protocol specification asks hosts to obtain user consent before exposing data to servers and before invoking tools. The protocol cannot enforce this. A server has no way to verify that the user approved something. Whether you get a confirmation prompt, an allow-list, or no prompt at all depends on how the host was built and configured. Treat this as a feature of your assistant, not of MCP.
Servers can ask for help, but only if the client allows it
Most traffic goes from client to server. MCP also lets a server make requests back to the client, but only for features the client declared support for during startup. Three examples from the specification:
- Sampling. The server asks the host to run a language model completion on its behalf. The host controls the model and can show the request to the user, so the server needs no model credentials.
- Roots. The client tells the server which directories or locations it should work within.
- Elicitation. The server asks the host to collect extra input from the user, such as a missing parameter.
Many hosts do not support all of these features. A server should not assume they exist. The capability exchange in a later chapter is how each side finds out what the other supports.
A server is just a program
A local server is an ordinary process that runs with your user's permissions. The protocol does not sandbox it. The host launches it, and it can do whatever any program you start could do, within whatever the operating system allows. That makes the choice of which servers to run a security decision, which a later chapter covers.
A client in code
You can see the client role directly by writing a small client using the official Python SDK. This program starts a server as a subprocess, connects to it, and lists its tools. It assumes a file named server.py that implements an MCP server, such as the calculator you will write in a later chapter, and that you have installed the SDK with pip install mcp.
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main() -> None:
params = StdioServerParameters(command="python", args=["server.py"])
async with stdio_client(params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.list_tools()
for tool in result.tools:
print(f"{tool.name}: {tool.description}")
asyncio.run(main())In this program, ClientSession plays the client role: it owns one connection and speaks the protocol on it. The script as a whole is a very small host. It decides which server to start and what to do with the results. A real coding assistant does the same things, but adds a language model, a user interface, and a permission system around them. It also repeats the process for every server in its configuration.
Common mistakes
- Calling the assistant "the client". In MCP terms the assistant is the host. If documentation says "the client failed to connect", it means one connection inside the host failed. Other connections may be fine.
- Assuming the server talks to the model. It does not. The server answers requests. The host decides whether the model's output becomes a request.
- Assuming one server connection is shared. Each host-server pair has its own client and its own session. Two hosts running the same server command start two separate server processes (for local servers).
- Expecting protocol-level safety. MCP defines how to ask for a tool call. It does not decide whether the call is wise. Approval and sandboxing belong to the host and the operating system.
- Confusing the process boundary with the role boundary. For a local server, the client lives in the host's process and the server is a child process. For a remote server, the server runs elsewhere on the network. The roles stay the same in both cases. Only the way messages travel changes, which is the topic of the transports chapter.
Exercises
Exercise
Your assistant is configured with three MCP servers. How many clients does the host create, and what happens to the other two sessions if one server crashes?
Show answer
The host creates three clients, one per server. A crash ends only that server's session, and its client reports an error. The other two clients and servers are independent and keep working.
Exercise
A teammate says, "The MCP server decided to run the search tool because the user asked about timeouts." Correct this statement by naming which component made which decision.
Show answer
The language model, which is part of the host's side, decided that a search tool call was appropriate and produced the request text. The host decided whether to allow the call and routed it to the right client. The server did not decide anything about whether to run. It only executed the tool when its client sent the request.
Exercise
A server wants to summarize a long document with a language model but has no model credentials. Which MCP feature lets it do this, and what must be true for it to work?
Show answer
Sampling. The server sends a sampling request back to the client, and the host runs the completion with its own model. This works only if the client declared the sampling capability during initialization. The host can also show the request to the user before running it.