Based on OpenAI’s official docs, checked
How to add an MCP server to Codex
Codex keeps MCP servers in config.toml, and the Codex CLI, IDE extension and ChatGPT desktop app share that configuration, so you set a server up once.
1. Add a local (stdio) server
Put the server command after a double dash. Pass environment variables with --env.
codex mcp add context7 -- npx -y @upstash/context7-mcp2. Add a remote server
Pass the server URL. If the provider needs a pre-registered OAuth client, add --oauth-client-id.
codex mcp add example --url https://mcp.example.com3. Sign in with OAuth
For servers that use OAuth, start the login flow. Codex supports CIMD and dynamic client registration.
codex mcp login <server-name>4. Check it is connected
List configured servers from the terminal, or type /mcp in the Codex TUI.
codex mcp list5. Or edit config.toml
Each server is a [mcp_servers.<name>] table in ~/.codex/config.toml, or .codex/config.toml in a trusted project.
[mcp_servers.context7] command = "npx" args = ["-y", "@upstash/context7-mcp"]
Tips
- Use bearer_token_env_var or env_http_headers instead of hard-coding secrets.
- enabled_tools and disabled_tools limit which tools a server exposes; default_tools_approval_mode controls approvals.
- startup_timeout_sec (default 10) and tool_timeout_sec (default 60) help with slow servers.
- OpenAI notes that every MCP server adds context and uses more of your limit, so disable servers you are not using.
Next steps
Verified MCP servers for Codex
Generate an MCP config for Codex
OpenAI Codex hub
Claude Code vs OpenAI Codex: documented features compared
How to add an MCP server to Cursor
Sources
- https://developers.openai.com/codex/mcp · checked 2026-10-16
- https://developers.openai.com/codex/pricing · checked 2026-10-16