Guide coding-agents/
Codex CLI MCP config: config.toml, servers and approvals
Where Codex CLI keeps MCP servers, how to add stdio and Streamable HTTP servers, how OAuth sign-in works, and how per-tool approvals and admin allowlists apply.
Short answer
Codex CLI reads MCP servers from [mcp_servers.<name>] tables in ~/.codex/config.toml, or from a trusted project's .codex/config.toml. Add a local stdio server with codex mcp add <name> -- <command> or a Streamable HTTP server with codex mcp add <name> --url <url>, and sign in to OAuth servers with codex mcp login <name>. Each server's default_tools_approval_mode sets when Codex asks before calling one of its tools.
Checked against: OpenAI’s Model Context Protocol, Command line options, Configuration Reference, Config basics and Managed configuration pages, plus github.com/openai/codex, December 6, 2026.
Run by us: no. Commands are copied from OpenAI’s docs.
As of December 6, 2026, developers.openai.com/codex/mcp redirects to learn.chatgpt.com/docs/extend/mcp, so the links here use the new address.
How do I add an MCP server with the Codex CLI?
Run codex mcp add, which writes a server entry to ~/.codex/config.toml: give a command after -- for a stdio server, or --url for a Streamable HTTP server.
codex mcp add <server-name> --env VAR1=VALUE1 --env VAR2=VALUE2 -- <stdio server-command>
codex mcp add context7 -- npx -y @upstash/context7-mcp
codex mcp add example --url https://mcp.example.com --oauth-client-id my-client
codex mcp add flag |
What it does |
|---|---|
--env KEY=VALUE |
Sets a variable for a stdio server; repeatable |
--url https://… |
Registers a Streamable HTTP server instead of stdio |
--bearer-token-env-var ENV_VAR |
Sends that variable’s value as a bearer token |
--oauth-client-id CLIENT_ID |
Uses a pre-registered OAuth client; requires --url |
--oauth-resource RESOURCE |
Adds an OAuth resource parameter at login; requires --url |
OpenAI’s MCP page lists two transports: stdio servers started by a command, and Streamable HTTP servers reached at an address. SSE isn’t on the list. OpenAI also says the ChatGPT desktop app, Codex CLI and the IDE extension share this configuration, so a server added once is available in all three.
What does an mcp_servers table look like?
Each server is a TOML table named [mcp_servers.<server-name>]; stdio servers need command, and Streamable HTTP servers need url.
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
env_vars = ["LOCAL_TOKEN"]
[mcp_servers.context7.env]
MY_ENV_VAR = "MY_ENV_VALUE"
[mcp_servers.figma]
url = "https://mcp.figma.com/mcp"
bearer_token_env_var = "FIGMA_OAUTH_TOKEN"
http_headers = { "X-Figma-Region" = "us-east-1" }
| Key | Applies to | Notes from OpenAI’s docs |
|---|---|---|
command, args, cwd |
stdio | command is required |
env |
stdio | Variables to set for the server |
env_vars |
stdio | Variables to allow and forward from your environment |
url |
HTTP | Required |
bearer_token_env_var |
HTTP | Variable holding a bearer token for Authorization |
http_headers, env_http_headers |
HTTP | Static header values, or header values read from variables |
http_headers_helper |
HTTP | Local command that prints a JSON object of headers |
startup_timeout_sec |
Both | Default 10 |
tool_timeout_sec |
Both | Default 60 |
enabled |
Both | false disables without deleting |
required |
Both | true makes startup fail if the server isn’t ready |
If no credential source resolves for an HTTP server, Codex can connect without authentication, so a server that needs sign-in still requires codex mcp login.
Can I scope MCP servers to one project?
Yes: put the table in .codex/config.toml inside the repo, and Codex loads it only after you trust the project.
| Precedence (highest first) | Where |
|---|---|
CLI flags and --config overrides |
Command line |
| Project config | .codex/config.toml, closest to the working directory wins; trusted projects only |
| Profile | ~/.codex/profile-name.config.toml, selected with --profile profile-name |
| User config | ~/.codex/config.toml |
| Cloud-managed defaults | Delivered for the signed-in workspace |
| System config | /etc/codex/config.toml on Unix |
The CLI reference describes codex mcp as managing entries in ~/.codex/config.toml and documents no scope flag, so write project servers by hand. If you mark a project as untrusted, Codex skips its .codex/ layers, including project config, hooks and rules.
How does OAuth sign-in work?
Run codex mcp login <server-name> for a Streamable HTTP server that supports OAuth; Codex chooses a client registration method for you.
codex mcp login <server-name>
codex mcp login <server-name> --no-browser
codex mcp login <name> --scopes read,write
codex mcp login <server-name> --oauth-client-registration cimd
codex mcp login <server-name> --oauth-client-registration dcr
With --no-browser, open the printed URL elsewhere and paste the full redirect URL back into the terminal, even if the browser can’t load the callback page. codex mcp logout <name> removes stored credentials. To set scopes permanently, use mcp_servers.<server-name>.scopes in config.toml.
Codex supports Client ID Metadata Documents (CIMD) and dynamic client registration. The default is auto: CIMD when the authorization server advertises client_id_metadata_document_supported: true and meets OpenAI’s other listed conditions, otherwise DCR when available. A configured client ID skips registration. For a confidential client, OpenAI’s example reads the secret from a variable:
codex mcp add example --url https://mcp.example.com --oauth-client-id my-client --oauth-client-secret "$MCP_CLIENT_SECRET"
Codex saves that secret as mcp_servers.example.oauth.client_secret in config.toml; OpenAI says to keep the file private and out of version control. Register the exact callback URL codex mcp add prints, for example OAuth callback URL: http://127.0.0.1/callback.
| Setting | Purpose |
|---|---|
mcp_oauth_callback_port |
Fixed global listener port for the callback |
mcp_servers.<server-name>.oauth.callback_port |
Per-server listener port |
mcp_oauth_callback_url |
Custom callback path or remote ingress URL |
mcp_oauth_credentials_store |
auto, file or keyring |
Codex validates any returned iss before exchanging the code, and a mismatched iss always rejects the response. Background on the flow is in MCP authorization step by step.
How do I control approvals for MCP tools?
Set default_tools_approval_mode on the server, override it per tool under tools.<tool>.approval_mode, and narrow the tool list with enabled_tools and disabled_tools.
[mcp_servers.chrome_devtools]
url = "http://localhost:3000/mcp"
enabled_tools = ["open", "screenshot"]
disabled_tools = ["screenshot"] # applied after enabled_tools
default_tools_approval_mode = "prompt"
startup_timeout_sec = 20
tool_timeout_sec = 45
enabled = true
[mcp_servers.chrome_devtools.tools.open]
approval_mode = "approve"
output_token_limit = 30000
Both approval keys accept auto, prompt, writes and approve. OpenAI defines writes as prompting for tools that aren’t marked read-only. disabled_tools is applied after enabled_tools, so a tool in both lists is off. output_token_limit caps one tool’s output.
enabled_tools works as a per-server tool allow-list. All of these keys are separate from approval_policy (for example approval_policy = "on-request"), which controls when Codex pauses before running the commands it generates. Servers bundled in plugins take the same policy keys under plugins.<plugin>.mcp_servers.<server>.
How do admins limit which MCP servers Codex can enable?
Add an mcp_servers approved list to requirements.toml; per OpenAI, “the client enables an MCP server only when both its name and identity match an approved entry; otherwise, the client disables it.”
[mcp_servers.docs]
identity = { command = "codex-mcp" }
[mcp_servers.remote]
identity = { url = "https://example.com/mcp" }
The string form of identity.command matches only the command, not args, cwd, env or env_vars. To pin a full invocation, use the structured form:
[mcp_servers.internal.identity]
command = { executable = "/usr/local/bin/codex-mcp", args = [
{ match = "exact", value = "serve" },
{ match = "prefix", value = "--workspace=" },
] }
Argument and URL rules support exact, prefix and full-value regex matching. An mcp_servers table that is present but empty disables every MCP server.
Requirements load from lowest to highest priority: the system file (/etc/codex/requirements.toml on Linux and macOS, %ProgramData%\OpenAI\Codex\requirements.toml on Windows), Agent Security requirements from the cloud, legacy managed_config.toml fields, then macOS MDM through com.openai.codex:requirements_toml_base64.
How do I check what’s connected, and fix what isn’t?
List servers from the shell, then use /mcp inside the codex TUI.
codex mcp list
codex mcp list --json
codex mcp get <name> --json
In the TUI, /mcp lists active servers and tools, /mcp verbose adds server diagnostics, /mcp login <name> signs in from the session, and /debug-config prints config layers and the mcp_servers policy in force.
| Symptom | Likely cause | Fix |
|---|---|---|
| Project servers missing | Project not trusted | Trust it, or move the table to ~/.codex/config.toml |
| Server times out at startup | startup_timeout_sec default of 10 |
Raise it for that server |
| Server connects without credentials | No credential source resolved | codex mcp login <name> or bearer_token_env_var |
| Login rejected after redirect | Callback not registered exactly, or mismatched iss |
Register the callback codex mcp add printed |
| Server disabled | requirements.toml allowlist |
Check /debug-config, ask your admin |
Can Codex itself run as an MCP server?
No: OpenAI removed codex mcp-server and the standalone codex-mcp-server binary.
| Item | Status in OpenAI’s docs |
|---|---|
codex mcp-server |
Removed; PR #42993 merged September 5, 2026 |
codex-mcp-server binary |
Removed |
| Suggested replacement | Codex app server |
OpenAI says the app server “isn’t an MCP server or a drop-in replacement for an MCP client” and uses its own JSON-RPC protocol. It is marked experimental and not supported for production workloads. Codex still acts as an MCP client to external servers.
What to read next
Sources
Changelog
- First published.
Cite this page
Agents for Devs. "Codex CLI MCP config: config.toml, servers and approvals." Published Dec 6, 2026. https://agentsfordevs.com/guides/codex-cli-mcp - Page: https://agentsfordevs.com/guides/codex-cli-mcp
- Markdown version: https://agentsfordevs.com/guides/codex-cli-mcp.md
- Reuse: quote or summarize with a link to this page. Reuse terms
Cite one section
- How do I add an MCP server with the Codex CLI?
- What does an mcp_servers table look like?
- Can I scope MCP servers to one project?
- How does OAuth sign-in work?
- How do I control approvals for MCP tools?
- How do admins limit which MCP servers Codex can enable?
- How do I check what’s connected, and fix what isn’t?
- Can Codex itself run as an MCP server?
- What to read next