Sub topic 10
Adding tools with MCP servers
This chapter assumes you can run the agent in VS Code, know how built-in tools and tool approval work, and can read JSON and run commands in a terminal. You do not need to have written a server before.
What MCP is and why it exists
The built-in tools cover searching, reading, editing, and running terminal commands. They know nothing about your issue tracker, your database, or your internal documentation. The Model Context Protocol (MCP) is an open protocol that lets you add tools like these without changing the editor.
MCP splits the work between two roles:
- A client is the application that hosts the model. In this tutorial the client is the agent in your editor.
- A server is a separate program that offers capabilities. It can be a local process or a remote service.
A server describes what it offers, and the client shows those descriptions to the model. When the model decides to use one, the client sends the call to the server and returns the result. From the agent's point of view, an MCP tool is another tool in the same loop you studied earlier: plan, call, observe, iterate.
Because the protocol is shared, one server can work in VS Code, JetBrains IDEs, Cursor, and other clients that support MCP. Only the configuration file differs between them.
What a server can provide
MCP defines several kinds of capability. Agent mode uses tools most, but you will see the others in configuration and in the tool picker.
| Capability | What it is | Example |
|---|---|---|
| Tools | Functions the model can call, each with a name, a description, and an input schema | `read_file`, `create_issue` |
| Resources | Data the server exposes for use as context | A database schema, a log file |
| Prompts | Reusable prompt templates the server offers | A "summarize this pull request" template |
Support for resources and prompts varies by client and version. Check your editor's documentation before you depend on them. Tools are supported most widely.
Transports: local and remote servers
A transport is the channel the client and server use to talk. Two are common.
- stdio: The editor starts the server as a child process and exchanges messages over its standard input and output. This suits local tools. The server runs with your user account's permissions.
- HTTP: The editor connects to a URL. This suits hosted services, and it usually involves authentication.
Remote servers are often listed with a url field instead of command and args. Exact field names and supported transport names depend on the editor version, so confirm them in its documentation.
Configuring a server in VS Code
VS Code reads MCP configuration from a .vscode/mcp.json file in the workspace. You can also add servers to your user profile, which makes them available in every workspace. Use the workspace file when the whole team should share the setup, and commit it to version control.
This example starts the reference filesystem server and limits it to the workspace folder:
{
"servers": {
"filesystem": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"${workspaceFolder}"
]
}
}
}Each field has a job:
serversis a map. The key (filesystem) is the name you will see in the editor.typeselects the transport.stdiomeans a local child process.commandandargsare the program and its arguments. Herenpx -ydownloads and runs the package without asking for confirmation.${workspaceFolder}is a variable that VS Code replaces with the path of the open folder. The filesystem server treats the directories you pass as the only places it may read and write.
That last argument matters for safety. The server only receives access to the directories you list. If you passed your home directory instead, the agent could read and change files far outside the project.
Starting a server and choosing tools
After you save the file, VS Code shows a control to start the server. When it starts, the editor asks the server for its tool list. A few things follow from this:
- The tools appear in the agent's tool picker, usually grouped under the server name.
- You can turn individual tools on or off. Enable only what the task needs.
- Each tool call goes through the same approval prompt as a built-in tool. You can allow a single call, or allow a tool for the session or workspace, depending on your editor's options.
Turning off unneeded tools is not only about safety. Every enabled tool's name, description, and schema is sent to the model. Many tools use context space and can make the model choose less accurately. Editors also cap the number of tools a request can include, so a long list may be truncated. A small, well-chosen set works better than everything switched on.
Passing secrets without committing them
Many servers need a token. Do not write a token directly into a file you commit. VS Code supports input variables: the file declares a prompt, and the editor asks you for the value when the server first starts, then stores it securely.
{
"inputs": [
{
"type": "promptString",
"id": "github-token",
"description": "GitHub personal access token",
"password": true
}
],
"servers": {
"github": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github-token}"
}
}
}
}The env map sets environment variables for the server process. The ${input:github-token} reference points to the entry in inputs with the matching id. The file you commit then contains no secret.
Give the token the smallest scope that does the job. A read-only token cannot be misused to delete anything, however the agent behaves.
Trust and risk
An MCP server is code that runs on your machine, or a service that receives data from your session. Adding one is a trust decision.
- Local servers run with your permissions. A stdio server started by
npxcan read your files and use your network. Treat the package like any dependency: check the publisher, and pin a version instead of taking the latest on every start. - Tool descriptions are text the model reads. A malicious or compromised server can write descriptions that try to steer the model. Likewise, the data a tool returns, such as a web page or an issue body, can contain instructions aimed at the model. This is called prompt injection. Approval prompts are your defense, so read what a call will do before you allow it.
- Data leaves the machine. Arguments you send to a remote server, and its results, may be logged by its operator. Do not point the agent at a service you would not give that data to.
- Shared configuration is a supply-chain path. A
.vscode/mcp.jsonin a cloned repository can name a command that your editor will run. Review the file before you start any server from a repository you did not write. VS Code asks you to confirm trust before it starts a server, so do not click through that prompt automatically.
Troubleshooting a server that does not work
Most failures fall into a few groups. Work through them in order.
- The server never starts. Run the same
commandandargsin a terminal. Ifnpxis not found, Node.js is not installed or is not on thePATHyour editor sees. Editors started from a launcher can have a shorterPATHthan your shell. - It starts and then stops. Open the editor's MCP output log. Look for an error on the server's standard error stream, such as a missing environment variable or a bad path argument.
- It runs but shows no tools. The server may have failed during its tool listing. Restart it, then check the log. Also confirm the tools are enabled in the picker.
- The model does not use the tool. The tool description may be vague, or the prompt may not suggest the tool is relevant. Name the capability in your prompt, for example "use the filesystem tools to list the files in
docs/". - A call fails with a permission or path error. The server is probably working as designed. A filesystem server refuses paths outside the directories you gave it. Widen the allowed directory only if the task really needs it.
- Authentication errors. The token is missing, expired, or lacks the scope the tool needs. Reenter the input value and check the scope.
A useful habit is to test a new server with one harmless, read-only request before you rely on it in a larger task.
Choosing when to add a server
Not every need calls for MCP. Use this as a rough guide.
| Situation | Better choice |
|---|---|
| The agent needs your build and test commands | Instructions file plus the terminal tool |
| The agent needs data from a system outside the repo | An MCP server for that system |
| The agent needs a capability you can script in one command | A script in the repo that the agent runs in the terminal |
| You need the same capability in several editors | An MCP server, since the protocol is shared |
A server also adds a process to keep running, a dependency to trust, and tool descriptions to carry in context. If a short script run through the terminal tool does the job, that is usually simpler.
Exercise
You add the filesystem server to .vscode/mcp.json with "${workspaceFolder}" as its only directory argument. The agent then tries to read ~/.ssh/config and the call fails. Is the server broken? Explain what to check, and what you should and should not change.
Show answer
The server is working as intended. It only serves the directories passed as arguments, so a path outside the workspace is rejected. You should check the log only to confirm the error is a path-restriction error. You should not add your home directory or ~/.ssh to the arguments, because that would give the agent, and any instructions injected into its context, access to private keys. If a task truly needs an outside file, copy that file into the workspace or allow only the one specific directory it lives in.
Exercise
A teammate wants to share a GitHub MCP server setup. Their mcp.json has the personal access token pasted into the env block. Rewrite the relevant part so the file can be committed, and name one way to limit the damage if the token is misused.
Show answer
Declare an input and reference it: add an inputs entry with "type": "promptString", "id": "github-token", and "password": true, then set "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github-token}" in env. Revoke the token that was pasted into the file, because it may already be in history. To limit damage, create the token with the smallest scope needed, for example read-only access to a single repository.