Setting up MCP Servers in Visual Studio Code

Model Context Protocol (MCP) enables AI models to interact with external tools and services through a unified interface. This guide will walk you through setting up MCP servers in Visual Studio Code to enhance your GitHub Copilot experience.

Prerequisites

  • Visual Studio Code version 1.99 or later
  • GitHub Copilot extension installed and configured

What is MCP?

MCP (Model Context Protocol) follows a client-server architecture where:

  • MCP clients (like VS Code) connect to MCP servers and request actions on behalf of the AI model
  • MCP servers provide tools that expose specific functionalities through a well-defined interface
  • The protocol defines the message format for communication between clients and servers

Enabling MCP Support

MCP support is enabled by default in VS Code 1.99+. If you need to manually enable it:

  1. Open VS Code Settings
    (⌘, on macOS)
    (Ctrl+, on Windows/Linux)
  2. Search for "chat.mcp.enabled"
  3. Ensure the setting is checked

Adding an MCP Server

There are two main ways to configure MCP servers:

1. Workspace Configuration

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

{
  "inputs": [
    {
      "type": "promptString",
      "id": "api-key",
      "description": "API Key",
      "password": true
    }
  ],
  "servers": {
    "my-server": {
      "type": "stdio",
      "command": "npx",
      "args": ["my-mcp-server"],
      "env": {
        "API_KEY": "${input:api-key}"
      }
    }
  }
}

2. User Settings Configuration

To use an MCP server across all workspaces, add it to your VS Code user settings:

  1. Open User Settings (⌘, on macOS, Ctrl+, on Windows/Linux)
  2. Search for "mcp"
  3. Add your server configuration under the "mcp.servers" setting

Security Considerations

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

🔒 Important: Never hardcode sensitive information like API keys. Use input variables or environment files instead.

Troubleshooting

If you encounter issues:

  1. Check the error indicator in the Chat view
  2. Select "Show Output" to view detailed server logs
  3. Use the "MCP: List Servers" command to check server status

Further Resources