# How to set up the GitHub MCP server

> **Governing MCP across your organization?**
> Speakeasy's [AI control plane](/product/ai-control-plane) connects, secures, and observes every agent and MCP server from one entry point — with SSO, RBAC, runtime guardrails, and a full audit trail.

GitHub's official MCP server is hosted at `https://api.githubcopilot.com/mcp/`. It gives an AI agent access to your GitHub repositories, so the agent can read code, triage issues, review pull requests, and comment for you.

This guide shows you how to connect the GitHub MCP server to Claude Code and Codex. You'll create a personal access token, save it, and add the server to your agent.

## Prerequisites

To follow along, you'll need:

- A GitHub account. The GitHub MCP server is available on every GitHub plan.
- [Claude Code](https://code.claude.com/docs) or [Codex CLI](https://developers.openai.com/codex) installed

## Step 1: Create a GitHub personal access token for MCP

The GitHub MCP server accepts a personal access token as a bearer token. Use a fine-grained token, so you can limit the agent to the repositories and permissions it needs.

Go to [github.com/settings/personal-access-tokens/new](https://github.com/settings/personal-access-tokens/new). Enter a **Token name** and check that **Resource owner** is your account. You can leave **Expiration** at its default.

![GitHub's new fine-grained personal access token form with the token name and resource owner highlighted](/assets/mcp/using-mcp/github-mcp/token-name-and-owner.png)

Under **Repository access**, select **Only select repositories** and choose the repositories you want your agent to work with.

Under **Permissions**, click **Add permissions** and add these repository permissions:

- **Contents**: Read-only
- **Issues**: Read and write
- **Pull requests**: Read and write

GitHub adds **Metadata** as read-only automatically. Add more permissions later if you want your agent to do more, such as run workflows.

![The token's repository access set to one repository, with Contents, Issues, Metadata, and Pull requests permissions and the Generate token button](/assets/mcp/using-mcp/github-mcp/token-permissions.png)

Click **Generate token**.

## Step 2: Save your GitHub MCP token

GitHub shows your new token once. Click the copy icon next to it. The token starts with `github_pat_`.

![The fine-grained personal access tokens page showing the new token, with the token value redacted, and its copy icon](/assets/mcp/using-mcp/github-mcp/token-created.png)

The token lets your agent act as you on GitHub, so keep it out of config files and code. Instead, save it as an environment variable in your shell profile:

```bash
echo 'export GITHUB_MCP_TOKEN="github_pat_your-token"' >> ~/.zshrc
```

Replace `github_pat_your-token` with the token you copied. If you use Bash, write to `~/.bashrc` instead.

Open a new terminal window so the variable loads.

## Step 3: Connect your agent to the GitHub MCP server

Follow the instructions for the agent you use: [Claude Code](#claude-code) or [Codex](#codex). For any other agent, see [Connect other MCP clients](#connect-other-mcp-clients).

### Claude Code

Add the GitHub MCP server to Claude Code:

```bash
claude mcp add --transport http --scope user github https://api.githubcopilot.com/mcp/ --header 'Authorization: Bearer ${GITHUB_MCP_TOKEN}'
```

Keep the single quotes around the header. They tell Claude Code to save the variable name rather than the token itself, and Claude Code reads the token from your environment when it starts. The `--scope user` option makes the server available in all your projects.

Check that the server connects:

```bash
claude mcp list
```

The `github` server shows as **Connected**.

![Terminal output of claude mcp add and claude mcp list, with the github server connected](/assets/mcp/using-mcp/github-mcp/claude-code-mcp-add.png)

Start Claude Code with `claude` and ask about one of your repositories, for example:

```text
Summarize the open issues in hashkader47/acme-weather-api and tell me which one to fix first
```

Replace `hashkader47/acme-weather-api` with a repository your token can access.

Claude Code asks for permission the first time it uses each GitHub tool. Select **Yes** to let it run.

![Claude Code asking for permission to run the GitHub List issues tool](/assets/mcp/using-mcp/github-mcp/claude-code-tool-approval.png)

Claude Code reads the issues and answers your question.

![Claude Code summarizing the open issues in the repository and recommending which one to fix first](/assets/mcp/using-mcp/github-mcp/claude-code-summary.png)

### Codex

Add the GitHub MCP server to Codex:

```bash
codex mcp add github --url https://api.githubcopilot.com/mcp/ --bearer-token-env-var GITHUB_MCP_TOKEN
```

The `--bearer-token-env-var` option tells Codex to read the token from the `GITHUB_MCP_TOKEN` environment variable and send it with each request.

Check the server's configuration:

```bash
codex mcp list
```

![Terminal output of codex mcp add and codex mcp list, with the github server enabled](/assets/mcp/using-mcp/github-mcp/codex-mcp-add.png)

Start Codex with `codex` and enter `/mcp`. The `github` server shows as **connected**.

![Codex /mcp output with the github server connected and 46 tools](/assets/mcp/using-mcp/github-mcp/codex-mcp-connected.png)

Ask Codex to do something on GitHub, for example:

```text
Comment on issue #1 in hashkader47/acme-weather-api saying that I'm picking this up today
```

Codex asks for permission before it runs a GitHub tool. Select **Allow** to let it continue.

![Codex asking for permission to run the add_issue_comment tool](/assets/mcp/using-mcp/github-mcp/codex-tool-approval.png)

The comment appears on the issue, posted as you.

![The comment Codex posted on issue #1 in the GitHub repository](/assets/mcp/using-mcp/github-mcp/github-issue-comment.png)

## Connect other MCP clients

You can connect any MCP client that supports remote (Streamable HTTP) servers and custom headers. Use these values:

| Setting | Value |
|---|---|
| Server URL | `https://api.githubcopilot.com/mcp/` |
| Header | `Authorization: Bearer ` |

## Troubleshooting

### Codex shows `github: failed (0 tools)`

If `/mcp` in Codex shows the GitHub server as failed, press `F2` to view the warning.

![Codex /mcp output with the github server failed and 0 tools](/assets/mcp/using-mcp/github-mcp/codex-mcp-failed.png)

The warning looks like this:

```text
MCP client for `github` failed to start: MCP startup failed: Environment variable GITHUB_MCP_TOKEN for MCP server 'github' is not set
MCP startup incomplete (failed: github)
```

This warning means Codex started before the `GITHUB_MCP_TOKEN` variable was set. Codex runs a background process that keeps the environment it started with, so you need to restart it.

Quit Codex, then stop its background process:

```bash
pkill -f "codex app-server"; pkill -f codex-code-mode-host
```

Open a new terminal window, start `codex`, and enter `/mcp` again.

## Next steps

You now have the GitHub MCP server connected to your agent. You created a fine-grained personal access token, saved it as an environment variable, and added the server to Claude Code or Codex. Your agent can read your repositories, triage issues and pull requests, and comment for you.

To keep going:

- Connect more services to your agent with the other guides in [Connect popular MCP servers](/mcp/using-mcp/mcp-server-providers).
- Learn how to get better results from your agent's tools in [Best practices for using MCP tools](/mcp/using-mcp/using-tools).
- See what teams build with MCP in [MCP use cases](/mcp/using-mcp/use-cases).

---

Index of every Speakeasy page for agents: [llms.txt](https://www.speakeasy.com/llms.txt). AI control plane and MCP gateway content in one file: [llms-full.txt](https://www.speakeasy.com/llms-full.txt). Any page is available as markdown by appending `.md` to its URL or by requesting it with `Accept: text/markdown`.
