---
title: "Codex CLI MCP config: config.toml, servers and approvals"
type: guide
url: https://agentsfordevs.com/guides/codex-cli-mcp
markdown: https://agentsfordevs.com/guides/codex-cli-mcp.md
publisher: Agents for Devs
author: Agents for Devs desk
reviewed_by: Agents for Devs desk
published: 2026-12-06
updated: 2026-12-06
license: https://agentsfordevs.com/reuse
citation: 'Agents for Devs. "Codex CLI MCP config: config.toml, servers and approvals." Published Dec 6, 2026. https://agentsfordevs.com/guides/codex-cli-mcp'
attribution: Credit Agents for Devs and link to https://agentsfordevs.com/guides/codex-cli-mcp
format: Guide
topics:
  - coding-agents
description: "Set up MCP servers in Codex CLI: codex mcp add, [mcp_servers] tables in config.toml, OAuth login, per-tool approval modes and requirements.toml allowlists."
---

# 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](https://learn.chatgpt.com/docs/extend/mcp?surface=cli), [Command line options](https://learn.chatgpt.com/docs/developer-commands?surface=cli), [Configuration Reference](https://learn.chatgpt.com/docs/config-file/config-reference), [Config basics](https://learn.chatgpt.com/docs/config-file/config-basic) and [Managed configuration](https://learn.chatgpt.com/docs/enterprise/managed-configuration) pages, plus [github.com/openai/codex](https://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](/glossary/stdio-transport), or `--url` for a Streamable HTTP server.

```bash
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](/glossary/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`.

```toml
[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.

```bash
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](/glossary/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:

```bash
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](/guides/mcp-oauth-flow).

## 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`.

```toml
[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](/glossary/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."

```toml
[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:

```toml
[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.

```bash
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](https://github.com/openai/codex/pull/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](/glossary/mcp-client) to external servers.

## What to read next

- [Claude Code MCP config](/guides/claude-code-mcp)
- [Gemini CLI MCP config](/guides/gemini-cli-mcp)
- [How coding agents ask permission](/guides/coding-agent-permissions)
- [MCP authorization step by step](/guides/mcp-oauth-flow)

## Sources

1. [Model Context Protocol, OpenAI](https://learn.chatgpt.com/docs/extend/mcp?surface=cli)
2. [Command line options, OpenAI](https://learn.chatgpt.com/docs/developer-commands?surface=cli)
3. [Configuration Reference, OpenAI](https://learn.chatgpt.com/docs/config-file/config-reference)
4. [Config basics, OpenAI](https://learn.chatgpt.com/docs/config-file/config-basic)
5. [Managed configuration, OpenAI](https://learn.chatgpt.com/docs/enterprise/managed-configuration)
6. [Codex MCP server removal, OpenAI](https://learn.chatgpt.com/docs/mcp-server)
7. [Remove the deprecated codex mcp-server command (#42993), OpenAI (GitHub) (2026-09-05)](https://github.com/openai/codex/pull/42993)

## Changelog

- 2026-12-06: 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: https://agentsfordevs.com/guides/codex-cli-mcp.md
- Reuse: quote or summarize with a link to the page. Terms: https://agentsfordevs.com/reuse
