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. 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-mcp
  2. 2. 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.com
  3. 3. 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. 4. Check it is connected

    List configured servers from the terminal, or type /mcp in the Codex TUI.

    codex mcp list
  5. 5. 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

Next steps

Sources