During daily repository maintenance with Codex CLI, switching back and forth between your browser and terminal quickly becomes tedious: bug reports live in GitHub Issues, while code changes and review discussions sit inside Pull Requests (PRs). Every time you inspect a ticket, you have to open the web page, manually copy the title, body, and comments, and paste them into the terminal prompt. Whenever someone posts a new reply or the ticket status changes, you have to copy everything all over again.
By connecting the official hosted GitHub MCP (Model Context Protocol) server, you allow Codex CLI to fetch the latest repository data directly from your terminal. The goal of this tutorial is straightforward: configure codex-cli 0.172.0 on Windows (verified on November 26, 2026) to invoke GitHub MCP tools directly, read a specific Issue and PR, return their titles, statuses, and original URLs, and confirm an exact match against the live GitHub pages.
| Verification Dimension | Configuration & Parameters | Verification Purpose & Pass Threshold |
|---|---|---|
| Runtime Environment | Windows PowerShell, codex-cli 0.172.0
|
Connects directly to GitHub's official remote HTTPS endpoint without local Docker, Node.js, or npx
|
| Model Provider Layer | Crazyrouter (responses wire protocol, env var OPENAI_API_KEY) |
Verifies basic model responses in isolation before adding MCP variables |
| GitHub Auth Layer | Fine-grained PAT (env var GITHUB_PAT_TOKEN) |
Scopes access to target repositories with Read-only permissions on Issues and Pull requests |
| Verification Targets | Issue #3917 and PR #3454 in github/github-mcp-server
|
Confirms actual github/issue_read and github/pull_request_read invocations in the execution trace |
The Issue #3917 page used for verification—its title, number, and status can be compared directly.
Environment and Prerequisites
Before editing any configuration files, verify the following 5 conditions:
-
Confirm Runtime Environment and Connection Mode
- We are running Codex CLI inside a Windows terminal (tested on Windows PowerShell with
codex-cli 0.172.0). - We connect directly over HTTPS to GitHub's official hosted remote MCP service—no local Node.js installation,
npxexecution, or Docker container is required.
- We are running Codex CLI inside a Windows terminal (tested on Windows PowerShell with
-
Note the Target Repository and Number Format
- Always format repository names as
owner/repo: for example,github/github-mcp-server, wheregithubis the owner andgithub-mcp-serveris the repository name. - Pass Issue and PR numbers as plain digits only:
3917and3454(omit the leading#shown on the web page).
- Always format repository names as
-
Check Your Codex CLI Version in PowerShell
- Run
codex --versionin your PowerShell terminal. If it outputs a version string such ascodex-cli 0.172.0, you are ready to proceed. - If PowerShell reports that
codexis not recognized, complete the CLI installation first and open a fresh terminal window.
- Run
-
Confirm Model Availability and Repository Access Rights
- Make sure Codex is already wired to a working model endpoint and can reply to normal chat prompts.
- If you plan to read a private repository later, your GitHub account itself must have access to that repository. Start by verifying the workflow on a public repository first, then switch to your private repository.
-
Locate Your Personal Configuration File
- On Windows, the personal configuration file lives in your user profile directory at
.codex/config.toml(for example,C:\Users\Alice\.codex\config.tomlfor user Alice). - Below, we cover two ways to register the MCP server (via CLI command or by manually editing
config.toml). Pick one method only so you do not register duplicate service entries.
- On Windows, the personal configuration file lives in your user profile directory at
Breaking Down the Call Chain Across Model, MCP, and GitHub Permissions
Splitting the end-to-end call chain into three distinct layers makes both setup and troubleshooting much clearer:
-
Layer 1: Codex Calls the Large Language Model
- Role: The model interprets your prompt ("which Issue to read, which fields to extract") and summarizes the structured data returned by the tool.
- What to watch: If your model endpoint or API key is misconfigured, Codex will not even respond to a simple greeting.
-
Layer 2: Codex Calls the GitHub MCP Server
- Role: The MCP server wraps GitHub's Issue, PR, and repository APIs into structured tools that Codex can call on demand.
-
What to watch: Seeing the server listed in
codex mcp listonly proves your TOML syntax is valid; you still need to confirm inside a session that the tool list loads and that execution actually triggers the tool call.
-
Layer 3: GitHub Validates PAT Token Permissions
- Role: Your Personal Access Token (PAT) determines which GitHub account is making the request, which repositories it can access, and whether it has read-only or read-write privileges.
- What to watch: Once public read-only testing succeeds, moving to private repositories or write operations requires updating the repository scope and permission toggles on your token.
Step 1 Verify That the Model Responds Normally
Always test the model layer in isolation first so you never confuse a model API error with an MCP connection error. In my daily workflow, I use Crazyrouter to manage endpoints and API keys across multiple models through a single gateway, so I use it here to verify the model layer. If you do not have an account yet, you can create one on the registration page by entering a username, password, email address, and verification code.
1. Check the Model Provider Block in config.toml
In .codex/config.toml, configure the [model_providers.crazyrouter] block with the following fields:
-
name: Set to"Crazyrouter", which is the display name shown inside Codex. -
env_key: Set to"OPENAI_API_KEY", which is the environment variable name holding your API key. Only write the variable name inconfig.toml; store the actual secret key in your Windows environment variables. -
wire_api: Set to"responses"to specify the Responses wire protocol. -
base_url: Set the model gateway endpoint URL by copying the address below:
https://cn.crazyrouter.com/v1
2. Launch a Session and Test a Basic Reply
-
Start Codex in PowerShell with Your Provider and Model
- Run
codex -c model_provider=crazyrouter -m gpt-6-solin PowerShell, where-c model_provider=crazyrouterselects the provider configured above and-m gpt-6-solspecifies the model identifier. - If the example model name is unavailable on your account, check the Crazyrouter model pricing catalog to confirm current model IDs and rates, then replace the value after
-mwith an active model on your account. This step only resolves model routing and is completely independent of your GitHub PAT repository permissions.
- Run
-
Send a Verification Prompt
- Once inside the session, ask it to reply with "Model call succeeded."
- When the terminal header shows
crazyrouteras the provider and returns that exact line, your model layer is ready. - If you are using OpenAI's official endpoint or another model provider, as long as normal chat responses work, you can move straight to Step 2.
Step 2 Configure Your GitHub PAT and Remote MCP Service
GitHub provides an official hosted remote MCP service. Codex only needs to connect to the HTTPS endpoint and pass your PAT via an environment variable—no local Docker containers required.
The official GitHub MCP installation guide for Codex showing the remote MCP URL and CLI setup.
1. Create a GitHub PAT (Personal Access Token)
-
Open the Token Creation Page
- Click your profile avatar in the top-right corner of GitHub and navigate to Settings → Developer settings → Personal access tokens → Fine-grained tokens → Generate new token.
Configure the Token Using Least Privilege
To read Issues and PRs from a repository, fill in the fields as follows:
| GitHub UI Field | Recommended Setting | Explanation |
|---|---|---|
| Token name | e.g., codex-github-read
|
Helps you identify the purpose of this token in your GitHub settings. |
| Expiration | e.g., 30 or 60 days | Always set an expiration window and rotate tokens as needed. |
| Resource owner | The user or organization that owns the target repo | Must match the owner of the repository, otherwise the repo will not appear below. |
| Repository access |
Only select repositories (select your target repo) |
Grant access only to required repositories rather than your entire account. |
| Repository permissions → Issues | Read-only |
Allows reading Issue titles, bodies, statuses, and comments. |
| Repository permissions → Pull requests | Read-only |
Allows reading PR titles, statuses, and review discussions. |
| Repository permissions → Metadata |
Read-only (selected automatically) |
Allows reading basic repository metadata. |
-
Adjust Permissions as Needed and Save the Token
- If you also want Codex to inspect source files inside the repository, set Contents to
Read-onlyas well. For read-only workflows, you do not need to enable anyRead and writepermissions. - Click Generate token, copy the generated token immediately, and store it safely (you cannot view the full token string again after closing the page). Place the token only in your local environment variable—never hardcode it into
config.tomlor paste it into a chat prompt. -
Note on Token Types: GitHub also offers Tokens (classic) (which use broad scopes such as
repo). For everyday CLI usage, prefer the Fine-grained token above for much tighter permission boundaries.
- If you also want Codex to inspect source files inside the repository, set Contents to
2. Set the Environment Variable on Windows
-
Create a User Environment Variable
- In the Windows search bar, open "Edit environment variables for your account" → click "Environment Variables".
- Under User variables, click "New", enter
GITHUB_PAT_TOKENas the variable name, and paste your newly generated GitHub PAT as the variable value.
-
Restart Your Terminal to Apply the Variable
- After saving, close your existing PowerShell window completely and open a brand-new PowerShell window (if Codex was running, exit it first).
-
Verify That PowerShell Can Read the Variable
- In the new PowerShell window, run
if ([string]::IsNullOrWhiteSpace($env:GITHUB_PAT_TOKEN)) { 'GITHUB_PAT_TOKEN not set' } else { 'GITHUB_PAT_TOKEN is set' }to confirm the variable is populated without printing your secret token on screen. - Once it outputs
GITHUB_PAT_TOKEN is set, continue to the next step; if it outputsnot set, double-check the variable name spelling and make sure you opened a fresh terminal session.
- In the new PowerShell window, run
3. Add GitHub MCP to Codex (Choose One of Two Methods)
-
Method A: Add via CLI Command (Recommended)
- In PowerShell, run
codex mcp add github --url https://api.githubcopilot.com/mcp/ --bearer-token-env-var GITHUB_PAT_TOKENfollowed bycodex mcp list. -
codex mcp add githubregisters an MCP server namedgithub;--url https://api.githubcopilot.com/mcp/sets GitHub's official remote MCP endpoint;--bearer-token-env-var GITHUB_PAT_TOKENtells Codex which environment variable holds the bearer token. - Running
codex mcp listprints your configured MCP servers—oncegithubappears with statusenabledand authBearer token, the registration is complete.
- In PowerShell, run
-
Method B: Manually Edit
config.toml- Open
%USERPROFILE%\.codex\config.toml, add a[mcp_servers.github]block, and seturl = "https://api.githubcopilot.com/mcp/"along withbearer_token_env_var = "GITHUB_PAT_TOKEN". - Important:
bearer_token_env_varexpects the environment variable nameGITHUB_PAT_TOKEN—never paste your rawghp_orgithub_pat_token string directly intoconfig.toml. Method A and Method B produce the exact same result, so use whichever you prefer.
- Open
-
Bonus: Why We Skip Legacy Local
npxand How the Read-Only Endpoint Works-
Why skip local
npx: Older tutorials often configurecommand = "npx"with@modelcontextprotocol/server-github. That npm package is now archived, frequently required plaintext tokens in config files, and routinely triggeredspawn npx ENOENTpath errors on Windows. The official remote HTTPS endpoint avoids all of those issues. -
Optional Official Read-Only Endpoint: If you want to strip out all write tools at the server level, change
urlto"https://api.githubcopilot.com/mcp/readonly"(for example, under[mcp_servers.github_readonly]). The/mcp/readonlyendpoint exposes only read tools from GitHub's server, whereas Codex CLI's-s read-onlyflag only restricts local filesystem sandboxing and does not block remote MCP calls. Keep only one GitHub MCP entry active at a time.
-
Why skip local
Step 3 Test Reading an Issue and PR and Verify the Output
With configuration complete, verify the end-to-end read workflow in three steps:
1. Three-Step Verification Workflow
-
Step 1: Check Server Status in the CLI
- Run
codex mcp listin PowerShell and confirm thatgithubshows statusenabledand authBearer token.
- Run
-
Step 2: Check Tool Loading Inside a Codex Session
- Launch Codex and type the slash command
/mcpin the prompt to confirm that the tool list undergithubloads properly.
- Launch Codex and type the slash command
-
Step 3: Send the Read Prompt
- Enter the following prompt in Codex to explicitly read Issue #3917 and PR #3454 from
github/github-mcp-serverusing only GitHub MCP tools:
- Enter the following prompt in Codex to explicitly read Issue #3917 and PR #3454 from
Use only GitHub MCP tools to read Issue #3917 in github/github-mcp-server, and read the title and status of PR #3454 in the same repository. Reply with two lines of facts and links; do not use shell commands or modify anything.
2. Live Results Compared Against the Original GitHub Pages
After sending the prompt, Codex's execution log sequentially invoked github/issue_read and github/pull_request_read. The returned fields matched the live GitHub web pages word for word:
| Target Read | Returned Status | Returned Full Title | Comparison Against Live Page |
|---|---|---|---|
| Issue #3917 | closed |
Repo-scoped tools fail with -32020 "missing Mcp-Param-owner header" in claude.ai chats; the same calls work from Claude Code |
Exact match with Issue #3917 page |
| PR #3454 | merged |
fix(inventory): restore typed tool HTTP header validation |
Exact match with PR #3454 page |
PR #3454 shows status Merged on GitHub, matching the tool output.
Three practical tips for daily usage:
-
Confirm Real Tool Invocations in the Log: Always glance at the Codex execution log to verify that
github/issue_readorgithub/pull_request_readwas actually called, rather than letting the model guess from pre-training memory or prior chat context. - Let the Model Summarize Facts, but Verify Causality Yourself: Both PR #3454 and Issue #3917 touch typed tool HTTP header validation, but PR #3454 was merged before Issue #3917 was even opened—so PR #3454 is not the fix that closed Issue #3917. When inspecting multiple tickets, ask Codex to list titles, statuses, and timestamps first before drawing causal conclusions.
-
Expand Permissions Gradually from Read to Write: Once public Issue and PR reads work, swap
owner/repofor your private repositories. When you later want Codex to post comments, open Issues, or push branches, inspect the required tool name via/mcpfirst and enableRead and writeonly for those specific modules in your GitHub PAT settings.
Common Errors and Troubleshooting Sequence
When something fails, checking layers in the order of "Model → Config File → Tool Loading → Authentication → Token Permissions → Repo Path → Network & Other Services" isolates the root cause fastest:
-
Symptom 1: Codex Cannot Reply to Normal Chat Questions
- Root Cause: The model provider layer is misconfigured; execution has not reached GitHub MCP yet.
-
Checks:
- Confirm
model_providermatches the table name inconfig.toml; - Confirm the model name passed via
-mis valid and available; - Confirm
base_urland the model API key environment variable are active.
- Confirm
-
Symptom 2: Model Replies, but
githubIs Missing fromcodex mcp list- Root Cause: The MCP block was written to the wrong file or has a TOML syntax error.
-
Checks:
- Verify you edited
%USERPROFILE%\.codex\config.tomlunder your current Windows user; - Check the
[mcp_servers.github]header and make sure all quotes are closed; - Save the file and re-run
codex mcp list.
- Verify you edited
-
Symptom 3:
githubIs Listed, but/mcpShows No Tools- Root Cause: The Codex session was not restarted, or remote server initialization failed.
-
Checks:
- Exit the current Codex session and launch a fresh one;
- Check that
urlis set tohttps://api.githubcopilot.com/mcp/; - Note that
/mcp/readonlyintentionally loads only read-only tools.
-
Symptom 4: Tool Calls Return
401 Unauthorized- Root Cause: The environment variable is not loaded in the current shell, or the PAT is invalid.
-
Checks:
- Run the
$env:GITHUB_PAT_TOKENcheck in the exact PowerShell window where you start Codex and confirm it printsGITHUB_PAT_TOKEN is set; - Check whether the GitHub PAT has expired, been revoked, or lost characters when copied;
- Always close and reopen PowerShell after changing Windows environment variables.
- Run the
-
Symptom 5: Tool Calls Return
403 Forbiddenor MentionSAML SSO- Root Cause: Insufficient token permissions, pending organization approval, or GitHub API rate limiting.
-
Checks:
-
Fine-grained token: verify the Resource owner, selected repositories, and
Read-onlypermissions on Issues and Pull requests (for organization repos, confirm an admin approved the token); - Classic token: if the organization enforces SAML SSO, click Configure SSO → Authorize on your GitHub Tokens page;
-
Rate limit (
API rate limit exceeded): narrow your query scope and wait for the rate-limit window to reset.
-
Fine-grained token: verify the Resource owner, selected repositories, and
-
Symptom 6: Tool Calls Return
404 Not Found-
Root Cause: A typo in
owner/repoor ticket number, or lack of access to a target private repository (GitHub returns 404 for unauthorized private repositories to avoid leaking their existence). -
Checks:
- Double-check the
owner/repospelling and confirm the Issue or PR number exists in that repo; - For private repositories, confirm you can view the repo in your browser first, then verify the repo is checked under
Repository accessin your PAT settings.
- Double-check the
-
Root Cause: A typo in
-
Symptom 7: Public Repos Work, but Private Repos Fail (or Read Works, Write Fails)
- Root Cause: Your PAT repository scope or read/write level does not cover the requested action.
-
Checks:
-
Private repo unreadable: add the private repository to the token's authorized list and enable
Read-onlyon the relevant modules; -
Read works, write fails: upgrade the relevant modules (Issues, Pull requests, Contents) from
Read-onlytoRead and write, and check repository branch protection rules.
-
Private repo unreadable: add the private repository to the token's authorized list and enable
-
Symptom 8: Request Timeout or
502 Bad Gateway- Root Cause: Transient network issues, or another MCP server mounted on your machine failing during startup.
-
Checks:
- Inspect the exact service name in the error log first. During my initial test run, a separate locally configured service (
magpie-artifacts) threw an HTTP 502 error; after temporarily disabling that unrelated server, everygithubMCP tool call succeeded immediately—so do not assume every 502 error comes from GitHub MCP; - If the error specifically names
github, test your network connection tohttps://api.githubcopilot.com/mcp/and retry.
- Inspect the exact service name in the error log first. During my initial test run, a separate locally configured service (
Summary and Next Steps
Following these three steps gives you a clean, working pipeline on Windows with Codex CLI:
-
Model Layer: Configure your model provider in
config.tomland verify normal chat responses; -
Connection Layer: Inject
GITHUB_PAT_TOKENvia Windows environment variables and mount GitHub's official remote MCP endpoint; -
Tool Layer: Use natural language prompts to trigger
github/issue_readandgithub/pull_request_readfor live Issue and PR inspection.
Starting with this read-only setup eliminates constant browser-to-terminal copy-pasting during bug triage and code review. When you are ready to connect private repositories or let Codex search code, post review comments, and manage workflows, simply expand the repository list and read/write permissions on your GitHub PAT.
References
- GitHub Official Documentation: Installing GitHub MCP Server in Codex (verified 2026-11-26)
- GitHub Official Documentation: GitHub MCP Server Remote Server & Read-only Endpoint (verified 2026-11-26)
- OpenAI Official Documentation: Codex CLI MCP Configuration Guide (verified 2026-11-26)




Top comments (0)