How to Add and Use an MCP Server in VS Code
Learn how to add an MCP server in VS Code, configure mcp.json, use MCP tools, manage servers, and secure API keys safely.
Overview of MCP and VS Code
If you want tools from your AI workflow to call real APIs, read files, or run dev commands, MCP is built for that. MCP stands for Model Context Protocol. It lets an MCP server expose capabilities to an MCP client, including VS Code extensions.
VS Code can act as that client through MCP-related extensions and built-in command support. After you install an MCP server, you wire it into VS Code so the server can advertise tools. Then you can invoke those tools without leaving your editor.
The process has three moving parts. First, you install the MCP server. Next, you connect it via mcp.json configuration. Finally, you use the MCP features through VS Code UI actions like the Command Palette.
To keep this guide practical, the steps below assume you already have VS Code installed and can run a local command-line process. If your MCP server is hosted remotely, the same ideas apply, but your configuration will differ slightly.

Steps to Add an MCP Server
Start by installing the right VS Code extension for MCP support. In most setups, you will use the built-in Extensions view to add MCP client support. Then you add the MCP server itself, which may be a package you install locally.
In VS Code, open the Extensions view. Search for “MCP” and install the MCP client extension that matches your workflow. If you also need built-in tool UI support, pick the extension that advertises MCP tool integration.
Then install your MCP server. Some servers ship as local Node packages. Others ship as Python tools. Some provide a ready-to-run binary.
Use this order to avoid setup loops.
- Install the VS Code extension that enables MCP support.
- Install or run the MCP server on your machine.
- Verify the server starts from the command line.
- Connect it in mcp.json configuration.
Once the server starts locally, you can confirm it responds to requests. A simple “start” command that leaves the process running is often enough. If your server requires a host and port, confirm those values before you write config.

Configuring the MCP Server
Configuration happens through an mcp.json file. VS Code reads that file from either your user profile or your workspace settings. Choose workspace config when the server is tied to a specific project. Choose user config for tools you want across many projects.
In practice, you edit mcp.json to describe how to launch the MCP server. That typically includes a command, arguments, and environment variables. Some setups also let you define an endpoint if the server is remote.
A good configuration begins with your start command. Then you add the least set of variables needed for the server to work. Keep it predictable, because you will use it again when you troubleshoot.
Here is a compact example structure. Your exact keys depend on the extension you installed, but the idea stays the same.
| Section | What to include | Example |
|---|---|---|
| command | The executable to start the server | node |
| args | Arguments to the server | path/to/server.js |
| env | Variables your server needs | API_KEY, BASE_URL |
| cwd | Optional working directory | ./workspace |
If you are unsure which keys your extension expects, check the extension documentation for mcp.json schema. Treat that doc as the source of truth. Small naming differences can break the connection.
Using MCP Server Tools
After VS Code detects the MCP server, you can start using its exposed tools. These tools can cover API access, file reads and writes, and command execution in a dev environment. The tool names and arguments come from what the server advertises.
To use an MCP tool, open VS Code’s Command Palette. The palette is the fastest way to access MCP actions. Look for entries that mention MCP or “Model Context Protocol.” Then choose the tool invocation flow provided by your extension.
In many setups, the UI will guide you to pick a tool. It may ask for required arguments, then it runs the tool and returns results to the chat panel or output area. If your tool supports optional parameters, you can tune them without changing code.
Here are examples of what tool usage feels like in a dev workflow.
- Access an API: provide an endpoint name and parameters, then get normalized output.
- Manage files: read project files, create a small patch, or list directory contents.
- Run commands: execute lint, tests, or build steps through a controlled tool wrapper.
When a tool fails, treat the error message as a hint about configuration or missing inputs. In particular, argument mismatches often mean your config or prompt needs the exact expected parameter names.
If you want a repeatable flow, keep your tool arguments consistent. Store common values as environment variables in mcp.json configuration when possible.
Managing MCP Servers in VS Code
VS Code provides multiple ways to manage MCP servers. Many extensions include commands for refreshing server discovery. Some also show status indicators or logs in an output panel.
Use the Command Palette to find management actions. Common options include reload, restart, or list tools. When you edit mcp.json, you often need to reload the MCP connection. Do that immediately after changes so you do not chase stale behavior.
If you use multiple servers, map them clearly. Use workspace config for project-specific servers. Use user config for tools you reuse across projects. That way, you avoid collisions and confusing tool lists.
When you add a new server, confirm tool discovery end-to-end. If the server runs but tools do not appear, check that the server actually advertises the tools you expect. Some servers enable tools only when certain features are turned on.
- After edits, reload MCP connections from the Command Palette.
- Prefer workspace config for per-project servers.
- Keep tool names stable so prompts and workflows stay valid.
Also remember that extensions can differ. One extension may show tool listings directly. Another may rely on chat-driven discovery. Either way, your job stays the same: confirm the server is reachable, then confirm its tools are exposed.
Security Considerations
Security is not optional when your MCP server can call external services. The server can be powerful because it can access APIs and run commands. Your biggest risk is usually secret leakage, especially API keys.
Use API key management that avoids hardcoding secrets in shared files. Put secrets in environment variables referenced by mcp.json configuration. Then ensure your secrets are not committed to git. If the extension reads environment variables at runtime, you can rotate keys without changing tool logic.
Use least-privilege credentials. If you have separate API keys for read-only and write access, pick the read-only one for file and query tools. For command tools, restrict what the server can run. Some servers include allowlists for commands or paths.
Also watch for logs. Output panels can capture request details. If your server returns errors that include request headers, you may leak secrets. Prefer redacted error output in your server code if that option exists.
| Risk | Mitigation | Where to apply |
|---|---|---|
| Secret leakage | Store keys in env vars, not in repo files | mcp.json env |
| Over-broad access | Use scoped keys and tool allowlists | server config |
| Accidental command execution | Restrict commands and working dirs | server permissions |
Finally, treat tool execution as code execution. If you ask the tool to run a command, you should assume it can modify your workspace. Use reviews and safe defaults when possible.
Troubleshooting Common Issues
Most MCP setup problems come from three areas. The server fails to start, VS Code cannot find mcp.json configuration, or the tool schema does not match your expectations.
If the server does not connect, start by checking the server start command outside VS Code. Confirm it runs from the same environment your VS Code uses. Then verify the server path, working directory, and environment variables.
If tools do not appear, confirm you placed mcp.json in the right location. It can be in either the user profile or workspace settings. Put it in one place first. Then move to the other if you need different behavior.
If you see errors during tool runs, validate your tool arguments. Many servers require exact parameter names. A mismatch can look like a “tool not found” or “missing argument” error.
When you troubleshoot, use this sequence.
- Restart the MCP server from the command line.
- Reload MCP connections in VS Code via Command Palette.
- Check server logs for startup and schema errors.
- Confirm mcp.json location and environment variables.
- Run one tool with the smallest input first.
For deeper validation, check what tools the server claims to expose. Then test the same tool in the same way the UI expects. That narrows the problem quickly to either server advertisement or client invocation.
If you keep hitting the same error, update only one variable per run. It makes it easier to identify what changed. Most fixes are one-line config tweaks once you know which area is failing.
Frequently asked questions
- How do I add an MCP server in VS Code?
- Install an MCP client extension, install the MCP server, then add its launch details in mcp.json. Reload MCP connections so VS Code discovers the server tools.
- Where should I put my mcp.json configuration in VS Code?
- You can place mcp.json in your user profile for global tools or in workspace settings for project-specific tools. Use one location first to avoid confusion.
- How do I use an MCP server in VS Code after it is configured?
- Open the Command Palette and choose the MCP tool action. Select a tool and provide the required arguments when prompted.
- What tools can an MCP server expose in VS Code?
- MCP servers commonly expose tools for API calls, file operations, and running commands in a dev environment. The exact tools depend on the server you install.
- How should I handle API keys for an MCP server?
- Put secrets in environment variables referenced by mcp.json. Avoid committing keys to git and use least-privilege credentials.
- Why do MCP tools not show up in VS Code after setup?
- Most causes are a server that fails to start, the wrong mcp.json location, or a tool schema mismatch. Reload MCP connections and check server logs first.