DEV Community

Cover image for Connecting Codex CLI to the Official GitHub MCP Server on Windows Without Docker
boluo
boluo

Posted on

Connecting Codex CLI to the Official GitHub MCP Server on Windows Without Docker

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

Live GitHub Issue 3917 page

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:

  1. 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, npx execution, or Docker container is required.
  2. Note the Target Repository and Number Format

    • Always format repository names as owner/repo: for example, github/github-mcp-server, where github is the owner and github-mcp-server is the repository name.
    • Pass Issue and PR numbers as plain digits only: 3917 and 3454 (omit the leading # shown on the web page).
  3. Check Your Codex CLI Version in PowerShell

    • Run codex --version in your PowerShell terminal. If it outputs a version string such as codex-cli 0.172.0, you are ready to proceed.
    • If PowerShell reports that codex is not recognized, complete the CLI installation first and open a fresh terminal window.
  4. 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.
  5. 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.toml for 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.

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:

  1. 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.
  2. 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 list only 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.
  3. 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.

Live Crazyrouter registration page

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 in config.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
Enter fullscreen mode Exit fullscreen mode

2. Launch a Session and Test a Basic Reply

  1. Start Codex in PowerShell with Your Provider and Model

    • Run codex -c model_provider=crazyrouter -m gpt-6-sol in PowerShell, where -c model_provider=crazyrouter selects the provider configured above and -m gpt-6-sol specifies 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 -m with an active model on your account. This step only resolves model routing and is completely independent of your GitHub PAT repository permissions.
  2. Send a Verification Prompt

    • Once inside the session, ask it to reply with "Model call succeeded."
    • When the terminal header shows crazyrouter as 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.

Live GitHub official Codex installation guide page

The official GitHub MCP installation guide for Codex showing the remote MCP URL and CLI setup.

1. Create a GitHub PAT (Personal Access Token)

  1. 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.
  2. 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.
  1. Adjust Permissions as Needed and Save the Token
    • If you also want Codex to inspect source files inside the repository, set Contents to Read-only as well. For read-only workflows, you do not need to enable any Read and write permissions.
    • 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.toml or 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.

2. Set the Environment Variable on Windows

  1. 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_TOKEN as the variable name, and paste your newly generated GitHub PAT as the variable value.
  2. 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).
  3. 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 outputs not set, double-check the variable name spelling and make sure you opened a fresh terminal session.

3. Add GitHub MCP to Codex (Choose One of Two Methods)

  1. 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_TOKEN followed by codex mcp list.
    • codex mcp add github registers an MCP server named github; --url https://api.githubcopilot.com/mcp/ sets GitHub's official remote MCP endpoint; --bearer-token-env-var GITHUB_PAT_TOKEN tells Codex which environment variable holds the bearer token.
    • Running codex mcp list prints your configured MCP servers—once github appears with status enabled and auth Bearer token, the registration is complete.
  2. Method B: Manually Edit config.toml

    • Open %USERPROFILE%\.codex\config.toml, add a [mcp_servers.github] block, and set url = "https://api.githubcopilot.com/mcp/" along with bearer_token_env_var = "GITHUB_PAT_TOKEN".
    • Important: bearer_token_env_var expects the environment variable name GITHUB_PAT_TOKEN—never paste your raw ghp_ or github_pat_ token string directly into config.toml. Method A and Method B produce the exact same result, so use whichever you prefer.
  3. Bonus: Why We Skip Legacy Local npx and How the Read-Only Endpoint Works

    • Why skip local npx: Older tutorials often configure command = "npx" with @modelcontextprotocol/server-github. That npm package is now archived, frequently required plaintext tokens in config files, and routinely triggered spawn npx ENOENT path 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 url to "https://api.githubcopilot.com/mcp/readonly" (for example, under [mcp_servers.github_readonly]). The /mcp/readonly endpoint exposes only read tools from GitHub's server, whereas Codex CLI's -s read-only flag only restricts local filesystem sandboxing and does not block remote MCP calls. Keep only one GitHub MCP entry active at a time.

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

  1. Step 1: Check Server Status in the CLI

    • Run codex mcp list in PowerShell and confirm that github shows status enabled and auth Bearer token.
  2. Step 2: Check Tool Loading Inside a Codex Session

    • Launch Codex and type the slash command /mcp in the prompt to confirm that the tool list under github loads properly.
  3. Step 3: Send the Read Prompt

    • Enter the following prompt in Codex to explicitly read Issue #3917 and PR #3454 from github/github-mcp-server using only GitHub MCP tools:

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

Live GitHub PR 3454 page

PR #3454 shows status Merged on GitHub, matching the tool output.

Three practical tips for daily usage:

  1. Confirm Real Tool Invocations in the Log: Always glance at the Codex execution log to verify that github/issue_read or github/pull_request_read was actually called, rather than letting the model guess from pre-training memory or prior chat context.
  2. 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.
  3. Expand Permissions Gradually from Read to Write: Once public Issue and PR reads work, swap owner/repo for your private repositories. When you later want Codex to post comments, open Issues, or push branches, inspect the required tool name via /mcp first and enable Read and write only 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:

  1. 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_provider matches the table name in config.toml;
      • Confirm the model name passed via -m is valid and available;
      • Confirm base_url and the model API key environment variable are active.
  2. Symptom 2: Model Replies, but github Is Missing from codex 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.toml under 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.
  3. Symptom 3: github Is Listed, but /mcp Shows 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 url is set to https://api.githubcopilot.com/mcp/;
      • Note that /mcp/readonly intentionally loads only read-only tools.
  4. 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_TOKEN check in the exact PowerShell window where you start Codex and confirm it prints GITHUB_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.
  5. Symptom 5: Tool Calls Return 403 Forbidden or Mention SAML 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-only permissions 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.
  6. Symptom 6: Tool Calls Return 404 Not Found

    • Root Cause: A typo in owner/repo or 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/repo spelling 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 access in your PAT settings.
  7. 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-only on the relevant modules;
      • Read works, write fails: upgrade the relevant modules (Issues, Pull requests, Contents) from Read-only to Read and write, and check repository branch protection rules.
  8. 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, every github MCP 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 to https://api.githubcopilot.com/mcp/ and retry.

Summary and Next Steps

Following these three steps gives you a clean, working pipeline on Windows with Codex CLI:

  1. Model Layer: Configure your model provider in config.toml and verify normal chat responses;
  2. Connection Layer: Inject GITHUB_PAT_TOKEN via Windows environment variables and mount GitHub's official remote MCP endpoint;
  3. Tool Layer: Use natural language prompts to trigger github/issue_read and github/pull_request_read for 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)