Sub topic 10
Adding tools with MCP servers
This chapter assumes you can edit and run projects in VS Code, you know the basic agent loop, and you have seen how the agent approves built-in tool calls. It covers how to add more tools to the agent with the Model Context Protocol (MCP).
What MCP is
The Model Context Protocol (MCP) is an open standard that lets an AI client talk to outside programs. An MCP server is a program that offers tools, and sometimes other resources, to the agent. VS Code is the client. The built-in tools cover search, read, edit, and terminal work. An MCP server adds tools for things the editor does not do itself, such as a database query, a ticket lookup, or browser control.
Once a server is running, its tools appear in the agent's tool list. The agent chooses them in the same loop as built-in tools: plan, call, observe, iterate.
Configure a server
A workspace server is defined in .vscode/mcp.json. This entry starts the reference filesystem server and limits it to the workspace folder:
{
"servers": {
"filesystem": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"${workspaceFolder}"
]
}
}
}The fields mean the following:
serversholds one named entry per server. The name appears in the tool list.typeofstdiomeans VS Code launches the server as a local process and talks to it over standard input and output.commandandargsare the command line that starts the process. Herenpx -ydownloads and runs the package without asking.${workspaceFolder}is replaced by the path of the open folder. The filesystem server treats it as the only directory it may access.
Servers can also be remote. A remote entry uses a URL instead of a command, for example "type": "http" with a "url" field.
Start it and use it
- Save
.vscode/mcp.json. VS Code shows start controls above the server entry in the file. - Start the server. VS Code asks you to trust it before it runs the command.
- Open the chat view in agent mode and open the tools picker. The server's tools are listed under its name.
- Turn tools on or off. Fewer enabled tools means a smaller choice for the model, so disable the ones a task does not need.
- Ask for something that needs a tool, then watch for the approval prompt.
Approval still applies
MCP tools go through the same confirmation step as other tools. You can approve a call once, for the session, or for the workspace. Read the arguments in the prompt before approving, because an MCP tool runs with whatever access the server has. A server that can write files or call an API can change things outside your editor.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Server shows an error on start | `npx` or `node` is not on the path VS Code uses | Install Node.js and restart VS Code |
| Tools do not appear | Server not started, or tools turned off in the picker | Start the server and enable its tools |
| Agent cannot reach a file | Path is outside the folder passed in `args` | Add the folder or move the file |
| Agent ignores a tool | Description is vague, or too many tools are enabled | Disable unused tools and name the tool in your prompt |
If a server fails, open its output log from the server entry. The log shows the process error, which is usually a missing command or a bad argument.
Exercise
You configured the filesystem server with ${workspaceFolder} and asked the agent to read ~/notes.txt. The call fails. Why, and what are two ways to fix it?
Show answer
The server only allows access to directories passed as arguments, and ~/notes.txt is outside the workspace folder. Either add the parent directory of the file as another entry in args, or copy the file into the workspace. Adding a directory widens access, so prefer the copy when the file is not needed long term.
Exercise
Why might you turn off most tools from a server in the tools picker even though they work?
Show answer
Each enabled tool is described to the model. Extra tools add noise, can lead the agent to pick the wrong one, and widen what a mistaken or manipulated call can do. Enable only what the task needs.