15 min read
Beginner
Client Integration

VS Code and Copilot MCP Setup

Configure MCP servers in Visual Studio Code with GitHub Copilot for AI-powered editor workflows

MCPgee Team

MCP Expert

VS Code 1.99+ installedGitHub Copilot extension installed and activeAn MCP server to connect (TypeScript or Python)Basic familiarity with VS Code settings

VS Code and Copilot MCP Setup

Introduction

Visual Studio Code has built-in support for MCP servers through GitHub Copilot's agent mode. This means you can connect any MCP server to your editor and use AI-powered tools directly in your development workflow, from querying databases to managing files to running custom operations.

This tutorial walks you through configuring MCP servers in VS Code, using them with Copilot Chat, and building productive AI-assisted workflows. For background on MCP, see our What is MCP tutorial.

Prerequisites

Before starting, ensure you have:

Configuring MCP Servers in VS Code

Method 1: Workspace Settings (Recommended)

Create a .vscode/mcp.json file in your project root:

json
{
  "servers": {
    "my-file-server": {
      "command": "node",
      "args": ["./mcp-servers/file-server.js"],
      "env": {
        "WORKSPACE_DIR": "${workspaceFolder}"
      }
    },
    "python-tools": {
      "command": "python",
      "args": ["./mcp-servers/tools_server.py"],
      "env": {
        "DATA_PATH": "${workspaceFolder}/data"
      }
    }
  }
}

This approach keeps MCP configuration scoped to your project, making it easy to share with team members.

Method 2: User Settings

For servers you want available across all projects, add them to your VS Code user settings (settings.json):

json
{
  "mcp": {
    "servers": {
      "global-utils": {
        "command": "npx",
        "args": ["@modelcontextprotocol/server-filesystem", "/home/user/documents"]
      }
    }
  }
}

Method 3: Command Palette

  1. Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
  2. Search for "MCP: Add Server"
  3. Follow the prompts to configure your server

Connecting to Different Server Types

Local stdio Servers

Most MCP servers use stdio transport for local communication:

json
{
  "servers": {
    "filesystem": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-filesystem", "/path/to/directory"]
    },
    "database": {
      "command": "python",
      "args": ["/path/to/db_server.py"],
      "env": {
        "DATABASE_URL": "postgresql://localhost/mydb"
      }
    }
  }
}

Remote Streamable HTTP Servers

For remote MCP servers deployed with Streamable HTTP transport:

json
{
  "servers": {
    "remote-tools": {
      "url": "https://your-mcp-server.example.com/mcp",
      "headers": {
        "Authorization": "Bearer your-token-here"
      }
    }
  }
}

Docker-Based Servers

Run MCP servers in Docker containers:

json
{
  "servers": {
    "docker-server": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "my-mcp-server:latest"]
    }
  }
}

Using MCP Tools with Copilot Chat

Agent Mode

Once configured, MCP tools are available in Copilot Chat's Agent mode:

  1. Open Copilot Chat (Ctrl+Shift+I / Cmd+Shift+I)
  2. Switch to Agent mode using the dropdown at the top
  3. Ask questions that involve your MCP tools

For example, if you have a database MCP server connected:

plaintext
User: Query the users table and show me the top 10 most active users
Copilot: [Uses the database MCP tool to run the query and display results]

Tool Approval

By default, VS Code asks for approval before executing MCP tools. You can:

  • Approve once for the current session
  • Always allow for trusted tools
  • Deny if the operation looks wrong

This aligns with MCP security best practices.

Viewing Available Tools

To see what MCP tools are available:

  1. Open the Command Palette
  2. Search for "MCP: List Servers"
  3. View connected servers and their available tools

Practical Workflows

Workflow 1: Database-Assisted Development

json
{
  "servers": {
    "postgres": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-postgres", "postgresql://localhost/devdb"]
    }
  }
}

Now you can ask Copilot:

  • "Show me the schema of the orders table"
  • "Write a migration to add an email column to users"
  • "Find all orders placed in the last 24 hours"

Workflow 2: File System Operations

json
{
  "servers": {
    "files": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-filesystem", "${workspaceFolder}"]
    }
  }
}

Ask Copilot:

  • "Find all TODO comments in the project"
  • "List all TypeScript files that import React"
  • "Show me the project structure"

Workflow 3: Custom Project Tools

Build a project-specific MCP server with tools tailored to your workflow:

python
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("project-tools")

@mcp.tool()
def run_tests(test_path: str = "") -> str:
    """Run project tests.

    Args:
        test_path: Specific test file or directory to run
    """
    import subprocess
    cmd = ["pytest", test_path] if test_path else ["pytest"]
    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.stdout + result.stderr

@mcp.tool()
def check_lint(file_path: str = "") -> str:
    """Run linter on project files.

    Args:
        file_path: Specific file to lint
    """
    import subprocess
    cmd = ["ruff", "check", file_path] if file_path else ["ruff", "check", "."]
    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.stdout + result.stderr

if __name__ == "__main__":
    mcp.run()

Then configure in .vscode/mcp.json:

json
{
  "servers": {
    "project-tools": {
      "command": "python",
      "args": ["${workspaceFolder}/tools/project_server.py"]
    }
  }
}

Managing Multiple Servers

Server Lifecycle

VS Code manages MCP server lifecycle automatically:

  • Starts servers when needed (on first tool request or at workspace open)
  • Restarts servers if they crash
  • Stops servers when you close the workspace

Monitoring Servers

Check server status in the Output panel:

  1. Open Output panel (Ctrl+Shift+U)
  2. Select "MCP" from the dropdown
  3. View connection logs and errors

Disabling Servers Temporarily

To disable a server without removing its configuration:

json
{
  "servers": {
    "my-server": {
      "command": "node",
      "args": ["./server.js"],
      "disabled": true
    }
  }
}

Team Collaboration

Sharing MCP Configurations

Since .vscode/mcp.json is a workspace file, you can commit it to your repository:

bash
git add .vscode/mcp.json
git commit -m "Add MCP server configuration for team"

Use VS Code variables for portability:

  • ${workspaceFolder} for project-relative paths
  • Environment variables for secrets (never commit tokens)

Environment-Specific Configuration

Use .env files for secrets and environment-specific values:

json
{
  "servers": {
    "api-server": {
      "command": "node",
      "args": ["./api-server.js"],
      "env": {
        "API_KEY": "${env:MY_API_KEY}"
      }
    }
  }
}

Troubleshooting VS Code MCP

Server Not Starting

  1. Check the Output panel for error messages
  2. Verify the command exists and is in your PATH
  3. Test the server manually in a terminal first
  4. Ensure all environment variables are set

Tools Not Appearing in Copilot

  1. Confirm you are in Agent mode in Copilot Chat
  2. Check that the server is running (MCP: List Servers)
  3. Restart the MCP server from the Command Palette
  4. Verify your VS Code version is 1.99+

Performance Issues

If MCP tools are slow:

Conclusion

VS Code's native MCP support through GitHub Copilot makes it easy to enhance your editor with AI-powered tools. By configuring MCP servers in your workspace, you can create powerful development workflows that combine Copilot's intelligence with custom tools tailored to your project.

For more on building MCP servers to use with VS Code, check out our first MCP server tutorial or explore the full clients directory for detailed VS Code integration documentation.

Code Examples

Workspace MCP Configuration (.vscode/mcp.json)json
{
  "servers": {
    "filesystem": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-filesystem", "${workspaceFolder}"]
    },
    "custom-tools": {
      "command": "python",
      "args": ["${workspaceFolder}/tools/server.py"],
      "env": {
        "PROJECT_ROOT": "${workspaceFolder}"
      }
    }
  }
}
Remote Server Configurationjson
{
  "servers": {
    "remote-api": {
      "url": "https://mcp-api.example.com/mcp",
      "headers": {
        "Authorization": "Bearer ${env:MCP_TOKEN}"
      }
    }
  }
}
Project-Specific MCP Server (Python)python
from mcp.server.fastmcp import FastMCP
import subprocess

mcp = FastMCP("project-tools")

@mcp.tool()
def run_tests(path: str = "") -> str:
    """Run project test suite.

    Args:
        path: Specific test file or directory
    """
    cmd = ["pytest", path, "-v"] if path else ["pytest", "-v"]
    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.stdout + result.stderr

@mcp.tool()
def git_status() -> str:
    """Get current git status."""
    result = subprocess.run(["git", "status", "--short"], capture_output=True, text=True)
    return result.stdout or "Working tree clean"

if __name__ == "__main__":
    mcp.run()

Key Takeaways

  • VS Code 1.99+ has built-in MCP support through GitHub Copilot agent mode
  • Configure servers via .vscode/mcp.json for project-scoped setup or user settings for global access
  • MCP tools work in Copilot Chat Agent mode with approval-based execution
  • Use VS Code variables like \${workspaceFolder} for portable configurations
  • Team configurations can be shared by committing .vscode/mcp.json to version control

Troubleshooting

MCP tools do not appear in Copilot Chat

Make sure you are using Agent mode in Copilot Chat, not the default chat mode. Also verify your VS Code is version 1.99 or later, and check MCP: List Servers to confirm the server is connected.

Server fails to start with command not found

The MCP server command must be in your PATH. For npx commands, ensure Node.js is installed. For Python servers, verify the Python binary path. You can use absolute paths in the command field if needed.

Environment variables not being passed to the server

Check that you are using the correct syntax in mcp.json. For system environment variables, use the \${env:VARIABLE_NAME} syntax. Make sure the variables are actually set in your shell environment.

Next Steps

  • Build a custom MCP server for your project workflow
  • Explore remote MCP server connections for team tools
  • Add database and API MCP servers to your editor
  • Learn about security best practices for MCP in editors

Was this helpful?

Share tutorial:

Stay Updated with MCP Insights

Join 5,000+ developers and get weekly insights on MCP development, new server releases, and implementation strategies delivered to your inbox.

We respect your privacy. Unsubscribe at any time.

MCPgee Team

We write in-depth guides, tutorials, and reviews to help developers get the most out of the Model Context Protocol ecosystem.

Frequently Asked Questions

Explore MCP Servers

Browse our directory of 33,000+ MCP servers. Find the perfect tools for your AI-powered workflows.