Guides › OpenAI Codex (CLI and IDE)

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)

  1. 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
  2. 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)

  1. Add a Streamable HTTP server
    codex mcp add linear --url https://mcp.linear.app/mcp
  2. Sign in or use a token
    For OAuth servers run codex mcp login NAME (add --no-browser on a machine without a browser). For API keys, point bearer_token_env_var at 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 = false turns a server off without deleting it. enabled_tools and disabled_tools limit which tools load.
  • Startup timeouts: see "MCP client timed out".
  • Since Codex 0.169.0 (November 13, 2026), codex exec keeps a project's config and MCP servers turned off in folders you haven't trusted, even with --sandbox workspace-write. Add --trust to codex exec or codex review to 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 = true on a server that must be ready at startup, or features.mcp_lazy_stdio_startup = false to start them all with the thread. Tab also completes /mcp arguments, for example /mcp lo to /mcp login.

Common problems in OpenAI Codex (CLI and IDE)

Sources

Weekly MCP digest
New servers, breaking changes, and fresh fixes. One email a week.