Utilize MCP Servers in VS Code's Agent Mode (Preview)

Model Context Protocol (MCP) is an open standard that enables AI models to interact with external tools and services through a unified interface. In Visual Studio Code, MCP support allows you to connect MCP-compatible servers to your agentic coding workflow. This enables tasks like file operations, accessing databases, or calling APIs in response to user requests. MCP follows a client-server architecture, where clients connect to servers and request actions on behalf of the AI model.

To use MCP servers in VS Code, you need to add them to your workspace or user settings. You can add an MCP server to your workspace by configuring it in the .vscode/mcp.json file in your workspace, or by using the 'MCP: Add Server' command from the Command Palette. VS Code supports both local standard input/output (stdio) and server-sent events (sse) for MCP server transport. Currently, servers can only provide tools to Copilot's agent mode, with the list and descriptions of tools being updated dynamically using list changed events.

Once an MCP server is added, you can use the tools it provides in agent mode. To do this, open the Chat view, select Agent mode from the dropdown, and then select the Tools button to view the list of available tools. You can also directly reference a tool in your prompt by typing # followed by the tool name. When a tool is invoked, you need to confirm the action before it is run, but you can use the Continue button dropdown options to automatically confirm the specific tool for the current session, workspace, or all future invocations.

# Use MCP servers in VS Code (Preview)

Get GitHub Copilot Free in VS Code!

Dismiss this update

Edit

## Introduction

Learn how to set up MCP servers and use tools with agent mode in Visual Studio Code.

### Note

MCP support in agent mode in VS Code is currently in preview.

## What is MCP?

Model Context Protocol (MCP) is an open standard that enables AI models to interact with external tools and services through a unified interface. In VS Code, MCP support enhances GitHub Copilot's agent mode by allowing you to connect any MCP-compatible server to your agentic coding workflow.

## MCP Architecture

### MCP clients

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

## The Model Context Protocol (MCP)

- Defines the message format for communication between clients and servers
- Includes tool discovery, invocation, and response handling

## Supported MCP Capabilities

- VS Code supports local standard input/output (stdio) and server-sent events (sse) for MCP server transport
- Servers can provide tools to Copilot's agent mode
- The list and descriptions of tools can be updated dynamically using list changed events

## Finding MCP servers

- [MCP's official server repository](https://github.com/microsoft/modelcontextprotocol) is a great starting point for reference, official, and community-contributed servers

## Add an MCP server

- Configure an MCP server in the `.vscode/mcp.json` file in your workspace
- Create a `.vscode/mcp.json` file in your workspace and select the Add Server button to add a template for a new server
- Run the MCP: Add Server command from the Command Palette and provide the server information to add a new MCP server configuration

## Configuration format

Use the following JSON configuration format to define MCP servers:

```json
{
  "servers": {
    // server name
    "server-name": {
      // server connection type
      "type": "stdio" | "sse",
      // command to start the server executable
      "command": "command",
      // array of arguments passed to the command
      "args": ["arg1", "arg2"],
      // environment variables for the server
      "env": {"variable": "value"},
      // path to an .env from which to load additional environment variables
      "envFile": "path/to/.env"
    }
  }
}

Use MCP tools in agent mode

  1. Open the Chat view (⌃⌘I (Windows, Linux Ctrl+Alt+I))
  2. Select Agent mode from the dropdown
  3. Select the Tools button to view the list of available tools
  4. Enter a prompt in the chat input box and notice how tools are automatically invoked as needed

Managing tools

  • Run the MCP: List Servers command from the Command Palette to view the list of configured MCP servers
  • When you select a server, you can start, stop, or restart the server
  • View the server configuration and server logs to diagnose issues

Command-line configuration

  • Use the VS Code command-line interface to add an MCP server to your user profile or to a workspace

Troubleshooting

  • When VS Code encounters an issue with an MCP server, it shows a error indicator in the Chat view
  • Select the error notification in the Chat view, and then select Show Output to view the server logs

Create an MCP server

FAQ

  • Can I control which MCP tools are used?
    • Yes, you have several options to control which tools are active:
    • 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