|
| 1 | +# Install GitHub MCP Server in fx |
| 2 | + |
| 3 | +[fx](https://fx.sh) is an open source coding agent for the terminal. It reads MCP servers from `~/.fx/mcp.json` under an `mcp` key. For general setup information (prerequisites, Docker installation, security best practices), see the [Installation Guides README](./README.md). |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. fx installed (`curl -fsSL https://fx.sh/setup.sh | bash` or see [fx installation docs](https://fx.sh/docs/getting-started/installation)) |
| 8 | +2. [GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new) with appropriate scopes |
| 9 | +3. For local installation: [Docker](https://www.docker.com/) installed and running |
| 10 | + |
| 11 | +> [!IMPORTANT] |
| 12 | +> fx rejects a literal `Authorization` header in `mcp.json` so credentials do not become ordinary profile data. Use `bearer_token_env` instead, which reads the token from an environment variable at connection time. |
| 13 | +
|
| 14 | +## Remote Server (Recommended) |
| 15 | + |
| 16 | +Uses GitHub's hosted server at `https://api.githubcopilot.com/mcp/`. Add it from your terminal: |
| 17 | + |
| 18 | +```sh |
| 19 | +fx mcp add --transport http github https://api.githubcopilot.com/mcp/ |
| 20 | +``` |
| 21 | + |
| 22 | +Then open `~/.fx/mcp.json` and add `bearer_token_env` to the saved entry: |
| 23 | + |
| 24 | +```json |
| 25 | +{ |
| 26 | + "mcp": { |
| 27 | + "github": { |
| 28 | + "type": "http", |
| 29 | + "url": "https://api.githubcopilot.com/mcp/", |
| 30 | + "bearer_token_env": "GITHUB_PERSONAL_ACCESS_TOKEN" |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Export the token in the shell that starts fx: |
| 37 | + |
| 38 | +```sh |
| 39 | +export GITHUB_PERSONAL_ACCESS_TOKEN=your_pat_here |
| 40 | +``` |
| 41 | + |
| 42 | +fx sends the value as a bearer token on every request. The token is never written to `mcp.json`. |
| 43 | + |
| 44 | +### Limiting toolsets |
| 45 | + |
| 46 | +The GitHub MCP server registers many tools. To keep prompts within your model's context window, filter server side with the `X-MCP-Toolsets` header, which fx sends through `headers`: |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "mcp": { |
| 51 | + "github": { |
| 52 | + "type": "http", |
| 53 | + "url": "https://api.githubcopilot.com/mcp/", |
| 54 | + "bearer_token_env": "GITHUB_PERSONAL_ACCESS_TOKEN", |
| 55 | + "headers": { |
| 56 | + "X-MCP-Toolsets": "repos,issues,pull_requests" |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +See the [Server Configuration Guide](../server-configuration.md) and the [main README's toolsets section](../../README.md#available-toolsets). |
| 64 | + |
| 65 | +## Local Server (Docker) |
| 66 | + |
| 67 | +The local GitHub MCP server runs via Docker and requires Docker Desktop (or another Docker runtime) to be installed and running. |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "mcp": { |
| 72 | + "github": { |
| 73 | + "type": "local", |
| 74 | + "command": [ |
| 75 | + "docker", "run", "-i", "--rm", |
| 76 | + "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", |
| 77 | + "ghcr.io/github/github-mcp-server" |
| 78 | + ], |
| 79 | + "environment": { |
| 80 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "your_pat_here" |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +To log in with OAuth instead of a token, publish a fixed callback port to loopback: |
| 88 | + |
| 89 | +```json |
| 90 | +{ |
| 91 | + "mcp": { |
| 92 | + "github": { |
| 93 | + "type": "local", |
| 94 | + "command": [ |
| 95 | + "docker", "run", "-i", "--rm", |
| 96 | + "-p", "127.0.0.1:8085:8085", |
| 97 | + "-e", "GITHUB_OAUTH_CALLBACK_PORT", |
| 98 | + "ghcr.io/github/github-mcp-server" |
| 99 | + ], |
| 100 | + "environment": { |
| 101 | + "GITHUB_OAUTH_CALLBACK_PORT": "8085" |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +See **[Local Server OAuth Login](../oauth-login.md)** for the native-binary flow, headless fallback, GitHub Enterprise, and bringing your own OAuth or GitHub App. |
| 109 | + |
| 110 | +The first launch of a container or package can exceed the default startup timeout. Raise it for that server with `"startup_timeout_ms": 60000`. |
| 111 | + |
| 112 | +## Verify Installation |
| 113 | + |
| 114 | +1. Connect and inspect the server without opening a session: |
| 115 | + |
| 116 | + ```sh |
| 117 | + fx mcp list --connect |
| 118 | + ``` |
| 119 | + |
| 120 | + The `github` entry should report `state=ready` along with its negotiated name and tool count. |
| 121 | + |
| 122 | +2. Try a prompt that references the server by name: |
| 123 | + |
| 124 | + ``` |
| 125 | + Use the github MCP server to list my recently merged pull requests. |
| 126 | + ``` |
| 127 | + |
| 128 | +## Managing the Server |
| 129 | + |
| 130 | +| Command | Purpose | |
| 131 | +| --- | --- | |
| 132 | +| `fx mcp list` | List configured servers from `mcp.json` without connecting. | |
| 133 | +| `fx mcp list --connect` | Connect and discover before rendering health. | |
| 134 | +| `fx mcp remove github` | Remove the server from the profile. | |
| 135 | +| `fx mcp path` | Print the path of the file fx reads. | |
| 136 | +| `/mcp reload` | Apply a hand edit without restarting an open session. | |
| 137 | + |
| 138 | +## Troubleshooting |
| 139 | + |
| 140 | +- **`401 Unauthorized` from the remote server**: confirm the environment variable named in `bearer_token_env` is exported in the shell that starts fx, and that the PAT is valid and not expired. |
| 141 | +- **Server reports `state=failed`**: run `fx mcp list --connect` for the failure line, and see the [Installation Guides README](./README.md) for shared troubleshooting. |
| 142 | +- **Context window exceeded**: the GitHub MCP server registers many tools. Filter with the `X-MCP-Toolsets` header shown above. |
| 143 | +- **Docker errors on the local server**: ensure Docker is running and the image has been pulled (`docker pull ghcr.io/github/github-mcp-server`). |
| 144 | + |
| 145 | +## Important Notes |
| 146 | + |
| 147 | +- **Configuration key**: fx uses `mcp` (not `mcpServers`). |
| 148 | +- **Config location**: `~/.fx/mcp.json`. Run `fx mcp path` to print it. |
| 149 | +- **Type discriminator**: `"type": "http"` for the remote server, `"type": "local"` for stdio. |
| 150 | +- **Command shape**: `command` is a single array combining the executable and its arguments. |
| 151 | +- **Environment variable key**: `environment` (`env` is also accepted). |
| 152 | +- **Credentials**: a literal `Authorization` header is rejected. Use `bearer_token_env` for a bearer token, or `header_env` to map a header name to an environment variable. |
| 153 | +- **CLI and session commands**: every `fx mcp` subcommand is also available inside a session as `/mcp`, for example `/mcp list`. |
0 commit comments