# 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
- Open the Chat view (⌃⌘I (Windows, Linux Ctrl+Alt+I))
- Select Agent mode from the dropdown
- Select the Tools button to view the list of available tools
- 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
- MCP's official SDKs are a good place to start for developing your own 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