Skip to main content

Using the GitHub MCP Server

Learn how to use the GitHub Model Context Protocol (MCP) server to extend Copilot Chat.

Observação

The GitHub MCP server is currently in versão prévia pública and subject to change.

Sobre o servidor de MCP do GitHub

O servidor de MCP do GitHub é um servidor de MCP (Protocolo de Contexto de Modelo) fornecido e mantido pelo GitHub. O MCP permite que você integre recursos de IA a outras ferramentas e serviços, aprimorando sua experiência de desenvolvimento fornecendo assistência de IA com reconhecimento de contexto.

Para obter mais informações sobre o MCP, confira a documentação oficial do MCP.

Você pode acessar o servidor de MCP do GitHub remotamente por meio do Visual Studio Code ou outros editores que dão suporte ao MCP remoto; ou você pode executá-lo localmente em qualquer editor compatível com MCP, permitindo escolher entre a conveniência de uma solução hospedada ou a personalização de uma configuração auto-hospedada.

Se você quiser utilizar o servidor de MCP remoto do GitHub, poderá fazer isso em algumas etapas, sem nenhuma configuração local. Isso é particularmente útil para usuários que desejam aproveitar rapidamente as funcionalidades de IA do GitHub sem a sobrecarga de gerenciar um servidor de MCP local.

Executar o servidor de MCP do GitHub localmente requer um pouco mais de configuração, mas permite uma maior personalização e controle sobre suas interações de IA.

O servidor de MCP do GitHub pode ser usado para:

  • Automatizar e simplificar tarefas relacionadas ao código.
  • Conectar ferramentas de terceiros (como Cursor, Windsurf ou integrações futuras) para aproveitar o contexto e as funcionalidades de IA do GitHub.
  • Habilitar fluxos de trabalho baseados em nuvem que funcionam em qualquer dispositivo, sem configuração local.

Disponibilidade

Atualmente, há amplo suporte para servidores de MCP locais em clientes como Visual Studio Code, IDEs do JetBrains, XCode e outros.

O suporte para servidores de MCP remotos está se ampliando, com editores como Visual Studio Code (com OAuth ou PAT), Visual Studio (somente PAT), Windsurf (somente PAT) e Cursor (somente PAT) já fornecendo essa funcionalidade.

Para descobrir se seu editor preferencial dá suporte a servidores de MCP remotos, verifique a documentação do editor específico.

Pré-requisitos

  • Uma conta do GitHub.
  • Visual Studio Code ou outro editor compatível com MCP.

Setting up the GitHub MCP server in Visual Studio Code

The instructions below guide you through setting up the GitHub MCP server in Visual Studio Code. Other MCP-compatible editors may have similar steps, but the exact process may vary.

You can choose to set up the GitHub MCP server either remotely or locally, depending on your needs and preferences. You can also configure your GitHub MCP server for either:

  • Um repositório específico. Isso permite que você compartilhe servidores de MCP com qualquer pessoa que abra o projeto no Visual Studio Code. Para fazer isso, crie um arquivo .vscode/mcp.json na raiz do repositório.
  • Sua instância pessoal do Visual Studio Code. Você será a única pessoa que terá acesso a servidores MCP configurados. Para fazer isso, adicione a configuração ao arquivo settings.json no Visual Studio Code. Os servidores de MCP configurados dessa forma ficarão disponíveis em todos os workspaces.

The remote GitHub MCP server uses one-click OAuth authentication by default, but you can also manually configure it to use a personal access token (PAT) for authentication. If you use OAuth, the MCP server will have the same access as your personal account. If you use a PAT, the MCP server will have access to the scopes granted by the PAT.

Observação

If you are an Enterprise Managed User with PAT restrictions, you won't be able to use PAT authentication. If you have OAuth access policy restrictions, you will need the OAuth apps for each client to be enabled (except Visual Studio Code and Visual Studio).

Remote MCP server configuration with OAuth

Observação

The remote GitHub MCP server is not available to GitHub Enterprise Server users. If you are using GitHub Enterprise Server, you can install the GitHub MCP server locally. See Local MCP server setup.

You do not need to create a PAT or install any additional software to use the remote GitHub MCP server with OAuth. You can set it up directly in Visual Studio Code. You can also install individual toolsets, either in read-only mode or with full read/write access, allowing you to tailor the server's capabilities to your specific needs. For more information, see Tool configuration.

  1. In Visual Studio Code, open the command palette by pressing Ctrl+Shift+P (Windows/Linux) / Command+Shift+P (Mac).

  2. Type: mcp: add server and then press Enter.

  3. From the list, select HTTP (HTTP or Server-Sent Events).

  4. In the Server URL field, enter http://api.githubcopilot.com/mcp/, and press Enter.

  5. Under Enter Server ID, press Enter to use the default server ID, or enter a custom server ID.

  6. Under Choose where to save the configuration, select where you want to save the MCP server configuration.

    • Visual Studio Code will open and add the configuration to the selected file in the editor, or create a new file if it doesn't exist.
  7. In the Visual Studio Code popup, to authorize the MCP server with OAuth, click Allow and select your personal account from the list.

Remote MCP server configuration with PAT

To configure the remote GitHub MCP server with a PAT, ensure you have created a PAT with the necessary scopes for the access you want to grant to the MCP server. For more information, see Gerenciar seus tokens de acesso pessoal.

You will need to manually configure the MCP server in Visual Studio Code to use the PAT for authorization.

  1. In Visual Studio Code, open the command palette by pressing Ctrl+Shift+P (Windows/Linux) / Command+Shift+P (Mac).

  2. Type: mcp: add server and then press Enter.

  3. From the list, select HTTP (HTTP or Server-Sent Events).

  4. In the Server URL field, enter http://api.githubcopilot.com/mcp/, and press Enter.

  5. Under Enter Server ID, press Enter to use the default server ID, or enter a custom server ID.

  6. Under Choose where to save the configuration, select where you want to save the MCP server configuration.

    • Visual Studio Code will open and add the configuration to the selected file in the editor, or create a new file if it doesn't exist.
  7. In the Visual Studio Code popup, to decline OAuth authorization, click Cancel.

  8. You will need to manually edit the configuration file to use a PAT. In the configuration file, at the end of the url line, add the following:

    JSON
        ,
          "headers": {
            "Authorization": "Bearer ${input:github_token}"
          }
        },
      },
      "inputs": [
        {
          "id": "github_token",
          "type": "promptString",
          "description": "GitHub Personal Access Token",
          "password": true
        }
      ]
    }
    
  9. A "Restart" button will appear in the file. Click "Restart" to restart the MCP server with the new configuration.

    Screenshot of the MCP server restart button in the configuration file. The "Restart" button is outlined in dark orange.

  10. In the command palette, you will see a prompt to enter your GitHub token. Enter the PAT you created earlier, and press Enter.

    • The MCP server will now be configured to use the PAT for authorization.

Local MCP server setup

Observação

If you are a GitHub Enterprise Server user, and your enterprise has PAT restrictions enabled, you can only use API endpoints for scopes that are allowed by your enterprise's PAT policy. If all API endpoints are restricted, you will not be able to use the MCP server. If you are unsure about your enterprise's PAT policy, contact your enterprise administrator for more information.

Using the GitHub MCP server locally requires you to have Docker installed and running on your machine. Additionally, you can only authenticate with a PAT, as OAuth is not supported for local MCP servers.

  1. Ensure you have Docker installed and running on your machine. See Docker installation instructions.

  2. Create a PAT with (at least) the read:packages and repo scopes. For more information, see Gerenciar seus tokens de acesso pessoal.

  3. Decide whether you want to configure the MCP server for a specific repository or for your personal instance of Visual Studio Code.

    • If you are using a specific repository, open the .vscode/mcp.json file in Visual Studio Code, and add the following configuration:
    JSON
       {
        "inputs": [
          {
            "type": "promptString",
            "id": "github_token",
            "description": "GitHub Personal Access Token",
            "password": true
          }
        ],
        "servers": {
          "github": {
            "command": "docker",
            "args": [
              "run",
              "-i",
              "--rm",
              "-e",
              "GITHUB_PERSONAL_ACCESS_TOKEN",
              "ghcr.io/github/github-mcp-server"
            ],
            "env": {
              "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
            }
          }
        }
      }
    
    • If you are using your personal instance of Visual Studio Code, open your settings.json file in Visual Studio Code:
      • Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
      • Type Preferences: Open Settings (JSON) and select it.
      • Add the following configuration:
    JSON
    {
      "mcp": {
        "inputs": [
          {
            "type": "promptString",
            "id": "github_token",
            "description": "GitHub Personal Access Token",
            "password": true
          }
        ],
        "servers": {
          "github": {
            "command": "docker",
            "args": [
              "run",
              "-i",
              "--rm",
              "-e",
              "GITHUB_PERSONAL_ACCESS_TOKEN",
              "ghcr.io/github/github-mcp-server"
            ],
            "env": {
              "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
            }
          }
        }
      }
    }
    
  4. Save the file.

  5. In the command palette, you will see a prompt to enter your GitHub token. Enter the PAT you created earlier, and press Enter.

    • The MCP server will now be configured to run locally with the PAT for authorization.

Tool configuration

The GitHub MCP server supports installing individual toolsets, either in read-only mode or with full read/write access, allowing you to tailor the server's capabilities to your specific needs. For one-click installation options of each toolset, see the GitHub MCP server repository.

Using the GitHub MCP server in Visual Studio Code

The GitHub MCP server enables you to perform a wide range of actions on GitHub, via Copilot Chat in Visual Studio Code.

  1. Abra o Copilot Chat clicando no ícone na barra de título do Visual Studio Code.
  2. Na caixa do Copilot Chat, selecione Agent no menu pop-up.
  3. To see the available actions, in the Copilot Chat box, click the Select tools icon.
    • In the Tools dropdown, under MCP Server:GitHub, you will see a list of available actions.
  4. In the Copilot Chat box, type a command or question related to the action you want to perform, and press Enter.
    • For example, you can ask the GitHub MCP server to create a new issue, list pull requests, or retrieve repository information.
  5. The GitHub MCP server will process your request and provide a response in the chat interface.
    • In the Copilot Chat box, you may be asked to give additional permissions or provide more information to complete the action.
  6. Follow the prompts to complete the action.

Solução de problemas

Se você tiver problemas ao usar o servidor de MCP do GitHub, há algumas etapas comuns de solução de problemas que você pode executar.

Problemas de autorização

Se você estiver tendo problemas para autorizar o servidor de MCP, verifique se:

  • Você está conectado ao GitHub no IDE que você escolheu.

Se você estiver autenticando com um PAT (personal access token), verifique se:

  • Seu PAT do GitHub é válido e tem os escopos necessários para as ações que você deseja executar.
  • Você inseriu o PAT correto quando solicitado no Visual Studio Code.

Problemas no modo do agente do Copilot

Se você estiver tendo problemas com o modo de agente do Copilot Chat, verifique se:

  • Você selecionou o agente correto na caixa do Copilot Chat.
  • Você configurou o servidor de MCP corretamente no Visual Studio Code.
  • Você tem as permissões necessárias para as ações que está tentando executar.

Dicas gerais

Se você estiver enfrentando outros problemas com o servidor de MCP do GitHub, aqui estão algumas dicas gerais para ajudar a solucionar problemas:

  • Verifique os logs de saída do servidor de MCP em busca de mensagens de erro.
  • Se você estiver executando o servidor de MCP localmente, verifique se o ambiente local está configurado corretamente para executar contêineres do Docker.
  • Tente reiniciar o servidor de MCP ou o IDE.

Further reading