Sub topic 7
Adding a Server to Your Assistant's Configuration
This chapter shows how to register an existing MCP server with a coding assistant so the assistant can launch it and use its tools. It assumes you can edit JSON files, run commands in a terminal, and have Node.js installed (for npx) or Python available. You should also know the host, client and server roles from earlier chapters, and that the stdio transport means the host starts the server as a child process.
What a configuration entry does
An MCP server does not run by itself when you open your assistant. The host (your coding assistant) reads a configuration file, finds a list of servers, and for each one starts a process or opens a connection. The host's built-in MCP client then performs the initialization handshake and asks the server what it offers.
So a configuration entry answers three questions:
- What is this server called?
- How does the host start it, or where does it connect?
- What settings does the server need, such as a token or a directory?
Most assistants use a JSON object named mcpServers. Each key inside it is a name you choose, and each value describes how to launch that server.
A first entry: the filesystem server
The reference filesystem server lets the assistant read and write files in a directory you name. Here is a typical entry:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
}
}
}Each part has a job:
| Field | Meaning |
|---|---|
| `"filesystem"` | The server's name. You choose it. The assistant shows it in its tool list and often uses it as a prefix on tool names. |
| `command` | The executable the host runs. Here it is `npx`, which downloads and runs an npm package. |
| `args` | The arguments passed to the command, as a list of separate strings. |
The arguments do three things here. -y tells npx to install the package without asking for confirmation, which matters because the host cannot answer an interactive prompt. @modelcontextprotocol/server-filesystem is the package to run. The last argument, /path/to/project, is read by the server itself and limits which directory it may touch. Replace it with the real absolute path of your project.
When the assistant starts, it runs the equivalent of this command and connects to the process through its standard input and output:
npx -y @modelcontextprotocol/server-filesystem /path/to/projectRunning that command yourself is a good first test. If it fails in your terminal, it will fail in the assistant too, and the terminal gives you a clearer error message.
Passing settings with `env`
Many servers need credentials or options. You pass these as environment variables in the env field. The host sets them in the server process and nowhere else.
{
"mcpServers": {
"my-api": {
"command": "python",
"args": ["server.py"],
"env": { "API_TOKEN": "<set-in-your-environment>" }
}
}
}The server reads the value with os.environ["API_TOKEN"] in Python or process.env.API_TOKEN in Node.js. This keeps secrets out of the server's source code, which is the main reason to use env.
The placeholder in the example is deliberate. A real token written into a configuration file is still a secret on disk. Do not commit a file containing one. If your assistant supports referencing a variable from your shell environment, use that. If it does not, keep the file out of version control, for example by putting a per-project config in .gitignore.
Reading the entry as a process launch
It helps to treat each entry as a precise description of a process launch. The host does not run your command through a shell the way your terminal does, so several habits from the terminal do not carry over:
- No shell expansion.
~,$HOME,*and pipes may not be expanded. Use absolute paths. - Separate arguments. Put each argument in its own string.
"args": ["--port 8080"]passes one argument containing a space, not two arguments. - A different
PATH. The host may start with a smaller environment than your terminal. A tool installed through a version manager, such asnvmorpyenv, may not be found. - A different working directory. Relative paths like
server.pyresolve against the host's idea of the current directory, which may not be your project. Use an absolute path when in doubt.
For the last two points, the fix is to give the full path to the executable:
{
"mcpServers": {
"my-api": {
"command": "/usr/local/bin/python3",
"args": ["/home/you/tools/server.py"],
"env": { "API_TOKEN": "<set-in-your-environment>" }
}
}
}To find the right path, run which python3 in the terminal (on Windows, where python).
Several servers in one file
You can register as many servers as you like. Each gets its own key and its own process.
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
},
"my-api": {
"command": "python",
"args": ["server.py"],
"env": { "API_TOKEN": "<set-in-your-environment>" }
}
}
}Names must be unique within the file. Keep them short and descriptive, because the assistant sees them, and so does the model. A name like filesystem tells the model more than server1.
Be selective. Every server you add contributes tool descriptions to the model's context, and each one is another program with access to your machine. Later chapters cover both costs.
Applying changes and checking the result
Most hosts read the configuration only at startup, or when you reload the MCP settings. After editing the file:
- Save the file. Check that it is valid JSON. A trailing comma or a missing quote makes the whole file fail to parse, which can disable every server, not just the one you edited.
- Restart the assistant, or use its reload option for MCP servers.
- Look at the server list in the assistant's interface. A healthy server shows as connected and lists its tools.
- Ask the assistant to do something only that server can do, such as listing the files in the allowed directory.
If a server does not appear, work through the common causes in order.
| Symptom | Likely cause | Fix |
|---|---|---|
| Server missing from the list | The file is in the wrong location or has invalid JSON | Confirm the path in the assistant's docs and validate the JSON |
| Server listed as failed | The command was not found, or the process exited at startup | Run the same command in a terminal and use absolute paths |
| Server connects but has no tools | The server needs a setting, such as a missing token | Check `env` and the server's documentation |
| Tools exist but calls are refused | The assistant is waiting for your approval, or the path is outside the allowed directory | Approve the call, or adjust the directory argument |
| Works in terminal, fails in assistant | Different `PATH` or working directory | Use full paths to the executable and the script |
Scope: global versus project configuration
Some assistants support more than one configuration location. A user-level file applies in every project. A project-level file applies only in that repository and can be shared with your team.
- Put general-purpose servers you want everywhere in the user-level file.
- Put servers tied to one codebase, such as a database for that project, in the project-level file.
- Never put secrets in a file you share. Use a per-user file or environment references for them.
When both files define the same name, behavior differs between assistants. Some let the project entry win and some merge or report a conflict. Avoid reusing a name across scopes unless you have checked how your assistant resolves it.
Remote servers in configuration
Everything above describes servers the host launches itself over stdio. Some servers run elsewhere and are reached over Streamable HTTP. For those, most assistants accept a URL in place of command and args, but the field names and the way authorization is configured vary more between assistants. The remote servers chapter covers these. For now, remember that the stdio form is the common default and the one every assistant supports.
Quick checklist
Before you blame the server, check these:
- The JSON parses.
- The command runs in your terminal exactly as written.
- Paths are absolute.
- Each argument is its own string.
- Required environment variables are set.
- You restarted or reloaded the assistant.
Exercise
Your assistant shows the server my-api as failed. Running python server.py in your project folder works fine in the terminal. The config entry has "command": "python" and "args": ["server.py"]. Name two likely causes and the fix for each.
Show answer
First, the host may start the process in a different working directory, so the relative path server.py is not found. Use an absolute path such as /home/you/tools/server.py. Second, the host may have a different PATH, so python resolves to a different interpreter or is not found, for example when Python comes from a version manager. Use the full path to the interpreter, found with which python3. A third possibility is a missing environment variable such as API_TOKEN, which you would add under env.
Exercise
A teammate writes "args": ["-y @modelcontextprotocol/server-filesystem /path/to/project"]. Why will this likely fail, and how should it be written?
Show answer
The whole string is passed to npx as one single argument, and no shell splits it at the spaces. It should be three separate strings: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"].