Sub topic 10
Configuring a host to launch and use servers
This chapter assumes you have read the earlier chapters on hosts, clients, and servers, on the stdio and Streamable HTTP transports, and on building a minimal server. You should be comfortable reading JSON and running commands in a terminal. Here you will learn how a host learns which servers exist, how it starts them, and what usually goes wrong.
What the host configuration does
A server does nothing until a host connects to it. The host needs to know three things for each server:
- A name the user and the host will use to refer to it.
- How to reach it. For a local server this is a command to run. For a remote server it is a URL.
- Any extra settings the server needs, such as arguments or environment variables.
Most hosts keep this information in a JSON file. The protocol itself does not define that file. The specification covers messages between client and server, not how a host stores its settings. So the file name, its location, and some of its fields differ from host to host. Many hosts, including Claude Desktop, use a common shape with a top-level mcpServers object.
{
"mcpServers": {
"demo": {
"command": "python",
"args": ["server.py"]
}
}
}Each key under mcpServers is a server name. Each value describes how to launch that server. In this example the host will run python server.py and treat that process as the server called demo.
What happens when the host starts
For every entry, the host creates one MCP client. That client owns exactly one connection to one server. The sequence for a local server looks like this:
The steps are:
- The host reads the configuration, usually when it starts. Many hosts do not re-read the file while running, so you often need to restart the host after an edit.
- The host creates a client for each entry.
- For a stdio server, the client launches the command as a subprocess. It writes JSON-RPC messages to the process's standard input and reads replies from its standard output.
- The client sends
initialize, the server answers with its capabilities, and the client sends thenotifications/initializednotification. - The client lists what the server offers, such as tools, and passes that information to the host.
- The host presents the tools to the model, along with its own tools and those of other servers.
The server's lifetime is tied to the host. When the host closes, it ends the subprocess.
Configuring a local stdio server
A stdio entry has these common fields:
| Field | Meaning |
|---|---|
| `command` | The executable to run, such as `python`, `node`, `npx`, or `uvx`. |
| `args` | A list of arguments passed to the command. |
| `env` | Extra environment variables for the subprocess. |
Here is a more realistic entry:
{
"mcpServers": {
"demo": {
"command": "/home/alex/projects/demo/.venv/bin/python",
"args": ["/home/alex/projects/demo/server.py"],
"env": {
"DEMO_API_KEY": "replace-me"
}
}
}
}Notice that both paths are absolute. This is deliberate, and the next section explains why.
Why absolute paths matter
The host launches your server, not your shell. That has several consequences:
- The working directory of the subprocess is chosen by the host. It is often not your project folder, so a relative path like
server.pymay fail. - The subprocess may not inherit your
PATH. Apythonthat works in your terminal might be missing, or might be a different Python without themcppackage installed. - A virtual environment is not active. Pointing
commandat the interpreter inside the environment is the reliable way to use it. - Tools like
npxoruvxmay not be on the host'sPATH, especially when the host is a desktop application started from a launcher.
When a server works in your terminal but fails in the host, the cause is nearly always one of these. Use absolute paths for the command and for each file argument.
Handling secrets
The env field is convenient, but the values sit in a plain text file. Keep these points in mind:
- Do not commit the configuration file to version control if it contains keys.
- Give each server only the credentials it needs.
- Some hosts support referencing environment variables or an input prompt instead of literal values. Check your host's documentation, since this is host-specific.
Standard output is reserved
With stdio, the server's standard output carries protocol messages and nothing else. A stray print() in your server writes text into the message stream. The client then fails to parse it, and the connection usually breaks.
Write diagnostics to standard error instead. Hosts typically capture standard error into a log file.
import sys
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
print(f"add called with {a}, {b}", file=sys.stderr)
return a + b
if __name__ == "__main__":
mcp.run(transport="stdio")The print call goes to standard error, so the protocol stream stays clean. The same rule applies to any library your server imports that prints to standard output.
Configuring a remote server
A remote server runs elsewhere and is reached over Streamable HTTP. The configuration holds a URL instead of a command. The exact field names differ by host. Some use url, some use serverUrl, and some require a type field such as http. A typical shape looks like this:
{
"mcpServers": {
"remote-demo": {
"type": "http",
"url": "https://example.com/mcp",
"headers": {
"Authorization": "Bearer replace-me"
}
}
}
}Treat this as an illustration of the idea and confirm the field names in your host's documentation. Some hosts do not support remote entries in their configuration file at all and instead add them through a settings screen.
Compare the two kinds of entry:
| Aspect | Local (stdio) | Remote (Streamable HTTP) |
|---|---|---|
| Who starts the server | The host, as a subprocess | Someone else, independently |
| Entry identifies server by | `command` and `args` | `url` |
| Server lifetime | Tied to the host | Independent of the host |
| Credentials | Usually `env` values | Usually HTTP headers or an authorization flow |
| Failure signs | Process exits or prints bad output | Network errors, HTTP status codes |
Several servers at once
You can list as many servers as you want. Each gets its own client and its own session.
{
"mcpServers": {
"demo": {
"command": "/home/alex/projects/demo/.venv/bin/python",
"args": ["/home/alex/projects/demo/server.py"]
},
"notes": {
"command": "/usr/bin/node",
"args": ["/home/alex/projects/notes/dist/index.js"]
}
}
}The host merges the tools from all servers into what the model sees. Two servers can define a tool with the same name. How the host resolves that clash is host-specific. Some prefix tool names with the server name and some do not. If you control the servers, pick distinctive tool names.
Each server also adds to the model's context, because every tool description is sent along with the request. A long list of servers with many tools costs tokens and can make the model choose less accurately. Enable only the servers a given task needs.
Consent and trust in configuration
A configuration entry for a local server is a command that the host runs on your machine with your permissions. Adding an entry is the same as installing a program.
- Only add servers from sources you trust, and read what a command does before adding it.
- A command such as
npx some-packagedownloads and runs code. Pin a version where you can, so the code does not change without your knowledge. - Hosts commonly ask for approval before running a tool. Do not turn that off for servers you have not reviewed.
The security chapter covers consent in more depth. For now, treat the configuration file as a list of programs that run as you.
Troubleshooting a server that does not appear
Work through these checks in order:
- Validate the JSON. A trailing comma or a missing quote makes the whole file unreadable, and some hosts then show no error.
- Restart the host fully. Closing the window may leave the application running in the background.
- Run the exact
commandandargsfrom a terminal, using the same absolute paths. If it fails, fix that first. - Confirm the server waits for input. A stdio server that starts and then sits silent is healthy. One that exits at once is not.
- Check the host's MCP log file. Standard error output from your server appears there in many hosts.
- Look for output on standard output that is not JSON-RPC.
- Test the server alone with a debugging tool, covered in the next chapter, to separate server faults from host faults.
You can also reproduce the handshake by hand. Start the server, paste the initialize request on one line, and see whether a valid result comes back:
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "manual-test", "version": "1.0.0"}}}A valid result containing the server's capabilities shows that the server itself is sound. Keep in mind that a real session also expects the notifications/initialized notification afterward.
Summary of key points
- A host configuration tells the host which servers to connect to and how.
- Each entry produces one client with one connection to one server.
- Local entries use
command,args, andenv. Remote entries use a URL. - Use absolute paths because the host does not share your shell environment.
- Never write non-protocol text to standard output in a stdio server.
- Every local entry is a program that runs with your permissions, so add only servers you trust.
Exercise
Your server runs correctly with python server.py in your terminal, but the host shows no tools from it. The configuration has "command": "python" and "args": ["server.py"]. Give two likely causes and the fix for each.
Show answer
First, the host launches the process from a different working directory, so server.py is not found. Second, the python the host finds may differ from the one in your terminal and may lack the mcp package, because your virtual environment is not active. The fix for both is to use absolute paths: set command to the interpreter inside the virtual environment and give the full path to server.py in args. Then restart the host.
Exercise
A stdio server you wrote works with the Python client but breaks in the host with parse errors in the log. The server has a line print("starting up") at the top of the file. Why does this break the connection, and what should you do instead?
Show answer
In stdio, the server's standard output carries the JSON-RPC messages. The text "starting up" is not valid JSON-RPC, so the client cannot parse it and the session fails. Send diagnostic text to standard error instead, for example print("starting up", file=sys.stderr), or use the SDK's logging facilities that write to standard error.
Exercise
Why is adding a local server entry to your host configuration a trust decision, and what two habits reduce the risk?
Show answer
The entry is a command that the host runs on your machine with your user's permissions, so it is equivalent to installing and running a program. Reduce the risk by adding only servers from sources you trust after reading what the command does, and by pinning package versions for commands like npx or uvx so the code cannot change silently. Keeping the host's per-tool approval prompts enabled also helps.