Sub topic 12
Connecting a host application
This chapter assumes you have a working server from the earlier chapters, such as the team-tools server, and that you have tested it with the MCP Inspector. You should also be comfortable with absolute paths and Python virtual environments.
What the host does with your configuration
A host is the application the user talks to. It contains one MCP client per server. The host does not import your code. It reads a configuration entry and starts or contacts the server for you.
For a local stdio server, the entry gives a command and its arguments. The host launches that command as a subprocess and talks to it over stdin and stdout.
A minimal stdio configuration
Many hosts, including Claude Desktop, use a JSON file with an mcpServers object. The key is a name you choose, and the host shows it in its interface.
{
"mcpServers": {
"team-tools": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
}
}
}The file location and some key names differ between hosts. Check your host's documentation before copying this. Restart the host after editing, because most hosts read the file only at startup.
Make the launch command reliable
The host starts the subprocess itself. It does not use your shell, your activated virtual environment, or your current directory. Most connection failures come from this difference.
- Use absolute paths for the script and any files it reads.
- Point
commandat the exact interpreter if you rely on a virtual environment, for example/home/you/team-tools/.venv/bin/python. - Pass secrets and settings through the
envfield, not through arguments. Arguments often appear in process listings.
{
"mcpServers": {
"team-tools": {
"command": "/home/you/team-tools/.venv/bin/python",
"args": ["/home/you/team-tools/server.py"],
"env": {
"TEAM_API_URL": "https://internal.example.com/api"
}
}
}
}Hosts usually pass only a limited set of environment variables to the subprocess. If your server needs a variable, list it in env explicitly.
Connecting to a remote server
If you deployed the server over Streamable HTTP, the host connects to a URL and does not launch anything. Hosts differ here. Some accept a url field in the same configuration file, and others add remote servers through a settings screen. Remote servers normally need authentication, so check which credentials your host can send.
Verify the connection
- Restart the host and look for
team-toolsin its list of connected servers. - Confirm that the tools, resources, and prompts you expect are listed.
- Ask a question that needs a tool, such as "Who owns the billing service?", and check that the host asks to run
get_service_owner.
If the server does not appear, read the host's MCP log. The Inspector from the previous chapter helps here. If the exact command and arguments work in the Inspector but fail in the host, the cause is almost always the environment or a relative path.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Server never appears | Invalid JSON or wrong config file | Validate the JSON and confirm the host's config path |
| Starts, then disconnects | Output on stdout, or an import error | Log to stderr and run the same command by hand |
| `ModuleNotFoundError` | Host used a different Python | Use the full path to the venv interpreter |
| File not found | Relative path in `args` | Use absolute paths |
| Tool missing after an edit | Host has not reloaded the config | Restart the host |
Exercise
Your server works in the MCP Inspector, but the host shows it as disconnected right after startup. Name two differences between the two launches that could explain this, and one fix for each.
Show answer
The host may run a different Python interpreter than your shell, so installed packages are missing. Fix this by setting command to the full path of the virtual environment's Python. The host may also start the process in a different working directory, so relative paths fail. Fix this by using absolute paths in args and in the server's file reads. A third possibility is that a missing environment variable is the cause, which you fix by adding it to env.