Codex MCP Setup: codex mcp add, config.toml & OAuth Login (2026)
Nikhil Tiwari
MCP Playground
Quick answer
Codex keeps MCP servers in ~/.codex/config.toml, one [mcp_servers.<name>] table each. The CLI, the IDE extension and the ChatGPT desktop app all read the same file.
# Local stdio server
codex mcp add context7 -- npx -y @upstash/context7-mcp
# Remote streamable HTTP server
codex mcp add sentry --url https://mcp.sentry.dev/mcp
codex mcp login sentry
# Check what's configured
codex mcp list
TL;DR
- Config is TOML, not JSON. Copying an
mcpServersblock from a Cursor guide won't work as-is. - Two transports: stdio and streamable HTTP. The docs don't list SSE.
- Auth: a bearer token from an env var, static headers, or OAuth via
codex mcp login. - Safety knobs most guides skip:
enabled_tools,disabled_toolsand per-tool approval modes. - Project config goes in
.codex/config.tomland only loads in trusted projects.
Codex can read your docs, drive a browser and pull errors from Sentry, but only once you've connected it to MCP servers. Most setup guides on the web are written for Claude Desktop or Cursor and use JSON. Codex uses TOML, which is where people get stuck.
This guide covers the CLI, the IDE extension and the ChatGPT desktop app. Every command and key below was checked against OpenAI's Codex MCP docs and the CLI reference on 1 December 2026.
Where Codex stores MCP config
| File | Applies to | Notes |
|---|---|---|
~/.codex/config.toml | Every project | The default. codex mcp add writes here. |
.codex/config.toml in a repo | That project | Only loads when the project is trusted. |
The ChatGPT desktop app, the Codex CLI and the IDE extension share this configuration. Add a server once and it shows up in all three.
Add a server with codex mcp add
Local stdio server
# Syntax
codex mcp add <server-name> --env VAR1=VALUE1 --env VAR2=VALUE2 -- <stdio server-command>
# Example: Context7 for up-to-date library docs
codex mcp add context7 -- npx -y @upstash/context7-mcp
Everything after -- is the command that starts the server. --env only applies to stdio servers.
Remote streamable HTTP server
# Syntax
codex mcp add <server-name> --url <url>
# With a token kept in an environment variable
codex mcp add my-api --url https://mcp.example.com/mcp --bearer-token-env-var MY_API_TOKEN
--url and a stdio command can't be combined: a server is one or the other.
The other subcommands
codex mcp list # every configured server (--json for scripts)
codex mcp get <name> # one server's config (--json prints the raw entry)
codex mcp remove <name> # delete the definition
codex mcp login <name> # OAuth sign-in (HTTP servers only)
codex mcp logout <name> # forget stored OAuth credentials
Inside the codex TUI, type /mcp to see active servers and tools. /mcp verbose adds diagnostics, and /mcp login <name> signs in without leaving the session.
Add a server in the desktop app or IDE extension
Prefer clicking? Both have the same form.
- ChatGPT desktop app: Settings → MCP servers → Add server. Enter a name, pick STDIO or Streamable HTTP, give the command or URL, save, then Restart.
- IDE extension: gear menu → MCP servers → Add server, same fields, then Restart extension.
Both lists show which servers need OAuth. Click Authenticate to sign in.
config.toml reference
For anything beyond the basics, edit the file. Each server is one table.
Stdio keys
| Key | What it does |
|---|---|
command (required) | The command that starts the server |
args | Arguments for that command |
env | Environment variables to set for the server |
env_vars | Variables to forward from your own environment |
cwd | Working directory to start in |
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
env_vars = ["LOCAL_TOKEN"]
[mcp_servers.context7.env]
MY_ENV_VAR = "MY_ENV_VALUE"
Streamable HTTP keys
| Key | What it does |
|---|---|
url (required) | The server address |
bearer_token_env_var | Env var whose value is sent as Authorization: Bearer |
http_headers | Static header values |
env_http_headers | Header values read from env vars |
http_headers_helper | A local command that prints headers as JSON, for short-lived tokens |
auth | oauth (default) for stored OAuth credentials |
[mcp_servers.figma]
url = "https://mcp.figma.com/mcp"
bearer_token_env_var = "FIGMA_OAUTH_TOKEN"
http_headers = { "X-Figma-Region" = "us-east-1" }
Keys for either transport
| Key | Default | What it does |
|---|---|---|
startup_timeout_sec | 10 | How long the server gets to start |
tool_timeout_sec | 60 | How long one tool call may run |
enabled | Set false to switch a server off without deleting it | |
required | Set true to make startup fail if the server isn't ready | |
enabled_tools / disabled_tools | Tool allow list and deny list (deny applied second) | |
default_tools_approval_mode | auto, prompt, writes or approve |
A slow server that times out on first start is the most common problem. Raise startup_timeout_sec before you debug anything else.
Bearer tokens, headers and OAuth
Got an API key? Keep it out of the file. Put it in an environment variable and point bearer_token_env_var (or --bearer-token-env-var) at it.
Server uses OAuth? Add it with --url, then sign in:
codex mcp login sentry
# SSH session or no local browser
codex mcp login sentry --no-browser
# Ask for specific scopes
codex mcp login sentry --scopes read,write
With --no-browser, open the printed URL, sign in, and paste the full redirect URL back into the terminal, even if the browser can't load the callback page.
Codex supports dynamic client registration and Client ID Metadata Documents. If the provider gave you a fixed client instead:
codex mcp add example --url https://mcp.example.com --oauth-client-id my-client
codex mcp add example --url https://mcp.example.com --oauth-client-id my-client --oauth-client-secret "$MCP_CLIENT_SECRET"
Codex saves that secret in config.toml, so keep the file private and out of git. Register the exact callback URL that codex mcp add prints. If the provider needs a fixed port, set mcp_oauth_callback_port globally or oauth.callback_port on one server.
Limit tools and approvals
Here's the part most setup guides skip. A server like GitHub exposes dozens of tools, and you rarely want Codex calling all of them without asking.
[mcp_servers.chrome_devtools]
url = "http://localhost:3000/mcp"
enabled_tools = ["open", "screenshot"]
default_tools_approval_mode = "prompt"
startup_timeout_sec = 20
tool_timeout_sec = 45
[mcp_servers.chrome_devtools.tools.open]
approval_mode = "approve"
output_token_limit = 30000
enabled_toolsexposes only the tools you list.default_tools_approval_mode = "writes"asks before any tool that isn't marked read-only. It's a sensible default for anything that touches production.tools.<tool>.output_token_limitcaps one noisy tool's output.
Convert a JSON config to Codex TOML
Most server READMEs give you this:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_TOKEN": "..." }
}
}
}
In Codex that becomes:
[mcp_servers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env_vars = ["GITHUB_TOKEN"]
Using env_vars forwards the token from your shell instead of writing it into the file. For a remote entry, "url" maps to url and "headers" maps to http_headers.
Rather not hand-write TOML? The MCP config generator produces the [mcp_servers] table from a URL or package name.
Good MCP servers for Codex
| Server | Use it for | Add it |
|---|---|---|
| Context7 | Current library docs | codex mcp add context7 -- npx -y @upstash/context7-mcp |
| Sentry | Errors and stack traces | codex mcp add sentry --url https://mcp.sentry.dev/mcp then codex mcp login sentry |
| Playwright | Drive and inspect a browser | codex mcp add playwright -- npx -y @playwright/mcp@latest |
| Figma | Read designs while you build | url = "https://mcp.figma.com/mcp" (see Figma's remote server docs) |
| GitHub | Issues, PRs, code search | codex mcp add github --url https://api.githubcopilot.com/mcp/ --bearer-token-env-var GITHUB_PAT |
Every remote URL above answered a live MCP request when we checked it on 1 December 2026. More servers, with connection details, are in the MCP server directory.
Test a server before Codex uses it
When a server fails in Codex you get a startup error and not much else. Checking it on its own first is quicker:
- Remote server: paste the URL into the MCP server tester to see the handshake, the auth it expects and every tool schema.
- How a GPT model handles it: Codex runs on OpenAI models, so open MCP with ChatGPT and OpenAI models or Agent Studio and watch a GPT model call your tools. If it picks the wrong tool there, it'll do the same in Codex, and the fix is in your tool descriptions.
- Local stdio server: run its command in a terminal first. If it prints anything other than JSON-RPC to stdout, it will break. See "Unexpected token" errors.
Troubleshooting
| Symptom | Fix |
|---|---|
| Server times out at startup | Raise startup_timeout_sec (default 10). First npx runs download packages and are slow. |
| Tool calls cut off after a minute | Raise tool_timeout_sec (default 60). |
| Project servers don't load | .codex/config.toml only loads in trusted projects. |
| Pasted JSON config does nothing | Codex reads TOML. Convert it as shown above. |
Server only offers an /sse URL | The docs only list stdio and streamable HTTP. Check whether the provider has a /mcp endpoint first. |
| OAuth redirect mismatch | Register the exact callback URL codex mcp add printed, or fix the port with mcp_oauth_callback_port. |
| 401 with a token | Check the env var named in bearer_token_env_var is set in the shell that started Codex. |
spawn npx ENOENT | Codex can't find Node on its PATH. See fix spawn npx ENOENT. |
Check an MCP server before you add it to Codex
Connect, list tools and call them in your browser. No install.
Open the MCP server tester →Frequently Asked Questions
Where is the Codex MCP config file?
~/.codex/config.toml for all projects, or .codex/config.toml inside a trusted project. MCP servers go in [mcp_servers.<name>] tables.How do I add an MCP server to Codex?
codex mcp add <name> -- <command> for a local server or codex mcp add <name> --url <url> for a remote one. In the desktop app or IDE extension, use the MCP servers settings page.Do the Codex CLI, IDE extension and desktop app share MCP servers?
config.toml, so a server added in one shows up in the others.Does Codex support OAuth for MCP servers?
codex mcp login <name>. Dynamic client registration, Client ID Metadata Documents and pre-registered clients (--oauth-client-id) are all supported.Can I stop Codex from calling write tools without asking?
default_tools_approval_mode = "writes" on the server. Codex then asks before any tool that isn't marked read-only. You can override single tools under tools.<tool>.approval_mode.Can Codex run as an MCP server?
codex mcp-server and the standalone codex-mcp-server binary were removed. OpenAI points to the Codex app server instead.Related
Written by Nikhil Tiwari
15+ years in product development. AI enthusiast building developer tools that make complex technologies accessible to everyone.
Free MCP Tools (no install)
Build, compare & ship MCP agents
Connect any MCP server, run evals on it, compare 90+ models side-by-side, deploy hosted servers, and save reusable agents you can export as an API — all in your browser.