Edit

Share via


Use MCP servers

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, MCP support enhances GitHub Copilot agent mode by allowing you to connect any MCP-compatible server to your agentic coding workflow.

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

Prerequisites

How MCP and Visual Studio extend the GitHub Copilot agent

MCP support in Visual Studio works as follows:

  • MCP clients, such as Visual Studio, 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 protocol defines the message format for communication between clients and servers, including tool discovery, invocation, and response handling.

For example, an MCP server for a file system might provide tools for reading, writing, or searching files and directories. The official GitHub 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. Visual Studio supports both configurations.

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

Configuration example with a GitHub MCP server

The following walkthrough requires version 17.14.9 or later.

  1. Create a new file: <SOLUTIONDIR>\.mcp.json or %USERPROFILE%\.mcp.json. We recommend that you use Visual Studio to edit this file so that its JSON schema is automatically applied.

  2. Paste the following contents into the .mcp.json file:

    {
      "servers": {
        "github": {
          "url": "https://api.githubcopilot.com/mcp/"
        }
      }
    }
    
  3. Save the file. Then activate the CodeLens information that appears over the new server to authenticate to this server through a GitHub account.

  4. In Visual Studio, select the Ask arrow in the GitHub Copilot Chat window, and then select Agent.

    Screenshot that shows the Copilot agent mode selector.

  5. Select the tools that you want to use; for example, List issues.

    Screenshot that shows MCP GitHub tools.

  6. Try a sample prompt: List issues assigned to me on GitHub.

  7. Copilot asks for permission to use a tool that the MCP server made available to it. Select Allow with the scope that you want to proceed with.

    Screenshot that shows confirmation options for agent tools.

Supported MCP capabilities

Visual Studio supports the following MCP capabilities:

  • The options for MCP server transport are local standard input/output (stdio), server-sent events (sse), and streamable HTTP (http).
  • Of the features (tools, prompts, resources, sampling), Visual Studio now supports:
    • Tools: Execute actions and operations through Copilot agent mode
    • Prompts: Reusable prompt templates that you can invoke with parameters
    • Resources: Access external data and context through URI-based resources
    • Sampling: Enhanced AI model interactions with your tools and services
  • Visual Studio provides servers with the current solution folders by using roots (specification).
  • For MCP authorization, Visual Studio supports authentication for remote servers with any OAuth provider.

Finding MCP servers

The official MCP server repository is a great starting point for reference, official, and community-contributed servers that showcase the versatility of MCP. You can explore servers for various functionalities, such as file system operations, database interactions, and web services.

MCP is 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.

Example MCP servers

Try out some other popular MCP servers in Visual Studio with one-click:

  • Install Awesome MCP in Visual Studio – Discover and install custom prompts and instructions for GitHub Copilot.
  • Install MarkItDown MCP in Visual Studio – Convert various file formats (PDF, Word, Excel, images, audio) to Markdown.
  • Install DuckDB Server in Visual Studio – Query and analyze data in DuckDB databases locally and in the cloud.
  • Install MongoDB MCP in Visual Studio – Database operations and management. Execute queries, manage collections, aggregation pipelines, and document operations.
  • Install HuggingFace MCP in Visual Studio – Access models, datasets, and Spaces on the Hugging Face Hub.

Options for adding an MCP server

You have multiple options to add an MCP server in Visual Studio.

Install from the web

With the latest servicing release of version 17.14, Visual Studio supports direct installation of MCP servers. You can select the Install button on an MCP server to automatically add it to your Visual Studio instance.


Add an Install button for an MCP server
  1. Write your MCP server configuration in JSON.

    Here's an HTTP/SSE server example:

    {"name":"My Server","type":"http","url":"https://example.com/mcp/"} 
    

    Here's a stdio server example:

    {"name":"My Server","type":"stdio","command":"python","args":["-m","my_mcp.server"]}
    

    Required fields are:

    Field Description
    name Friendly name for your server
    type Server connection type, such as http or stdio
    url URL of the server, required for http
    command Command to start the server executable, required for stdio
    args Array of arguments passed to the command, required for stdio
  2. URL-encode the JSON. You can use an online encoder or your browser console.

    Here's a browser console example:

    encodeURIComponent('{"name":"My Server","type":"http","url":"https://example.com/mcp/"}')
    
  3. Insert the URL-encoded JSON into the MCP URI format to form a Visual Studio installation link. Use this format:

    vsweb+mcp:/install?<ENCODED_JSON>
    
  4. Add the Markdown badge to your GitHub repository or documents. For example:

    [![Install MCP Server in Visual Studio](https://img.shields.io/badge/Install%20in%20Visual%20Studio-blue?logo=visualstudio)](vsweb+mcp:/install?<ENCODED_JSON>)
    

When a user selects the badge, Visual Studio opens (or prompts you to open it). The MCP installation dialog appears, prefilled with your server details.


Add from chat view

With Visual Studio version 17.14.13 or later, you can add an MCP Server from the chat view in Visual Studio.

To add an MCP server from chat view:

  1. Select the green plus (+) button in the tool picker in the chat window.

    Screenshot the plus button in tool picker of Visual Studio chat to add MCP server.

  2. Specify the server name and connection details, such as the URL for HTTP servers or the command and arguments for stdio servers.

    Screenshot that shows adding an MCP server from the chat view.

Create a file to manage configuration of MCP servers

If you don't already have an mcp.json file, create one in any of the supported locations based on your repository, user, or editor requirements.

To add an MCP server, locate the server's JSON configuration online. For example, find it in the GitHub repository for MCP servers. Then paste it into your mcp.json file.

File locations for automatic discovery of MCP configuration

Visual Studio also checks for MCP configurations that other development environments set up. MCP server configurations are read from the following directories, in the following order:

  1. %USERPROFILE%\.mcp.json
    Serves as a global MCP server configuration for a specific user. Adding an MCP server here makes it load for all Visual Studio solutions.
  2. <SOLUTIONDIR>\.vs\mcp.json
    Specific to Visual Studio and loads the specified MCP servers only for a specific user, for the specified solution.
  3. <SOLUTIONDIR>\.mcp.json
    Works well if you're looking for an MCP configuration that you can track in source control for a repository.
  4. <SOLUTIONDIR>\.vscode\mcp.json
    Scoped to the repository/solution and typically not source controlled.
  5. <SOLUTIONDIR>\.cursor\mcp.json
    Scoped to the repository/solution and typically not source controlled.

Some of these locations require .mcp.json, whereas others require mcp.json.

MCP configuration format

You can define both remote (URL and credentials) and local (command-line invocation) servers.

It's common to invoke tools via package managers; for example, npx -y @azure/mcp@latest or docker run ... mcp/github. Visual Studio respects whatever command you specify, so you can pin versions or pass flags as needed.

The format must follow the MCP specification. For example, it must include an array of server objects, each with name, command or url, and transport.

Editing MCP configuration

With an existing mcp.json file, add the file location to Solution Items in Solution Explorer, if you're checking the file into your version control system.

When the file is saved with valid syntax, the GitHub Copilot agent restarts and reloads the configured servers.

Screenshot that shows adding the MCP configuration file location to Solution Items.

Tool lifecycle

As soon as a server is discovered or added:

  • Visual Studio initializes the server by performing a handshake and querying the tool list.
  • Visual Studio subscribes to the MCP event notifications/tools/list_changed.
  • When that event fires, Visual Studio resets any prior acceptances or permissions on tools (to prevent rug-pull attacks), re-fetches the tool list, and updates the count/UI live.
  • When the server is successfully enabled, tools become available to the agent. The tools are disabled by default and must be manually enabled.
  • If a server is removed, Visual Studio immediately stops its process and withdraws all its tools from the UI.
  • If you edit a server definition, Visual Studio terminates and restarts it, and then re-queries.

Management of tool approvals

When a tool is invoked, Copilot requests confirmation to run the tool. The reason is that tools might run locally on your machine and perform actions that modify files or data.

After a tool invocation, on the chat pane, use the Allow dropdown options. You can automatically confirm the specific tool for the current session, the current solution, or all future invocations.

Screenshot that shows managing agent tool approvals.

You can reset tool confirmation selections in the Tools > Options pane, under the All Settings > GitHub > Copilot > Tools section.

Screenshot that shows tool configuration settings for GitHub Copilot.

You can reset tool confirmation selections in the Tools > Options dialog, under the GitHub > Copilot section in the Tools group.

Screenshot that shows tool configuration settings.

Manage authorization

Visual Studio now supports authentication for remote servers with any OAuth provider, in accordance with the MCP authorization specification. This support is in addition to integration with the Visual Studio keychain.

To manage authentication for an MCP server:

  1. In the .mcp.json file, select Manage Authentication for that server from CodeLens.

  2. Provide credentials for the necessary OAuth provider for that server in the browser pop-up dialog.

MCP prompts and prompt templates

MCP servers can provide reusable prompt templates that help you interact more effectively with language models. These prompts are tailored to specific tasks and can include customizable arguments.

Use MCP prompts

To reference prompts from an MCP server:

  1. Select the + Add Reference in chat.
  2. Select Prompts > MCP prompts.
  3. Choose a prompt and select Insert Prompt.

Some prompts include arguments that you can customize before inserting them into chat. These are called prompt templates.

Example: The GitHub MCP server provides prompts for analyzing pull requests, generating commit messages, and reviewing code changes.

Install GitHub MCP in Visual Studio

MCP resources and resource templates

MCP resources provide context to language models, such as files, database schemas, or application-specific data. Each resource has a unique URI that you can reference in chat.

Use MCP resources

Reference MCP resources in Copilot chat using a hashtag (#) followed by the resource URI.

For resources with arguments (resource templates):

  1. Select + Add Reference in chat.
  2. Select MCP resources.
  3. Choose your resource, fill in any required arguments, and select Add Resource.

Example: The Azure DevOps MCP server exposes work items resources, sprint information, and team capacity data for project planning tasks.

Install in Azure DevOps MCP Visual Studio

Example: The Figma MCP server provides access to design component resources, style guides, and design specifications.

Install Figma MCP in Visual Studio

MCP sampling

Sampling allows MCP servers to make LLM calls on your behalf, enabling more complex, multi-step operations. Visual Studio automatically supports sampling if your MCP server provides it.

When Copilot needs to make a sampling call, you'll see a confirmation dialog. Review the details and approve before the action proceeds, ensuring you maintain control over automated operations.

Example: The Playwright MCP server uses sampling to generate test scenarios based on your application's DOM structure and user flows.

Install Playwright MCP in Visual Studio

Frequently asked questions

As an administrator, how do I control use of MCP servers in agent mode for Visual Studio users?

The GitHub policy settings on the GitHub Copilot dashboard for administrators govern agent mode and MCP usage in Visual Studio. If the administrator turns off this setting, users under that subscription can't use agent mode or connect to MCP servers in Visual Studio.

For more information, see Managing policies and features for GitHub Copilot in your enterprise.