Observação
O Agente de codificação do Copilot está em versão prévia pública e está sujeito a alterações. Durante a versão prévia, o uso do recurso está sujeito a Termos de licença de pré-lançamento do GitHub.
Prerequisite
Before setting up an MCP server for Agente de codificação do Copilot, read Model Context Protocol (MCP) and Agente de codificação do Copilot to make sure you understand the concepts around MCP servers and Agente de codificação do Copilot.
Introduction
As a repository administrator, you can configure MCP servers for use within your repository. You do this using a JSON-formatted configuration that specifies the details of the MCP servers you want to use. You enter the JSON configuration directly into the settings for the repository on GitHub.com.
Aviso
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.
Adding an MCP configuration to your repository
Repository administrators can configure MCP servers by following these steps:
-
Em GitHub, acesse a página principal do repositório.
-
Abaixo do nome do repositório, clique em Configurações. Caso não consiga ver a guia "Configurações", selecione o menu suspenso , clique em Configurações.
-
In the "Code & automation" section of the sidebar, click Copilot then Coding agent.
-
Add your configuration in the MCP configuration section.
The following sections in this article explain how to write the JSON configuration that you need to enter here.
-
Click Save.
Your configuration will be validated to ensure proper syntax.
-
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 Agente de codificação do Copilot.
Writing a JSON configuration for MCP servers
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, sentry
), and the value is an object with the configuration for that MCP server.
{ "mcpServers": { "MCP SERVER 1": { "command": "VALUE", "args": [ VALUES ], ... }, "MCP SERVER 2": { "command": "VALUE", "args": [ VALUES ], ... }, ... } }
{
"mcpServers": {
"MCP SERVER 1": {
"command": "VALUE",
"args": [ VALUES ],
...
},
"MCP SERVER 2": {
"command": "VALUE",
"args": [ VALUES ],
...
},
...
}
}
The configuration object can contain the following keys:
Required keys for local and remote MCP servers
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 strongly recommend that you allowlist specific read-only tools, since the agent will be able to use these tools autonomously and will not ask you for approval first. You can also enable all tools by including*
in the array.type
(string
): Agente de codificação do Copilot accepts"local"
,"http"
, or"sse"
.
Local MCP specific keys
command
(string
): Required. The command to run to start the MCP server.args
(string[]
): Required. The arguments to pass to thecommand
.env
(object
): Optional. 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.
- The name of a GitHub Actions secret you have configured, beginning with
Remote MCP specific keys
url
(string
): Required. The MCP server's URL.headers
(object
): Optional. The headers to attach to requests to the server. This object should map the name of header keys to either of the following:- The name of a GitHub Actions secret you have configured, beginning with
COPILOT_MCP_
preceded by a$
- A string value
- The name of a GitHub Actions secret you have configured, beginning with
Example configurations
Example: Sentry
The Sentry MCP server gives Copilot authenticated access to exceptions recorded in Sentry.
// If you copy and paste this example, you will need to remove the comments prefixed with `//`, which are not valid JSON. { "mcpServers": { "sentry": { "type": "local", "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": "http://contoso.sentry.io", // or refer to a GitHub Actions secret with a name starting with // `COPILOT_MCP_` "SENTRY_ACCESS_TOKEN": "COPILOT_MCP_SENTRY_ACCESS_TOKEN" } } } }
// If you copy and paste this example, you will need to remove the comments prefixed with `//`, which are not valid JSON.
{
"mcpServers": {
"sentry": {
"type": "local",
"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": "http://contoso.sentry.io",
// or refer to a GitHub Actions secret with a name starting with
// `COPILOT_MCP_`
"SENTRY_ACCESS_TOKEN": "COPILOT_MCP_SENTRY_ACCESS_TOKEN"
}
}
}
}
Example: Notion
The Notion MCP server gives Copilot authenticated access to notes and other content from Notion.
// If you copy and paste this example, you will need to remove the comments prefixed with `//`, which are not valid JSON. { "mcpServers": { "notionApi": { "type": "local", "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": ["*"] } } }
// If you copy and paste this example, you will need to remove the comments prefixed with `//`, which are not valid JSON.
{
"mcpServers": {
"notionApi": {
"type": "local",
"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": ["*"]
}
}
}
Example: Azure
The Azure MCP server creates a seamless connection between Copilot and key Azure services such as Azure Cosmos DB and the Azure Storage platform.
To use the Azure MCP with Agente de codificação do Copilot, you must update the repository's copilot-setup-steps.yml
file to include an Azure login workflow step.
-
Configure OIDC in a Microsoft Entra application, trusting GitHub. See Use the Azure Login action with OpenID Connect.
-
Add a
.github/workflows/copilot-setup-steps.yml
Actions workflow file in your repository if you do not already have one. -
Add an Azure login step to the
copilot-setup-steps
workflow job.YAML on: workflow_dispatch: permissions: id-token: write contents: read jobs: copilot-setup-steps: runs-on: ubuntu-latest permissions: id-token: write contents: read environment: copilot steps: - name: Azure login uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
on: workflow_dispatch: permissions: id-token: write contents: read jobs: copilot-setup-steps: runs-on: ubuntu-latest permissions: id-token: write contents: read environment: copilot steps: - name: Azure login uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
This configuration ensures the
azure/login
action is executed when Agente de codificação do Copilot runs. -
In your repository’s Copilot environment, add secrets for your
AZURE_CLIENT_ID
,AZURE_TENANT_ID
andAZURE_SUBSCRIPTION_ID
. -
Configure the Azure MCP server by adding an
azure
object to your MCP configuration.
{ "mcpServers": { "Azure": { "type": "local", "command": "npx", "args": [ "-y", "@azure/mcp@latest", "server", "start" ], "tools": ["*"] } } }
{
"mcpServers": {
"Azure": {
"type": "local",
"command": "npx",
"args": [
"-y",
"@azure/mcp@latest",
"server",
"start"
],
"tools": ["*"]
}
}
}
Example: Cloudflare
The Cloudflare MCP server creates connections between your Cloudflare services, including processing documentation and data analysis.
{ "mcpServers": { "cloudflare": { "type": "sse", "url": "http://docs.mcp.cloudflare.com/sse", "tools": ["*"] } } }
{
"mcpServers": {
"cloudflare": {
"type": "sse",
"url": "http://docs.mcp.cloudflare.com/sse",
"tools": ["*"]
}
}
}
Reusing your MCP configuration from Visual Studio Code
If you have already configured MCP servers in VS Code, you can leverage a similar configuration for Agente de codificação do Copilot.
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 Agente de codificação do Copilot, you will need to:
- Add a
tools
key for each MCP server, specifying which tools will be available to Copilot. - If you've configured
inputs
, switch to usingenv
directly. - If you've configured an
envFile
, switch to usingenv
directly. - Update any references to
inputs
in yourargs
configuration to refer to environment variables fromenv
instead.
For more information on MCP in VS Code, see the VS Code docs.
Setting up a Copilot environment for Agente de codificação do Copilot
Some MCP servers will require keys or secrets. To leverage those servers in Agente de codificação do Copilot, 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.
-
Em GitHub, acesse a página principal do repositório.
-
Abaixo do nome do repositório, clique em Configurações. Caso não consiga ver a guia "Configurações", selecione o menu suspenso , clique em Configurações.
-
Na barra lateral esquerda, clique em Ambientes.
-
Clique em Novo ambiente.
-
Call the new environment
copilot
and click Configure environment. -
Under "Environment secrets", click Add environment secret.
-
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.
- Create an issue in the repository, then assign it to Copilot.
- Wait a few seconds, and Copilot will leave an 👀 reaction on the issue.
- Wait a few more seconds, and Copilot will create a pull request, which will appear in the issue's timeline.
- Click the created pull request in the timeline, and wait until a "Copilot started work" timeline event appears.
- Click View session to open the Agente de codificação do Copilot logs.
- Click the ellipsis button (...) at the top right of the log viewer, then click Copilot in the sidebar.
- Click the Start MCP Servers step to expand the logs.
- 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
Actions workflow file 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 and 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.
-
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 Gerenciar seus tokens de acesso pessoal.
-
Em GitHub, acesse a página principal do repositório.
-
Abaixo do nome do repositório, clique em Configurações. Caso não consiga ver a guia "Configurações", selecione o menu suspenso , clique em Configurações.
-
In the "Code & automation" section of the sidebar, click Copilot then Coding agent.
-
Add your configuration in the MCP configuration section.
-
Click Save.
-
Na barra lateral esquerda, clique em Ambientes.
-
Click the
copilot
environment. -
Under "Environment secrets", click Add environment secret.
-
Call the secret
COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKEN
, enter your personal access token in the "Value" field, then click Add secret.
For information on using the GitHub MCP server in other environments, see Using the GitHub MCP Server.