Try to extend agent mode in VS Code!

Use MCP servers in VS Code

Model Context Protocol (MCP) is an open standard that lets AI models use external tools and services through a unified interface. In VS Code, MCP servers add tools for tasks like file operations, databases, or interacting with external APIs.

This article guides you through setting up MCP servers and using tools with agent mode in Visual Studio Code.

How does MCP work?

MCP follows a client-server architecture:

  • MCP clients (like VS Code) connect to MCP servers and request actions on behalf of the AI model
  • MCP servers provide one or more tools that expose specific functionalities through a well-defined interface
  • Model Context Protocol defines the message format for communication between clients and servers, including tool discovery, invocation, and response handling

For example, a file system MCP server might provide tools for reading, writing, or searching files and directories. GitHub's MCP server offers tools to list repositories, create pull requests, or manage issues. MCP servers can run locally on your machine or be hosted remotely, and VS Code supports both configurations.

By standardizing this interaction, MCP eliminates the need for custom integrations between each AI model and each tool. This allows you to extend your AI assistant's capabilities by simply adding new MCP servers to your workspace. Learn more about the Model Context Protocol specification.

Supported MCP capabilities in VS Code

VS Code supports the following MCP capabilities:

  • MCP Server transport: local standard input/output (stdio), HTTP Stream (http), and server-sent events (sse, legacy support).
  • MCP features: tools, prompts, resources, elicitation, sampling, and authentication.
  • VS Code provides servers with the current workspace folders using roots (spec).
Note

MCP support in VS Code is generally available starting from VS Code 1.102.

Prerequisites

Enable MCP support in VS Code

You can enable or disable MCP support in VS Code with the chat.mcp.enabled setting. By default, MCP support is enabled.

Centrally manage MCP support

You have two options to centrally manage MCP support in your organization:

Add an MCP server

Caution

MCP servers can run arbitrary code on your machine. Only add servers from trusted sources, and review the publisher and server configuration before starting it. VS Code prompts you to confirm that you trust the MCP server when you start an MCP server for the first time.

You have multiple options to add an MCP server in VS Code:

Install an MCP server directly from the web

Websites can provide a link to directly install an MCP server in VS Code, making it easy to add servers without manually configuring them.

For example, to install an MCP server from the curated list of MCP servers:

  1. Open the Extensions view and enter @mcp in the search bar.

  2. Select Browse MCP Servers to open the list of MCP servers in your browser. Alternatively, run the MCP: Browse Servers command from the Command Palette.

  3. Select Install on any MCP server, which opens VS Code and shows the server details page.

  4. Select Install on the server details page to add the MCP server to your VS Code instance.

    The MCP server is installed in your user configuration and can be used in any workspace.

Add an MCP server to your workspace

To configure an MCP server for a specific workspace, you can create a .vscode/mcp.json file in your workspace folder. Project team members can then use the same server configuration.

Important

Make sure to avoid hardcoding sensitive information like API keys and other credentials by using input variables or environment files.

To add an MCP server to your workspace:

  1. Create a .vscode/mcp.json file in your workspace.

  2. Select the Add Server button to add a template for a new server. VS Code provides IntelliSense for the MCP server configuration file.

    The following example shows how to configure the GitHub remote MCP server. Learn more about the MCP configuration format in VS Code.

    {
      "servers": {
        "github-mcp": {
          "type": "http",
          "url": "https://api.githubcopilot.com/mcp"
        }
      }
    }
    
  3. Alternatively, run the MCP: Add Server command from the Command Palette, choose the type of MCP server to add and provide the server information. Next, select Workspace Settings to create the .vscode/mcp.json file in your workspace if it doesn't already exist.

Add an MCP server to your user configuration

To configure an MCP server for all your workspaces, you can add the server configuration to your user configuration. This allows you to reuse the same server configuration across multiple projects.

To add an MCP to your user configuration, run the MCP: Open User Configuration command, which opens the mcp.json file in your user profile. If the file does not exist, VS Code creates it for you.

Alternatively, use the MCP: Add Server command from the Command Palette, provide the server information, and then select Global to add the server configuration to your profile.

When you use multiple VS Code profiles, this allows you to switch between different MCP server configurations based on your active profile. For example, the Playwright MCP server could be configured in a web development profile, but not in a Python development profile.

MCP servers are executed wherever they're configured. If you're connected to a remote and want a server to run on the remote machine, it should be defined in your remote settings (MCP: Open Remote User Configuration) or in the workspace's settings. MCP servers defined in your user settings are always executed locally.

Add an MCP server to a dev container

MCP servers can be configured in Dev Containers through the devcontainer.json file. This allows you to include MCP server configurations as part of your containerized development environment.

To configure MCP servers in a Dev Container, add the server configuration to the customizations.vscode.mcp section:

{
  "image": "mcr.microsoft.com/devcontainers/typescript-node:latest",
  "customizations": {
    "vscode": {
      "mcp": {
        "servers": {
          "playwright": {
            "command": "npx",
            "args": ["-y", "@microsoft/mcp-server-playwright"]
          }
        }
      }
    }
  }
}

When the Dev Container is created, VS Code automatically writes the MCP server configurations to the remote mcp.json file, making them available in your containerized development environment.

Automatically discover MCP servers

VS Code can automatically detect and reuse MCP servers that you defined in other tools, such as Claude Desktop.

Enable autodiscovery with the chat.mcp.discovery.enabled setting.

When VS Code starts the MCP server for the first time, it discovers the server's capabilities and tools. You can then use these tools in agent mode. VS Code caches the list of tools for an MCP server. To clear the cached tools, use the MCP: Reset Cached Tools command in the Command Palette.

View installed MCP servers

To view and manage the list of configured MCP servers:

  • Run the MCP: Show Installed Servers command from the Command Palette to open the MCP Servers view.

    Alternatively, directly open the MCP SERVERS - INSTALLED section in the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)).

    Screenshot showing the MCP servers in the Extensions view.

  • Run the MCP: List Servers command from the Command Palette to view the list of installed MCP servers.

Use MCP tools in agent mode

Once you have added an MCP server, you can use the tools it provides in agent mode.

To use MCP tools in agent mode:

  1. Open the Chat view (⌃⌘I (Windows, Linux Ctrl+Alt+I)), and select Agent mode from the dropdown.

    Agent mode dropdown option

  2. Select the Tools button to view the list of available tools.

    Optionally, select or deselect the tools you want to use. You can search tools by typing in the search box.

    MCP tools list

    Important

    A chat request can have a maximum of 128 tools enabled at a time. If you have more than 128 tools selected, reduce the number of tools by deselecting some tools in the tools picker, or ensure that virtual tools are enabled (github.copilot.chat.virtualTools.threshold).

  3. Enter a prompt in the chat input box and notice how tools are automatically invoked as needed. For example, install the GitHub MCP server and ask "List my GitHub issues".

    Screenshot of the Chat view, showing an MCP tool invocation in agent mode.

    Tip

    You can also directly reference a tool in your prompt by typing # followed by the tool name. You can do this in all chat modes (ask, edit, and agent mode).

  4. When prompted, carefully review the tool invocation details before confirming.

    Caution

    MCP tools might run locally on your machine and could perform actions that modify files or data. Always ensure you understand the implications of the tool's actions.

    Use the Continue button dropdown options to automatically confirm the specific tool for the current session, workspace, or all future invocations.

    MCP Tool Confirmation

  5. Optionally, verify and edit the tool input parameters before running the tool.

    MCP Tool Input Parameters

Use MCP resources

In addition to tools, MCP servers can also provide resources that you can use as context in your chat prompts. For example, a file system MCP server might provide access to files and directories, or a database MCP server might provide access to database tables.

To add a resource from an MCP server to your chat prompt:

  1. In the Chat view, select Add Context > MCP Resources

  2. Select a resource type from the list and provide optional resource input parameters.

    Screenshot of the MCP resource Quick Pick, showing resource types provided by the GitHub MCP server.

To view the list of available resources for an MCP server, use the MCP: Browse Resources command or use the MCP: List Servers > Browse Resources command to view resources for a specific server.

MCP tools can return resources as part of their response. You can view or save these resources to your workspace by selecting Save or by dragging and dropping the resource to the Explorer view.

Use MCP prompts

MCP servers can provide preconfigured prompts for common tasks, so you don't have to type an elaborate chat prompt. You can directly invoke these prompts in the chat input box by typing / followed by the prompt name, formatted as mcp.servername.promptname. Optionally, the prompt might ask you for extra input parameters.

Screenshot of the Chat view, showing an MCP prompt invocation and a dialog asking for additional input parameters.

Use MCP elicitations

MCP servers can request extra input from you through elicitations. When an MCP server needs more information to complete a task, it can prompt you for specific details, such as confirmations, configuration values, or other parameters required for the operation.

When an MCP server sends an elicitation request, VS Code presents you with a dialog or input field where you can provide the requested information. This allows MCP servers to gather necessary data dynamically without requiring all configuration to be set up in advance.

As you add more MCP servers, the list of tools can become long. This can make it tedious to manage individual tools, for example when you want to define a reusable prompt file or a custom chat mode.

To help you manage tools, you can group related tools into a tool set. A tool set is a collection of individual tools that you can refer to as a single entity. A tool set can contain built-in tools, MCP tools, or tools provided by extensions.

Learn more about how to create and use tool sets in VS Code.

Manage MCP servers

You can perform various actions on the installed MCP servers, such as starting or stopping a server, viewing the server logs, uninstalling the server, and more.

To perform these actions on an MCP server, use either of these options:

  • Right-click on the server in the MCP SERVERS - INSTALLED section or select the gear icon

    Screenshot showing the MCP servers in the Extensions view.

  • Open the mcp.json configuration file and access the actions inline in the editor (lenses)

    MCP server configuration with lenses to manage server.

    Use the MCP: Open User Configuration or MCP: Open Workspace Folder Configuration commands to access the MCP server configuration.

  • Run the MCP: List Servers command from the Command Palette and select a server

    Screenshot showing the actions for an MCP server in the Command Palette.

Automatically start MCP servers

When you add an MCP server or change its configuration, VS Code needs to (re)start the server to discover the tools it provides.

You can configure VS Code to automatically restart the MCP server when configuration changes are detected by using the chat.mcp.autostart setting (Experimental).

Alternatively, manually restart the MCP server from the Chat view, or by selecting the restart action from the MCP server list.

Screenshot showing the Refresh button in the Chat view.

Command-line configuration

You can also use the VS Code command-line interface to add an MCP server to your user profile or to a workspace.

To add an MCP server to your user profile, use the --add-mcp command line option, and provide the JSON server configuration in the form {\"name\":\"server-name\",\"command\":...}.

code --add-mcp "{\"name\":\"my-server\",\"command\": \"uvx\",\"args\": [\"mcp-server-fetch\"]}"

URL handler

VS Code also includes a URL handler that you can use to install an MCP server. To form the URL, construct an obj object in the same format as you would provide to --add-mcp, and then create the link by using the following logic:

// For Insiders, use `vscode-insiders` instead of `code`
const link = `vscode:mcp/install?${encodeURIComponent(JSON.stringify(obj))}`;

This link can be used in a browser, or opened on the command line, for example via xdg-open $LINK on Linux.

Find MCP servers

MCP is still a relatively new standard, and the ecosystem is rapidly evolving. As more developers adopt MCP, you can expect to see an increasing number of servers and tools available for integration with your projects.

The curated list of MCP servers on the VS Code website is a great starting point. Choose from different categories and directly install MCP servers in VS Code.

MCP's official server repository provides official, and community-contributed servers that showcase MCP's versatility. You can explore servers for various functionalities, such as file system operations, database interactions, and web services.

VS Code extensions can also contribute MCP servers and configure them as part of the extension's installation process. Check the Visual Studio Marketplace for extensions that provide MCP server support.

MCP server trust

MCP servers can run arbitrary code on your machine. Only add servers from trusted sources, and review the publisher and server configuration before starting it.

When you add an MCP server to your workspace or change its configuration, you need to confirm that you trust the server and its capabilities before starting it. VS Code shows a dialog to confirm that you trust the server when you start a server for the first time. Select the link to MCP server in the dialog to review the MCP server configuration in a separate window.

Screenshot showing the MCP server trust prompt.

If you don't trust the server, it is not started, and chat requests continue without using the tools provided by the server.

You can reset trust for your MCP servers by running the MCP: Reset Trust command from the Command Palette.

Note

If you start the MCP server directly from the mcp.json file, you are not prompted to trust the server configuration.

Synchronize MCP servers across devices

With Settings Sync enabled, you can synchronize settings and configurations across devices, including MCP server configurations. This allows you to maintain a consistent development environment and access the same MCP servers on all your devices.

To enable MCP server synchronization with Settings Sync, run the Settings Sync: Configure command from the Command Palette, and ensure that MCP Servers is included in the list of synchronized configurations.

Configuration format

MCP servers are configured using a JSON file (mcp.json) that defines two main sections: server definitions and optional input variables for sensitive data.

MCP servers can connect using different transport methods. Choose the appropriate configuration based on how your server communicates.

Configuration structure

The configuration file has two main sections:

  • "servers": {} - Contains the list of MCP servers and their configurations
  • "inputs": [] - Optional placeholders for sensitive information like API keys

You can use predefined variables in the server configuration, for example to refer to the workspace folder (${workspaceFolder}).

Standard I/O (stdio) servers

Use this configuration for servers that communicate through standard input and output streams. This is the most common type for locally-run MCP servers.

Field Required Description Examples
type Yes Server connection type "stdio"
command Yes Command to start the server executable. Must be available on your system path or contain its full path. "npx", "node", "python", "docker"
args No Array of arguments passed to the command ["server.py", "--port", "3000"]
env No Environment variables for the server {"API_KEY": "${input:api-key}"}
envFile No Path to an environment file to load more variables "${workspaceFolder}/.env"
Note

When using Docker with stdio servers, don't use the detach option (-d). The server must run in the foreground to communicate with VS Code.

Example local server configuration

This example shows the minimal configuration for a basic, local MCP server using npx:

{
  "servers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    }
  }
}

HTTP and Server-Sent Events (SSE) servers

Use this configuration for servers that communicate over HTTP. VS Code first tries the HTTP Stream transport and falls back to SSE if HTTP is not supported.

Field Required Description Examples
type Yes Server connection type "http", "sse"
url Yes URL of the server "http://localhost:3000", "https://api.example.com/mcp"
headers No HTTP headers for authentication or configuration {"Authorization": "Bearer ${input:api-token}"}
Example remote server configuration

This example shows the minimal configuration for a remote MCP server without authentication:

{
  "servers": {
    "context7": {
      "type": "http",
      "url": "https://mcp.context7.com/mcp"
    }
  }
}

Input variables for sensitive data

Input variables let you define placeholders for configuration values, avoiding the need to hardcode sensitive information like API keys or passwords directly in the server configuration.

When you reference an input variable using ${input:variable-id}, VS Code prompts you for the value when the server starts for the first time. The value is then securely stored for subsequent use. Learn more about input variables in VS Code.

Input variable properties:

Field Required Description Example
type Yes Type of input prompt "promptString"
id Yes Unique identifier to reference in server config "api-key", "database-url"
description Yes User-friendly prompt text "GitHub Personal Access Token"
password No Hide typed input (default: false) true for API keys and passwords
Example server configuration with input variables

This example configures a local server that requires an API key:

{
  "inputs": [
    {
      "type": "promptString",
      "id": "perplexity-key",
      "description": "Perplexity API Key",
      "password": true
    }
  ],
  "servers": {
    "perplexity": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "server-perplexity-ask"],
      "env": {
        "PERPLEXITY_API_KEY": "${input:perplexity-key}"
      }
    }
  }
}

Server naming conventions

When defining MCP servers, follow these naming conventions for the server name:

  • Use camelCase for the server name, such as "uiTesting" or "githubIntegration"
  • Avoid using whitespace or special characters
  • Use a unique name for each server to avoid conflicts
  • Use a descriptive name that reflects the server's functionality or brand, such as "github" or "database"

Troubleshoot and debug MCP servers

MCP output log

When VS Code encounters an issue with an MCP server, it shows an error indicator in the Chat view.

MCP Server Error

Select the error notification in the Chat view, and then select the Show Output option to view the server logs. Alternatively, run MCP: List Servers from the Command Palette, select the server, and then choose Show Output.

MCP Server Error Output

Debug an MCP server

You can enable development mode for MCP servers by adding a dev key to the MCP server configuration. This is an object with two properties:

  • watch: A file glob pattern to watch for files change that will restart the MCP server.
  • debug: Enables you to set up a debugger with the MCP server.
{
  "servers": {
    "gistpad": {
      "command": "node",
      "args": ["build/index.js"],
     "dev": {
       "watch": "build/**/*.js",
       "debug": { "type": "node" }
     },
Note

We currently only support debugging Node.js and Python servers launched with node and python respectively.

Frequently asked questions

Can I control which MCP tools are used?

  • Select the Tools button in the Chat view when in agent mode, and toggle specific tools on/off as needed.
  • Add specific tools to your prompt by using the Add Context button or by typing #.
  • For more advanced control, you can use .github/copilot-instructions.md to fine-tune tool usage.

The MCP server is not starting when using Docker

Verify that the command arguments are correct and that the container is not running in detached mode (-d option). You can also check the MCP server output for any error messages (see Troubleshooting).

I'm getting an error that says "Cannot have more than 128 tools per request."

A chat request can have a maximum of 128 tools enabled at a time due to model constraints. If you have more than 128 tools selected, reduce the number of tools by deselecting some tools or whole servers in the tools picker in the Chat view, or ensure that virtual tools are enabled (github.copilot.chat.virtualTools.threshold).

Screenshot showing the Chat view, highlighting the Tools icon in the chat input and showing the tools Quick Pick where you can select which tools are active.