Sub topic 7
Adding a Server to Your Assistant's Configuration
This chapter assumes you can edit JSON files, run commands in a terminal, and have used an AI coding assistant. You should also know the host, client and server roles from earlier chapters. Here you will register an existing MCP server with your assistant and check that it works.
What the configuration does
An MCP server does nothing until the host knows about it. The host is the assistant application. It reads a configuration file, and for each entry it starts a client that connects to one server. For a local server, "connect" means launching the server as a child process and talking to it over stdio.
The file name and location depend on the assistant. Some use a user-level file, some a per-project file, and some offer both. Check your assistant's documentation for the path. The shape of the mcpServers entry is similar across most assistants.
A first entry: the filesystem server
The reference filesystem server gives the assistant read and write access to files in directories you choose.
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
}
}
}Each field has a job:
"filesystem"is the name you choose for the server. The assistant uses it to label the server's tools and to show status.commandis the executable the host launches. Here it isnpx, which runs a Node package.argsis the list of arguments passed to that command.-ytellsnpxto install the package without prompting. The last argument is the one directory the server may access.
The host runs the equivalent of npx -y @modelcontextprotocol/server-filesystem /path/to/project. If you can run that command yourself and it waits for input without errors, the host can usually run it too.
Passing secrets with env
Many servers need a token or other setting. Use the env field to pass these values to the server process. They stay out of the server's source code and out of the args list.
{
"mcpServers": {
"my-api": {
"command": "python",
"args": ["server.py"],
"env": { "API_TOKEN": "<set-in-your-environment>" }
}
}
}The placeholder shows where the value goes. Replace it with a real token only if the config file is private. Do not commit a file containing a real token to version control. Some assistants can read a value from your shell environment instead of storing it in the file. Check whether yours supports that.
Common errors
Most failures at this step come from the launch, not from MCP itself.
| Symptom | Likely cause | Fix |
|---|---|---|
| Server shows as failed or never appears | `command` not found on the host's `PATH` | Use the full path to the executable, or install the runtime |
| Works in your terminal, fails in the assistant | The host has a different `PATH` or working directory | Use absolute paths in `command` and `args` |
| Server starts, then disconnects | The process crashed or printed non-protocol text to stdout | Run the command by hand and read the error output |
| Tools missing after editing the file | The host reads the config only at startup | Restart the assistant or reload its servers |
| Server cannot see your files | Wrong or relative directory argument | Pass an absolute path |
A stdio server must write only protocol messages to stdout. Any stray print goes to the same channel and corrupts the stream. Servers should send logs to stderr.
Verify the connection
After restarting the assistant, look for the server in its server list or status view. Then confirm the tools were discovered. Most assistants show tool names, or you can ask the assistant which tools it has from filesystem. If the list is empty or the status is an error, run the launch command in a terminal first. A later chapter covers the MCP Inspector for deeper debugging.
Exercise
Your entry works when you run npx -y @modelcontextprotocol/server-filesystem /path/to/project in a terminal, but the assistant shows the server as failed. Name two likely causes and one fix for each.
Show answer
First, the assistant may launch with a different PATH than your shell, so it cannot find npx. The fix is to use the full path to npx in command. Second, the directory argument may be relative, so it resolves against a different working directory. The fix is to pass an absolute path. Another valid cause is that the assistant was not restarted after the file was edited.
Exercise
Why is env a better place for an API token than the server's source code or args?
Show answer
The source code is often shared or committed, and args can show up in process listings and logs. The env field passes the value to the server process as an environment variable, so the code stays free of secrets and the config file is the only place to protect.