|
| 1 | +# Install GitHub MCP Server in Copilot CLI |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +1. Copilot CLI installed (see [official Copilot CLI documentation](https://docs.github.com/en/copilot/concepts/agents/about-copilot-cli)) |
| 6 | +2. [GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new) with appropriate scopes |
| 7 | +3. For local installation: [Docker](https://www.docker.com/) installed and running |
| 8 | + |
| 9 | +<details> |
| 10 | +<summary><b>Storing Your PAT Securely</b></summary> |
| 11 | +<br> |
| 12 | + |
| 13 | +For security, avoid hardcoding your token. Set your PAT as an environment variable: |
| 14 | + |
| 15 | +```bash |
| 16 | +# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.) |
| 17 | +export GITHUB_PERSONAL_ACCESS_TOKEN=your_token_here |
| 18 | +``` |
| 19 | + |
| 20 | +</details> |
| 21 | + |
| 22 | +## GitHub MCP Server Configuration |
| 23 | + |
| 24 | +You can configure the GitHub MCP server in Copilot CLI using either the interactive command or by manually editing the configuration file. |
| 25 | + |
| 26 | +### Method 1: Interactive Setup (Recommended) |
| 27 | + |
| 28 | +Use the Copilot CLI to interactively add the MCP server: |
| 29 | + |
| 30 | +``` |
| 31 | +/mcp add |
| 32 | +``` |
| 33 | + |
| 34 | +Follow the prompts to configure the GitHub MCP server. |
| 35 | + |
| 36 | +### Method 2: Manual Configuration |
| 37 | + |
| 38 | +Create or edit the configuration file `~/.copilot/mcp-config.json` and add one of the following configurations: |
| 39 | + |
| 40 | +#### Remote Server |
| 41 | + |
| 42 | +Connect to the hosted MCP server: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "mcpServers": { |
| 47 | + "github": { |
| 48 | + "url": "https://api.githubcopilot.com/mcp/", |
| 49 | + "headers": { |
| 50 | + "Authorization": "Bearer ${GITHUB_PERSONAL_ACCESS_TOKEN}" |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +#### Local Docker |
| 58 | + |
| 59 | +With Docker running, you can run the GitHub MCP server in a container: |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "mcpServers": { |
| 64 | + "github": { |
| 65 | + "command": "docker", |
| 66 | + "args": [ |
| 67 | + "run", |
| 68 | + "-i", |
| 69 | + "--rm", |
| 70 | + "-e", |
| 71 | + "GITHUB_PERSONAL_ACCESS_TOKEN", |
| 72 | + "ghcr.io/github/github-mcp-server" |
| 73 | + ], |
| 74 | + "env": { |
| 75 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}" |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +#### Binary |
| 83 | + |
| 84 | +You can download the latest binary release from the [GitHub releases page](https://github.com/github/github-mcp-server/releases) or build it from source by running `go build -o github-mcp-server ./cmd/github-mcp-server`. |
| 85 | + |
| 86 | +Then, replacing `/path/to/binary` with the actual path to your binary, configure Copilot CLI with: |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "mcpServers": { |
| 91 | + "github": { |
| 92 | + "command": "/path/to/binary", |
| 93 | + "args": ["stdio"], |
| 94 | + "env": { |
| 95 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}" |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## Verification |
| 103 | + |
| 104 | +To verify that the GitHub MCP server has been configured: |
| 105 | + |
| 106 | +1. Start or restart Copilot CLI |
| 107 | +2. The GitHub tools should be available for use in your conversations |
| 108 | + |
| 109 | +## Troubleshooting |
| 110 | + |
| 111 | +### Local Server Issues |
| 112 | + |
| 113 | +- **Docker errors**: Ensure Docker Desktop is running |
| 114 | + ```bash |
| 115 | + docker --version |
| 116 | + ``` |
| 117 | +- **Image pull failures**: Try `docker logout ghcr.io` then retry |
| 118 | +- **Docker not found**: Install Docker Desktop and ensure it's running |
| 119 | +
|
| 120 | +### Authentication Issues |
| 121 | +
|
| 122 | +- **Invalid PAT**: Verify your GitHub PAT has correct scopes: |
| 123 | + - `repo` - Repository operations |
| 124 | + - `read:packages` - Docker image access (if using Docker) |
| 125 | +- **Token expired**: Generate a new GitHub PAT |
| 126 | +
|
| 127 | +### Configuration Issues |
| 128 | +
|
| 129 | +- **Invalid JSON**: Validate your configuration: |
| 130 | + ```bash |
| 131 | + cat ~/.copilot/mcp-config.json | jq . |
| 132 | + ``` |
| 133 | +
|
| 134 | +## References |
| 135 | +
|
| 136 | +- [Copilot CLI Documentation](https://docs.github.com/en/copilot/concepts/agents/about-copilot-cli) |
0 commit comments