# Codex MCP server setup

To add an MCP server to Codex, run codex mcp add with the server name and its start command or URL, or add a [mcp_servers.name] table to ~/.codex/config.toml. Then run codex mcp list, or type /mcp inside Codex, to see that it loaded. The form below writes both for you.

Use the tool: https://agentshandbook.com/tools/codex-mcp-config (runs in the browser).

## How to use it

1. **Describe the server.** Pick a preset, or enter a name and either the command that starts a local server or the URL of a remote one. Write secrets as ${NAME} so the key stays in your environment.
2. **Run the command or paste the TOML.** Run the codex mcp add command in your terminal, or paste the TOML into ~/.codex/config.toml. Use .codex/config.toml in the repo when the server is for one trusted project only.
3. **Check that Codex loaded it.** Run codex mcp list in your shell, or type /mcp inside the Codex TUI to see the active servers. Start a new Codex session after you edit the file by hand.

## Questions

### How do I add an MCP server to Codex?

Run codex mcp add name -- command args for a local server, for example codex mcp add context7 -- npx -y @upstash/context7-mcp. For a remote server, run codex mcp add name --url https://example.com/mcp. Both write a [mcp_servers.name] table to ~/.codex/config.toml.

### How do I check which MCP servers are enabled in Codex?

Run codex mcp list in your terminal to see every configured server. Inside the Codex TUI, type /mcp to see the servers that are active in this session. A server with enabled = false stays in config.toml but does not start.

### Where is the Codex MCP config file?

Codex keeps MCP servers in ~/.codex/config.toml. You can also scope a server to one repo in .codex/config.toml, which Codex reads only in trusted projects. The Codex CLI, the IDE extension and the ChatGPT desktop app share this configuration, so you set a server up once.

### How do I pass an API key to a Codex MCP server?

For a local server, env sets values and env_vars forwards variables that already exist in your shell, so the key never sits in the file. For a remote server, bearer_token_env_var names the variable that holds the token, and env_http_headers maps headers to variables. For OAuth servers, run codex mcp login name.

### Why does my MCP server time out when Codex starts?

Codex waits 10 seconds for a server to start and 60 seconds for a tool call by default. A first npx download can take longer. Raise startup_timeout_sec or tool_timeout_sec in the server's table, or install the package once before you start Codex.

### Can I paste a Claude or Cursor mcp.json into Codex?

No. Codex reads TOML, and a JSON mcpServers block does not load. Paste your JSON into the checker on this page, then copy the Codex output, which is the same server as a [mcp_servers.name] table.

### Can Codex itself run as an MCP server?

Not any more. OpenAI's CLI reference says the codex mcp-server command and the standalone codex-mcp-server binary have been removed, and points to the Codex app server instead. Guides that still show codex mcp-server are out of date.

## Sources

- [Codex: Model Context Protocol](https://developers.openai.com/codex/mcp) (checked 2026-11-12)
- [Codex CLI command line reference (codex mcp, codex mcp-server)](https://developers.openai.com/codex/cli/reference) (checked 2026-11-12)

## Related playbooks

- [Test your local web app in a real browser and fix console errors in one loop](https://agentshandbook.com/p/test-local-web-app-in-browser-and-fix-console-errors.md)
- [Triage a production error from Sentry or logs into a tested fix pull request](https://agentshandbook.com/p/triage-production-error-into-a-fix-pr.md)
- [Map an unfamiliar codebase into a checked architecture document before you change it](https://agentshandbook.com/p/map-an-unfamiliar-codebase-before-you-change-it.md)

## Lessons

- [Scheduled agents break quietly when a connector or node version changes](https://agentshandbook.com/lessons/connector-updates-silently-break-scheduled-agents.md)

More free tools: https://agentshandbook.com/tools.md