Sub topic 2
Hosts, clients and servers
This chapter assumes you can read async Python, know what JSON Schema is, and have called an LLM API with tool calling. It explains the three roles in the Model Context Protocol (MCP). The rest of the tutorial builds on them.
The three roles
MCP splits an integration into three parts.
- Host: the application the user runs. It owns the conversation, calls the LLM, and decides what the model is allowed to do. The application you write in this tutorial is a host.
- Client: a connector inside the host. Each client keeps one connection to one server. It sends requests, receives responses, and tracks the state of that connection.
- Server: a program that exposes capabilities such as tools, resources and prompts. It can be a local process or a remote service.
The relationship is one host, many clients, and exactly one server per client. To use three servers, the host creates three clients.
Who does what
The LLM never speaks MCP. The model only sees tool definitions and returns tool-call requests in the format of its own API. The host translates between the two worlds.
| Role | Talks to | Responsibility |
|---|---|---|
| Host | The user, the LLM API, its clients | Conversation, approvals, deciding which tools the model sees |
| Client | One server | Protocol messages, connection state |
| Server | One client at a time per connection | Running tools, serving data and prompts |
In the Python SDK, the ClientSession class plays the client role. Your own code around it is the host.
Why the split matters
The separation gives you three practical benefits.
- Reuse. A server written once works with any host that speaks MCP. You do not write a new integration for each application.
- Isolation. Each client has its own connection. A crashed or slow server affects only its own client, and the host can keep running.
- Control. The host sits between the model and every server. It is the right place to ask the user for approval, filter tools, and log activity.
That last point is the most important for later chapters. Servers are often written by third parties. A server cannot make the host call it. The host decides what to connect to and what to expose to the model.
A common mistake
Beginners often call the whole application "the MCP client". In the specification, the client is only the per-server connector. If you describe your application as a host with several clients, other developers and the documentation will read it correctly.
Where this leads
The next chapters look at what servers offer (tools, resources and prompts) and how the messages and transports work. Keep the three-role picture in mind. Every later step, from listing tools to running the agent loop, happens in the host through a client talking to a server.
Exercise
Your application connects to a file server and a database server, then passes their tools to an LLM. Name the host, count the clients, and say which component converts the model's tool-call request into an MCP request.
Show answer
The host is your application. It has two clients, one per server. The host's own code (the agent loop) converts the model's tool-call request into an MCP request and sends it through the matching client, because the model never speaks MCP directly.