Skip to main content

Extending Copilot coding agent with the Model Context Protocol (MCP)

Learn how to use the Model Context Protocol (MCP) to extend the capabilities of Copilot coding agent.

Hinweis

Copilot coding agent is in public preview and subject to change.

For more information about Copilot coding agent, see About assigning tasks to Copilot.

The Model Context Protocol (MCP) is an open standard that defines how applications share context with large language models (LLMs). MCP provides a standardized way to connect AI models to different data sources and tools, enabling them to work together more effectively.

You can use MCP to extend the capabilities of Copilot coding agent by connecting it to other tools and services.

The agent can use tools provided by local MCP servers. For example, the Playwright MCP server provides tools to interact with web pages and pull in additional context when executing on the requested task.

For more information on MCP, see the official MCP documentation. For information on some of the currently available MCP servers, see the MCP servers repository.

Hinweis

  • Copilot coding agent only supports tools provided by MCP servers. It does not support resources or prompts.
  • Copilot coding agent currently only supports local MCP servers. To learn more about transport types, see the official MCP documentation.

Staying safe with MCP servers

Once you've configured an MCP server, Copilot will be able to use the tools provided by the server autonomously, and will not ask for your approval before using them.

We recommend that you restrict your servers to read-only tools. You can use the tools configuration option to only expose known, safe tools to Copilot.

Setting up MCP servers in a repository

As a repository administrator, you can configure MCP servers for use within your repository. This is done via JSON configuration that specifies the details of the MCP servers you want to use.

Once MCP servers are configured for use within a repository, the tools specified in the configuration will be available to Copilot coding agent on each assigned task.

Creating your JSON MCP configuration

You configure MCP servers using a special JSON format. The JSON must contain an mcpServers object, where the key is the name of the MCP server (for example, playwright), and the value is an object with the configuration for that MCP server.

The configuration object can contain the following keys:

  • command (string): The command to run to start the MCP server.
  • args (string[]): The arguments to pass to the command.
  • tools (string[]): The tools from the MCP server to enable. You may be able to find a list of tools in the server's documentation, or in its code. We recommend that you allowlist specific tools, but you can also enable all tools by including * in the array.
  • env (object): The environment variables to pass to the server. This object should map the name of the environment variable that should be exposed to your MCP server to either of the following:
    • The name of a GitHub Actions secret you have configured, beginning with COPILOT_MCP_.
    • A string value.

Example: Playwright

The Playwright MCP server provides tools which allow Copilot to browse the internet.

JSON
{
  "mcpServers": {
    "playwright": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "--init", "mcp/playwright"],
      "tools": ["*"]
    }
  }
}

Example: Sentry

The Sentry MCP server gives Copilot authenticated access to exceptions recorded in Sentry.

JavaScript
// If you copy and paste this example, you will need to remove the comments prefixed with `//`, which are not valid JSON.
{
  "mcpServers": {
    "sentry": {
      "command": "npx",
      // We can use the $SENTRY_HOST environment variable which is passed to
      // the server because of the `env` value below.
      "args": ["@sentry/mcp-server@latest", "--host=$SENTRY_HOST"],
      "tools": ["get_issue_details", "get_issue_summary"],
      "env": {
        // We can specify an environment variable value as a string...
        "SENTRY_HOST": "https://contoso.sentry.io",
        // or refer to a GitHub Actions secret with a name starting with
        // `COPILOT_MCP_`
        "SENTRY_AUTH_TOKEN": "COPILOT_MCP_SENTRY_AUTH_TOKEN"
      }
    }
  }
}

Example: Notion

The Notion MCP server gives Copilot authenticated access to notes and other content from Notion.

JavaScript
// If you copy and paste this example, you will need to remove the comments prefixed with `//`, which are not valid JSON.
{
  "mcpServers": {
    "notionApi": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        // We can use the $NOTION_API_KEY environment variable which is passed to
        // the server because of the `env` value below.
        "OPENAPI_MCP_HEADERS={\"Authorization\": \"Bearer $NOTION_API_KEY\", \"Notion-Version\": \"2022-06-28\"}",
       "mcp/notion"
      ],
      "env": {
        // The value of the `COPILOT_MCP_NOTION_API_KEY` secret will be passed to the
        // server command as an environment variable called `NOTION_API_KEY`
        "NOTION_API_KEY": "COPILOT_MCP_NOTION_API_KEY"
      },
      "tools": ["*"]
    }
  }
}

Reusing your MCP configuration from Visual Studio Code

If you have already configured MCP servers in VS Code, you can leverage similar configuration for Copilot coding agent.

Depending on how VS Code is configured, you may be able to find your MCP settings in your repository's .vscode/mcp.json file, or in your machine's private settings.json file.

To adapt the configuration for Copilot coding agent, you will need to:

  1. Add a tools key for each MCP server, specifying the tools that should be available to Copilot.
  2. If you've configured inputs, switch to using env directly.
  3. If you've configured an envFile, switch to using env directly.
  4. Update any references to inputs in your args configuration to refer to environment variables from env instead.

For more information on MCP in VS Code, see the VS Code docs.

Adding your configuration to your repository

Repository administrators can configure MCP servers by following these steps:

  1. Navigieren Sie auf GitHub zur Hauptseite des Repositorys.

  2. Wähle unter dem Namen deines Repositorys die Option Einstellungen aus. Wenn die Registerkarte „Einstellungen“ nicht angezeigt wird, wähle im Dropdownmenü die Option Einstellungen aus.

    Screenshot eines Repositoryheaders mit den Registerkarten. Die Registerkarte „Einstellungen“ ist dunkelorange umrandet.

  3. In the "Code & automation" section of the sidebar, click Copilot then Coding agent.

  4. Add your configuration in the MCP configuration section.

  5. Click Save.

    Your configuration will be validated to ensure proper syntax.

  6. If your MCP server requires a key or secret, add a secret to your Copilot environment. Only secrets with names prefixed with COPILOT_MCP_ will be available to your MCP configuration. See Setting up a Copilot environment for Copilot coding agent.

Setting up a Copilot environment for Copilot coding agent

Some MCP servers will require keys or secrets. To leverage those servers in Copilot coding agent, you can add secrets to an environment for Copilot. This ensures the secrets are properly recognized and passed to the applicable MCP server that you have configured.

You must be a repository administrator to configure a Copilot environment for your repository.

  1. Navigieren Sie auf GitHub zur Hauptseite des Repositorys.

  2. Wähle unter dem Namen deines Repositorys die Option Einstellungen aus. Wenn die Registerkarte „Einstellungen“ nicht angezeigt wird, wähle im Dropdownmenü die Option Einstellungen aus.

    Screenshot eines Repositoryheaders mit den Registerkarten. Die Registerkarte „Einstellungen“ ist dunkelorange umrandet.

  3. Klicke auf der linken Randleiste auf Umgebungen.

  4. Klicke auf Neue Umgebung.

  5. Call the new environment copilot and click Configure environment.

  6. Under "Environment secrets", click Add environment secret.

  7. Give the secret a name beginning COPILOT_MCP_, add the secret value, then click Add secret.

Validating your MCP configuration

Once you've set up your MCP configuration, you should test it to make sure it is set up correctly.

  1. Create an issue in the repository, then assign it to Copilot.
  2. Wait a few seconds, and Copilot will leave an 👀 reaction on the issue.
  3. Wait a few more seconds, and Copilot will create a pull request, which will appear in the issue's timeline.
  4. Click the created pull request in the timeline, and wait until a "Copilot started work" timeline event appears.
  5. Click View session to open the Copilot coding agent logs.
  6. Click the ellipsis button (...) at the top right of the log viewer, then click Copilot in the sidebar.
  7. Click the Start MCP Servers step to expand the logs.
  8. If your MCP servers have been started successfully, you will see their tools listed at the bottom of the logs.

If your MCP servers require any dependencies that are not installed on the GitHub Actions runner by default, such as uv and pipx, or that need special setup steps, you may need to create a copilot-setup-steps.yml to install them. For more information, see Customizing the development environment for Copilot coding agent.

Customizing the built-in GitHub MCP server

The GitHub MCP server is enabled by default, giving Copilot access to GitHub data like issues and pull requests.

By default, the MCP server connects to GitHub with a specially scoped token that only has read-only access to the current repository.

If you want to allow Copilot to access data outside the current repository, you can give it a personal access token with wider access.

  1. Create a personal access token with the appropriate permissions. We recommend using a fine-grained personal access token, where you can limit the token's access to read-only permissions on specific repositories. For more information on personal access tokens, see Verwalten deiner persönlichen Zugriffstoken.

  2. Navigieren Sie auf GitHub zur Hauptseite des Repositorys.

  3. Wähle unter dem Namen deines Repositorys die Option Einstellungen aus. Wenn die Registerkarte „Einstellungen“ nicht angezeigt wird, wähle im Dropdownmenü die Option Einstellungen aus.

    Screenshot eines Repositoryheaders mit den Registerkarten. Die Registerkarte „Einstellungen“ ist dunkelorange umrandet.

  4. In the "Code & automation" section of the sidebar, click Copilot then Coding agent.

  5. Add your configuration in the MCP configuration section.

  6. Click Save.

  7. Klicke auf der linken Randleiste auf Umgebungen.

  8. Click the copilot environment.

  9. Under "Environment secrets", click Add environment secret.

  10. Call the secret COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKEN, enter your personal access token in the "Value" field, then click Add secret.

Best practices for using MCP servers in Copilot coding agent

  • Enabling third-party MCP servers for use may impact the performance of the agent and the quality of the outputs. Review the third-party MCP server thoroughly and ensure that it meets your organization’s requirements.

  • By default, Copilot coding agent does not have access to write MCP server tools. However, some MCP servers do contain such tools. Be sure to review the tools available in the MCP server you want to use. Update the tools field in the MCP configuration with only the necessary tooling.

  • Carefully review the configured MCP servers prior to saving the configuration to ensure the correct servers are configured for use.

Further reading