---
title: How to connect GitHub MCP to Codex
description: Run codex mcp add with https://api.githubcopilot.com/mcp/ and --bearer-token-env-var. Read-only mode, toolsets, approvals and a project config.
canonical: https://mcp1.com/blog/github-mcp-codex
last-updated: 2026-11-23
---

# How to connect GitHub MCP to Codex

Run codex mcp add with https://api.githubcopilot.com/mcp/ and --bearer-token-env-var. Read-only mode, toolsets, approvals and a project config.

![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite

 \~/.codex/config.toml

[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PAT"

githubEnabled

 \~/.codex/config.toml

[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PAT"

githubEnabled

To connect GitHub to Codex, create a fine-grained personal access token, export it, and run `codex mcp add` with GitHub’s hosted server, `https://api.githubcopilot.com/mcp/`, and `--bearer-token-env-var`. Codex then reads repositories, issues, pull requests and Actions logs with your access. Use the `/readonly` URL or the `X-MCP-Readonly` header to keep it from writing.

## How do I add the GitHub MCP server to Codex?

GitHub hosts the server, so there is nothing to install. These steps work for the Codex CLI and the IDE extension, which share one config file.

1. 1Create a fine-grained token at `github.com/settings/personal-access-tokens`. Pick the repositories it may reach and grant read access to Contents, Issues, Pull requests and Metadata. Add Actions for build logs. Grant write only where you want Codex to write.
2. 2Export it and add the server:  
Terminal  
```  
export GITHUB_PAT_TOKEN=github_pat_...  
codex mcp add github --url https://api.githubcopilot.com/mcp/ \  
  --bearer-token-env-var GITHUB_PAT_TOKEN  
```
3. 3Start `codex` and run `/mcp`. `github` should be listed with its tools. In the IDE extension, open the gear menu and choose MCP servers.

`codex mcp add` writes this to `~/.codex/config.toml`. The file stores the variable’s name, never the token:

\~/.codex/config.toml

```
[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PAT_TOKEN"
```

Then make a call that changes nothing:

Prompt

```
Use the GitHub tools to list the open pull requests in this repository
that are waiting on my review. Don't change anything.
```

Why a token and not codex mcp login

Codex’s OAuth sign-in registers itself with the server through dynamic client registration or a client metadata document. GitHub’s sign-in doesn’t offer either, so GitHub’s own Codex guide uses a token and says `--bearer-token-env-var` is required. Codex reads the variable from the environment it starts in, so export it in your shell profile, not only in a `.env` file.

## Which GitHub tools does Codex get?

The base URL loads five default toolsets: `context`, `repos`, `issues`, `pull_requests` and `users`. These are the tools you’ll use most:

ToolWhat it does

`get_file_contents`

Reads a file or directory from any repository the token reaches. Read.

`search_code`

Searches code across GitHub with qualifiers like repo: and org:. Read.

`issue_read`

Fetches an issue with its comments; list\_issues and search\_issues find them. Read.

`pull_request_read`

Fetches a pull request’s diff, files, reviews or check status. Read.

`get_job_logs`

Returns logs for a failed Actions job. Read, in the actions toolset.

`issue_write`

Creates or updates an issue. Write.

`create_pull_request`

Opens a pull request from a branch. Write.

`merge_pull_request`

Merges a pull request. Write.

Codex already has `git` and your checkout, so the server is for what isn’t local: other repositories, issues, review threads and CI logs.

## How do I make GitHub MCP read-only in Codex?

Change the URL to `https://api.githubcopilot.com/mcp/readonly`, or send GitHub’s headers with `http_headers`. `X-MCP-Readonly` drops every write tool and `X-MCP-Toolsets` picks which toolsets load:

\~/.codex/config.toml

```
[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PAT_TOKEN"
http_headers = { "X-MCP-Toolsets" = "repos,issues,pull_requests,actions", "X-MCP-Readonly" = "true" }
```

SettingEffect

`/readonly`

Default toolsets, read tools only.

`/x/actions/readonly`

One toolset in the path. Use the header for more than one.

`X-MCP-Toolsets`

Comma-separated toolsets. Unknown names are ignored.

`X-MCP-Tools`

Single tools. A misspelled name stops the server from starting.

`enabled_tools`

Codex’s own allowlist for the server. disabled\_tools is applied after it.

Headers and Codex’s lists are config anyone can edit. A token without write permissions is the limit GitHub enforces. More in [how to make an MCP server read-only](https://mcp1.com/blog/read-only-mcp-server).

## How do I make Codex ask before GitHub writes?

Set an approval mode per server or per tool. The modes are `auto`, `prompt`, `writes` and `approve`; `writes` asks before any tool that isn’t marked read-only. Remove tools you never want with `disabled_tools`:

\~/.codex/config.toml

```
[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PAT_TOKEN"
default_tools_approval_mode = "writes"
disabled_tools = ["merge_pull_request", "delete_file"]

[mcp_servers.github.tools.create_pull_request]
approval_mode = "prompt"
```

OpenAI’s docs also say a tool that advertises a destructive annotation always needs approval, unless it is also marked read-only. Don’t rely on annotations alone: a tool without them could do anything. See [how to stop agents from running destructive MCP tools](https://mcp1.com/blog/stop-destructive-mcp-tools).

## How do I share the GitHub server with my team in Codex?

Commit the same block to `.codex/config.toml` at the repository root. Codex loads project config only for projects you’ve marked as trusted, and the closest file wins over `~/.codex/config.toml`. Each teammate exports their own `GITHUB_PAT_TOKEN`, so the file holds no secret and every call is made as the person who ran it.

`codex mcp add` always writes to the global file, so edit the project file by hand. For CI, where nobody exports a token by hand, see [MCP servers in CI and headless agents](https://mcp1.com/blog/mcp-in-ci-and-headless-agents).

## Can I sign in with OAuth using the local server?

Yes. GitHub’s Docker image runs the server on your machine over stdio and opens a browser sign-in on first use, keeping the token in memory. This is the setup GitHub’s Codex guide now leads with, and it needs Docker running:

\~/.codex/config.toml

```
[mcp_servers.github]
command = "docker"
args = ["run", "-i", "--rm", "-p", "127.0.0.1:8085:8085", "-e", "GITHUB_OAUTH_CALLBACK_PORT", "ghcr.io/github/github-mcp-server"]
env = { GITHUB_OAUTH_CALLBACK_PORT = "8085" }
```

The local server is also the only option for GitHub Enterprise Server. It takes `GITHUB_TOOLSETS` and `GITHUB_READ_ONLY` as environment variables in place of the headers.

## What if GitHub MCP doesn’t connect in Codex?

Terminal

```
codex mcp list
codex mcp get github
```

- A 401 or an empty tool list. `GITHUB_PAT_TOKEN` isn’t set in the environment Codex started from. An IDE launched from the dock may not see variables from your shell profile; start it from a terminal, or set the variable system-wide.
- Codex tries a browser sign-in. The server was added without `--bearer-token-env-var`, so Codex looked for OAuth. Remove it with `codex mcp remove github` and add it again with the flag.
- Organization repositories come back empty. Your organization may need to approve fine-grained tokens, or the token needs SSO authorization.
- The server times out on start. Raise `startup_timeout_sec` above its default of 10.

## GitHub for the whole team, without a token on every laptop

The setup above leaves a GitHub token in every developer’s environment and keeps read-only mode in a file anyone can change. MCP1 is a gateway that does it once. An admin installs [GitHub](https://mcp1.com/servers/github) in the workspace with a fine-grained token, and can add a second, read-only token that people on read-only access call with, so GitHub itself refuses their writes. Each person adds one URL and signs in with OAuth, which works in Codex because MCP1 supports dynamic client registration:

Terminal

```
codex mcp add mcp1 --url https://mcp1.com/mcp/<workspace>/<gateway>
codex mcp login mcp1
```

GitHub’s tools appear as `github__<tool>` next to Linear, Sentry and the rest, rules like `github__merge_*` hold risky tools to admins, and every call is in the audit log. The same server in other clients: [Claude Code](https://mcp1.com/blog/github-mcp-claude-code) and [VS Code](https://mcp1.com/blog/github-mcp-vscode). The [docs](https://mcp1.com/docs) cover gateways and groups, and you can [start free](https://mcp1.com/signup).

## Common questions

### Does codex mcp login work with GitHub’s MCP server?

Not with the hosted server. GitHub’s sign-in doesn’t offer the client registration Codex’s OAuth uses, so GitHub’s Codex guide uses a personal access token with --bearer-token-env-var. The local Docker server does sign in with a browser.

### Do the Codex CLI and the IDE extension need separate setup?

No. Both read \~/.codex/config.toml, so a server added with codex mcp add shows up in the extension too, after a restart.

### Where do I put GitHub’s X-MCP-Readonly header in Codex?

In http\_headers under \[mcp\_servers.github\] in config.toml. codex mcp add has no flag for custom headers. You can also use the /readonly URL instead.

### Can I commit the GitHub MCP config for my team?

Yes, in .codex/config.toml at the repository root. Codex loads it only in trusted projects, and each person exports their own token, so the file holds no secret.

Give your team one URL

Create a workspace, install your servers and share a gateway with a group. Free for individuals.

[Start with MCP1](https://mcp1.com/signup)[Read the docs](https://mcp1.com/docs)

## More from the blog

[ Terminal$ claude mcp add --transport http sentry mcp.sentry.dev/mcp/acme/websentryAuthenticatedHow to connect Sentry MCP to Claude CodeRun claude mcp add with https://mcp.sentry.dev/mcp/<org>/<project>, then /mcp to sign in. Skills, permission rules, tokens for CI and self-hosted Sentry.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/sentry-mcp-claude-code)[ POST /mcpHTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer   resource_metadata=".../oauth-protected-resource/mcp"aud = https://mcp.example.com/mcpValidHow to add OAuth to a remote MCP serverPublish protected resource metadata, return 401 with WWW-Authenticate, and accept only tokens whose audience is your server. What the auth server needs.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/add-oauth-to-mcp-server)

---

This is the markdown copy of https://mcp1.com/blog/github-mcp-codex. Site index for agents: https://mcp1.com/llms.txt
