Sub topic 10
Configuring a Host to Launch and Use Servers
This chapter assumes you have read the earlier chapters on roles and transports. You should know that a host runs one client per server, and that a stdio server is a subprocess. It also assumes you can read JSON and run commands in a terminal. Here you will see how a host learns which servers to start, and what goes wrong when the configuration is off.
What a host configuration does
A host does not discover servers on its own. A user tells it which servers to use, usually through a JSON file. At startup the host reads the file. For each entry it launches the server, creates a client for it, and runs the initialization handshake from the lifecycle chapter. If the handshake works, the server's tools, resources, and prompts become available to the host.
The mcpServers format
Many hosts, such as Claude Desktop, read a file in this format. The file name and location differ by host, so check your host's documentation.
{
"mcpServers": {
"demo": {
"command": "python",
"args": ["server.py"]
}
}
}Each key under mcpServers is a name you choose. The host uses it to label the connection. The fields for a stdio server are:
| Field | Meaning |
|---|---|
| `command` | The executable the host runs |
| `args` | A list of arguments passed to the command |
| `env` | Optional environment variables for the subprocess |
The demo entry above is equivalent to running python server.py in a terminal. The host then talks to that process over its standard input and output.
Passing secrets and settings
Some servers need an API key or a path. Many hosts accept an env object for this:
{
"mcpServers": {
"demo": {
"command": "python",
"args": ["server.py"],
"env": {
"DEMO_API_KEY": "replace-with-your-key"
}
}
}
}The server reads the value from its environment. Keep this file out of version control if it holds real secrets.
Common errors
Most failures come from the fact that the host, not your shell, launches the process.
- Command not found. The host may not use your shell's
PATH. Apythonthat works in your terminal may be missing, or may be a different version, when the host starts it. Use an absolute path to the executable. - Relative paths.
server.pyis resolved against the host's working directory, which is often not your project folder. Use an absolute path inargs. - Wrong virtual environment. If the SDK is installed in a virtual environment, point
commandat that environment's Python. - Output on stdout. With stdio, stdout carries protocol messages. A stray
printin your server corrupts the stream. Write logs to stderr instead. - Invalid JSON. A trailing comma or a comment breaks the whole file, and the host may silently load no servers.
- No restart. Most hosts read the file only at startup. Restart the host after each edit.
Checking that it works
After a restart, look in the host's interface for the server and its tool list. If nothing appears, run the same command by hand with the same absolute paths. If the server starts and waits for input, the command is probably fine, and the problem is in the host configuration or the handshake. The debugging chapter covers MCP Inspector, which lets you test a server without a host.
Exercise
A server works when you run python server.py in your project folder, but the host shows no tools. Name two configuration problems that could explain this, and one fix for each.
Show answer
First, the host may launch python from a different PATH or environment, so the SDK is not found. Fix it by setting command to the absolute path of the Python in the correct virtual environment. Second, server.py is a relative path and the host's working directory is different. Fix it by using the absolute path to server.py in args. Other valid answers are a print to stdout that corrupts the stream, invalid JSON in the config file, or not restarting the host.