Sub topic 2
Hosts, clients, and servers
This chapter assumes you can read JSON and know the basic idea of LLM tool calling: a model asks for a function to be run, and the application runs it. The chapter names the three roles in MCP (Model Context Protocol) and shows how they connect. Later chapters use these roles when they cover the session handshake, transports, and configuration.
The three roles
MCP splits a connection into three parts.
| Role | What it is | Example |
|---|---|---|
| Host | The AI application the user interacts with. It runs the model and decides what the model may do. | Claude Desktop, an IDE assistant, a chat tool you build |
| Client | A connector inside the host. It holds one connection to one server and speaks the protocol. | A client object created by the host's MCP library |
| Server | A program that exposes tools, resources, and prompts. | The `team-tools` server you will write |
You write the server. The host and client usually come from an existing application or an SDK.
One client per server
A host does not talk to servers directly. For each server it connects to, it creates a separate client. If a host uses three servers, it holds three clients, and each client has its own session and state.
This design isolates servers from each other. The team-tools server cannot see what the filesystem server returns. Only the host sees all of them, because the host is the one that combines the results for the model.
What the host is responsible for
The host owns everything that involves the model or the user:
- It starts or connects to servers, usually from configuration.
- It collects the tools from every client and presents them to the model.
- It sends the model's tool requests to the right client.
- It asks the user for approval before risky actions.
The server does none of this. A server only describes what it offers and answers requests. It does not call the model, and it does not know which model is on the other side.
What the server is responsible for
Your server answers three kinds of questions from its client:
- What do you offer? (The list of tools, resources, and prompts.)
- Run this tool with these arguments.
- Give me this resource or prompt.
Because the server only answers requests, one server can work with many hosts. The same team-tools code can run under a desktop app, an IDE, or a command-line agent without changes.
How the host finds your server
For a local server, the host reads a configuration file, starts your program as a subprocess, and creates one client for it. Each entry below produces one client.
{
"mcpServers": {
"team-tools": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp/shared"]
}
}
}The file location and exact keys depend on the host. The pattern is the same everywhere: a name, a command to run, and its arguments. A later chapter covers this configuration in detail.
Common mistakes
- Calling the host the client. In casual speech people say "the MCP client" for the whole application. In the protocol, the client is the per-server connector inside the host. Keep the terms separate when you debug, because a problem in one connection does not mean the host is broken.
- Putting user approval in the server. The host controls confirmation prompts. Your server can describe a tool honestly and refuse bad input, but it cannot rely on its own dialog to protect the user.
- Assuming one shared state. Each client has its own session. Do not store per-conversation data in a global variable and expect another client to see it, or to be isolated from it, without checking how your transport handles sessions.
- Expecting the server to start the conversation. The client opens the connection and asks first. The server responds.
Exercise
A host application is configured with four MCP servers. How many clients does it hold, and which part of the system decides whether the user must approve a tool call?
Show answer
It holds four clients, one per server. The host decides whether the user must approve a tool call, because the host owns the model and the user interaction. The server only describes its tools and answers requests.