How to add MCP servers to OpenAI Codex (config.toml)
Codex keeps MCP servers in config.toml. The Codex CLI, the Codex IDE extension and the ChatGPT desktop app share this file, so you set a server up once.
Checked against the official docs on 2026-11-26. Apps change often; the sources are linked at the bottom.
Where the config file lives
| All projects | ~/.codex/config.toml |
| One project (trusted projects only) | .codex/config.toml |
| Top-level key | [mcp_servers.<name>] |
Add a local server (runs on your computer)
- Add a command (stdio) server
Put the server's command after--. Pass environment variables with--env.codex mcp add context7 -- npx -y @upstash/context7-mcp codex mcp add myserver --env API_KEY=your-key -- npx -y @example/mcp-server - Or edit config.toml
Each server is a[mcp_servers.NAME]table.[mcp_servers.context7] command = "npx" args = ["-y", "@upstash/context7-mcp"] startup_timeout_sec = 20 # default 10 tool_timeout_sec = 60 # default 60
Add a remote server (a URL)
- Add a Streamable HTTP server
codex mcp add linear --url https://mcp.linear.app/mcp - Sign in or use a token
For OAuth servers runcodex mcp login NAME(add--no-browseron a machine without a browser). For API keys, pointbearer_token_env_varat an environment variable.[mcp_servers.example] url = "https://mcp.example.com/mcp" bearer_token_env_var = "EXAMPLE_TOKEN"
Check and manage servers
codex mcp list
codex mcp --help
# inside the codex TUI: /mcp
Tips
enabled = falseturns a server off without deleting it.enabled_toolsanddisabled_toolslimit which tools load.- Startup timeouts: see "MCP client timed out".
- Since Codex 0.169.0 (November 13, 2026),
codex execkeeps a project's config and MCP servers turned off in folders you haven't trusted, even with--sandbox workspace-write. Add--trusttocodex execorcodex reviewto trust the folder. - Since Codex 0.172.0 (November 23, 2026), an optional stdio server with a cached tool list starts at its first tool call, not when the thread starts. Set
required = trueon a server that must be ready at startup, orfeatures.mcp_lazy_stdio_startup = falseto start them all with the thread. Tab also completes/mcparguments, for example/mcp loto/mcp login.
Common problems in OpenAI Codex (CLI and IDE)
- Codex: "MCP client for `server` timed out after 10 seconds"
- Remote MCP server says "Needs authentication" or 401 after it used to work
- Fix "spawn npx ENOENT" when starting an MCP server