Skip to content
Status

Using MCP servers

How to set up the GitHub MCP server

Governing MCP across your organization?

Speakeasy’s 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 or Codex CLI 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. 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

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

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

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:

Terminal window
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 or Codex. For any other agent, see Connect other MCP clients.

Claude Code

Add the GitHub MCP server to Claude Code:

Terminal window
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:

Terminal window
claude mcp list

The github server shows as Connected.

Terminal output of claude mcp add and claude mcp list, with the github server connected

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

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

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

Codex

Add the GitHub MCP server to Codex:

Terminal window
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:

Terminal window
codex mcp list

Terminal output of codex mcp add and codex mcp list, with the github server enabled

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

Codex /mcp output with the github server connected and 46 tools

Ask Codex to do something on GitHub, for example:

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

The comment appears on the issue, posted as you.

The comment Codex posted on issue #1 in the GitHub repository

Connect other MCP clients

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

SettingValue
Server URLhttps://api.githubcopilot.com/mcp/
HeaderAuthorization: Bearer <your github_pat_ token>

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

The warning looks like this:

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:

Terminal window
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: