How to Add and Configure MCP Servers in VS Code with mcp.json

Add MCP servers in VS Code and configure workspace or user servers safely with mcp.json, input variables, trust checks, and sandbox rules.

7 min read

MCP (Model Context Protocol) servers connect AI agents in VS Code to external tools. Once configured, the agent can query databases, browse the web, and call APIs through the server's tools.

You do not need to write glue code. The MCP standard handles the connection.

This article covers adding and configuring MCP servers in Stable VS Code.

Quickstart: install a server and use it

The fastest way to add an MCP server is through the Extensions view.

The workflow and schema below follow the official VS Code MCP guide and MCP configuration reference.

Find an MCP server

Open the Extensions view (Ctrl+Shift+X / Cmd+Shift+X) and type @mcp in the search field. This filters to show only MCP servers available in the gallery.

Install it

Open the server details and review its publisher, source repository, configuration, and requested access. For this example, select the Playwright server linked from the official VS Code guide, then select Install.

To install in your workspace instead of your profile, right-click the server and select Install in Workspace. This updates .vscode/mcp.json instead of your user configuration.

Trust the server

VS Code shows a trust dialog the first time you start a server. Review the server configuration, then confirm. The server starts and VS Code discovers its tools.

Use the server's tools in chat

Open the Chat view and send a prompt that uses the server's tools. For Playwright:

Go to code.visualstudio.com, decline the cookie banner, and take a screenshot of the homepage.

The agent invokes the Playwright tools, opens a browser, and returns the screenshot. You may be asked to confirm each tool invocation.

Select Configure Tools in the chat input to see all tools the server provides. You can toggle individual tools on or off.

Configure servers in mcp.json

For more control, edit the mcp.json file directly. There are two locations:

ScopePathShared?
Workspace.vscode/mcp.jsonYes, commit to version control
User profileRun MCP: Open User ConfigurationNo, personal

VS Code provides IntelliSense for mcp.json, including auto-completion for server types, commands, and configuration fields.

Server types

TypeWhen to useExample
stdioThe server runs as a local commandnpx, python, node
httpThe server is a remote URLGitHub Copilot MCP API

Example: remote server (http)

Connect to a hosted MCP server over HTTP. This server runs on GitHub's infrastructure:

jsonjson
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp"
    }
  }
}

Example: local server (stdio)

Run a local process as an MCP server. This example uses npx to start the Playwright browser automation server:

jsonjson
{
  "servers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@microsoft/mcp-server-playwright"]
    }
  }
}

This command matches the official VS Code example. Because -y accepts the package without an install prompt, review the package source and publisher before starting it. For shared configuration, pin an approved package version.

Sensitive data: use input variables

Never hardcode API keys in mcp.json, especially in workspace files that get committed. Use input variables instead:

jsonjson
{
  "inputs": [
    { "type": "promptString", "id": "apiKey", "description": "API key", "password": true }
  ],
  "servers": {
    "my-api": {
      "command": "node",
      "args": ["server.js"],
      "env": {
        "API_KEY": "${input:apiKey}"
      }
    }
  }
}

VS Code prompts you for the value when the server starts. The value is not stored in the configuration file.

The first value is stored securely for later use. Rotate the credential at its provider if it is exposed.

Sandbox MCP servers

On macOS and Linux, you can sandbox a local MCP server. Add sandboxEnabled to the server and a top-level sandbox with file system and network rules:

jsonjson
{
  "servers": {
    "myServer": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@example/mcp-server"],
      "sandboxEnabled": true
    }
  },
  "sandbox": {
    "filesystem": { "allowWrite": ["${workspaceFolder}"] },
    "network": { "allowedDomains": ["api.example.com"] }
  }
}

With sandboxing enabled, tool calls from the server are auto-approved because they run in a controlled environment. Sandboxing is not available on Windows.

Beyond tools: resources, prompts, and apps

MCP servers can provide more than tools:

CapabilityWhat it doesHow to access
ResourcesRead-only data like files or database rows attached as contextAdd Context > MCP Resources in chat
PromptsPre-built prompt templates from the serverType /<server>.<prompt> in chat
MCP AppsInteractive UI components rendered in chatAppears inline when the server supports it

For example, a database MCP server might expose table schemas as resources and provide a /db.explain-query prompt template.

MCP prompts come from the server. For repository-owned slash commands, use /vscode/how-to-create-and-use-reusable-prompt-md-files-in-vs-code instead.

Manage servers

Manage installed servers from several places:

  • Extensions view: right-click a server in the MCP SERVERS section for start, stop, uninstall, and log options.
  • Command Palette: run MCP: List Servers, select a server, and choose an action.
  • mcp.json editor: inline code lens actions appear above each server definition.

To disable a server without uninstalling it, right-click it in the Extensions view and select Disable. Disabled servers do not start and their tools are excluded from chat.

Enable chat.mcp.autoStart (Experimental) to automatically restart servers when their configuration changes, instead of restarting them manually.

MCP server trust

When you add a server or change its configuration, VS Code asks you to confirm that you trust it. Review the server configuration before accepting. If you decline, the server does not start and its tools are unavailable.

Reset trust for all servers by running MCP: Reset Trust from the Command Palette.

Local MCP servers run arbitrary code on your machine. Only add servers from publishers you trust. Review the server's source repository before installing, especially for servers that request network access or file system write permissions.

Synchronize across devices

Enable Settings Sync and run Settings Sync: Configure. Check the MCP Servers option. Your user-level MCP server configurations now sync across devices.

MCP servers can also be included in custom agents. Learn how to create agents that use MCP tools in /vscode/how-to-create-custom-agents-in-vs-code-with-agent-md-files.

Rune AI

Rune AI

Key Insights

  • Install MCP servers from the Extensions view by searching @mcp, or write them manually in mcp.json.
  • Workspace servers go in .vscode/mcp.json (team-shared). User servers go in your profile (personal).
  • Two server types: stdio (runs a local command) and http (connects to a remote URL).
  • MCP servers provide tools, resources, prompts, and interactive apps to AI agents.
  • Enable sandboxing on macOS/Linux with sandboxEnabled: true to restrict file system and network access.
  • Use input variables for sensitive data instead of hardcoding API keys in mcp.json.
RunePowered by Rune AI

Frequently Asked Questions

What is the difference between a workspace and user MCP server?

Workspace servers go in .vscode/mcp.json and are shared with your team. User servers are in your profile and available across all workspaces.

Are MCP servers safe to install?

Local servers run code on your machine. Only install from trusted publishers. VS Code shows a trust dialog before starting. Review the source before accepting.

Can I use MCP servers when connected to a remote machine via SSH?

Yes. Define the server in remote workspace settings or run MCP: Open Remote User Configuration to run it on the remote host.

Conclusion

MCP servers extend what AI agents can do in VS Code. Install a server from the MCP gallery or configure it in mcp.json, review its source and permissions, and verify its tools in chat. Start with one trusted server that solves a specific problem.