Codex MCP: How to Add an MCP Server to Codex CLI

· 0x.cloud Team

Codex MCP: How to Add an MCP Server to Codex CLI

Codex MCP setup takes one command: codex mcp add <name> --url <url> for a remote server, or codex mcp add <name> -- <command> for a local one. Codex saves the server to ~/.codex/config.toml, and the next session can use its tools. Check it with codex mcp list in your shell or /mcp inside Codex.

Below: the syntax from the official Codex docs, the config.toml format, and a working example with the 0x.cloud MCP server, which lets Codex price and create a VPS on its own.

On this page: commands · config.toml · manage · 0x.cloud example · troubleshooting

Codex MCP add: the commands

Remote server (Streamable HTTP):

# name, URL, and the env var that holds the token
codex mcp add my-api --url https://mcp.example.com/mcp --bearer-token-env-var MY_API_KEY

--bearer-token-env-var stores only the variable name. On each request Codex puts its value into the Authorization: Bearer header.

Remote server with OAuth. Add it without a token. If the server supports OAuth, codex mcp add prints "Detected OAuth support" and opens the sign-in in your browser. To sign in again, or on a machine without a browser:

codex mcp add example --url https://mcp.example.com
codex mcp login example --no-browser

With --no-browser, Codex prints a URL. Open it on your laptop, sign in, and paste the full redirect URL back into the terminal, even if the page fails to load. Codex supports Dynamic Client Registration (DCR) and CIMD, so most servers don't need a pre-registered app.

Local server (stdio). Everything after -- is the server's launch command:

codex mcp add context7 -- npx -y @upstash/context7-mcp
# env vars for the server process
codex mcp add airtable --env AIRTABLE_API_KEY=your_key -- npx -y airtable-mcp-server

Codex CLI MCP config in config.toml

Anything codex mcp add does, you can write by hand in ~/.codex/config.toml:

# remote server, key read from the environment
[mcp_servers.0x-cloud]
url = "https://0x.cloud/v1/mcp"
bearer_token_env_var = "OX_API_KEY"
startup_timeout_sec = 20   # default 10
tool_timeout_sec = 60      # default 60

# local server
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]

[mcp_servers.context7.env]
MY_ENV_VAR = "value"

Keys worth knowing:

Key What it does
url, bearer_token_env_var HTTP server URL and the env var with its token
http_headers, env_http_headers extra headers (literal values or env var names)
command, args, env, cwd how to launch a local server
startup_timeout_sec, tool_timeout_sec startup and per-call timeouts
enabled switch a server off without deleting it
enabled_tools, disabled_tools allow list and deny list of tools
default_tools_approval_mode when to ask first: auto, prompt, writes (only tools not marked read-only), approve
env_vars which environment variables to forward to a local server
required fail startup if this server isn't ready

Per-project config. A .codex/config.toml at the repo root adds servers for that project only, and only once you've marked the project as trusted. Keep keys out of it: use bearer_token_env_var.

Check and manage servers

codex mcp list               # all servers and their settings
codex mcp get 0x-cloud       # one server in detail (--json for scripts)
codex mcp logout 0x-cloud    # drop stored OAuth tokens (if you used OAuth)
codex mcp remove 0x-cloud    # delete it from the config

Inside a codex session, /mcp lists active servers. The Codex CLI, the IDE extension and the ChatGPT desktop app share one MCP configuration, so setup carries over.

Example: the 0x.cloud MCP server in Codex

With the 0x.cloud MCP server, Codex can check prices, create servers and read your balance, and it works inside a server without SSH: run_command, read_file, write_file, snapshots. Which tools it sees depends on the permissions you grant. The full list is on the 0x.cloud MCP server page. You create the 0x.cloud account; Codex acts on your behalf.

Option 1: OAuth sign-in (recommended). No key needed:

codex mcp add 0x-cloud --url https://0x.cloud/v1/mcp
# headless VPS: codex mcp login 0x-cloud --no-browser

On the 0x.cloud sign-in page you choose the permissions, monthly spend cap, expiry and "own servers only" yourself. The grant shows up in your dashboard as a regular key, where you can edit or revoke it.

Option 2: an API key. Good for scripts and machines where a browser sign-in is awkward.

  1. Create a dedicated key for Codex in your dashboard. A new key defaults to servers.*: it can delete servers and run commands on them as root. Keep servers.read and servers.create (dry_run needs it), remove servers.delete and servers.exec unless you need them, and set a monthly spend cap such as $20. Only the owner can change permissions and the cap later, in the dashboard.
  2. Put the key in your environment, not your shell history:
read -s OX_API_KEY && export OX_API_KEY

To have it in every session, keep it in a mode 600 file as shown in how to store API keys on a server.

  1. Add the server:
codex mcp add 0x-cloud --url https://0x.cloud/v1/mcp --bearer-token-env-var OX_API_KEY

To have Codex ask you before any tool that changes something, add default_tools_approval_mode = "writes" under [mcp_servers.0x-cloud]: 0x.cloud tools carry read-only and destructive hints.

Start codex, check /mcp, and give it a task:

Prompt for an AI agent

Using the 0x.cloud MCP server, run a dry_run for an s2-4 server with Ubuntu 24.04, hourly billing and ttl_hours 5, show me the exact price and wait for my approval. Then create it with the same pricing_fingerprint, wait until it's ready and print the server details.

dry_run returns the exact price and a pricing_fingerprint valid for 10 minutes, and creates nothing. If the price changes in that window, the create call returns 409 price_changed and Codex should ask you again. An s2-4 (2 vCPU, 4 GB RAM) costs $15.99/mo or about $0.109520 an hour: a 5-hour test runs about $0.55, and ttl_hours deletes the server for you. The spend cap stops Codex from creating anything new past the limit, but an hourly server that already exists keeps billing, so set the timer or delete it yourself. Deleting returns the unused balance.

Want Codex running 24/7 instead of on your laptop? Install it on a VPS with Codex CLI on Ubuntu, or start from a ready Codex VPS. Also using Claude Code? Its syntax differs: MCP server in Claude Code.

Troubleshooting Codex MCP

Symptom Cause and fix
server fails to start, timeout raise startup_timeout_sec (default 10 seconds)
401 Unauthorized the bearer_token_env_var variable isn't set in the shell that launched codex, or the key was revoked
bearer_token is not supported for streamable_http the token itself is in the config (bearer_token = "..."): switch to bearer_token_env_var
403 insufficient_scope from 0x.cloud the key lacks a permission, such as servers.create for dry_run: add it in the dashboard
402 key_spend_limit_reached the key's spend cap is used up: only the owner can raise it in the dashboard, so retrying won't help
server in .codex/config.toml not loaded the project isn't marked as trusted
long tool call gets cut off raise tool_timeout_sec (default 60 seconds)
codex mcp login can't open a browser on a server add --no-browser and paste the redirect URL by hand

Codex MCP FAQ

Where is the Codex MCP config? In ~/.codex/config.toml, under [mcp_servers.<name>] tables. A project can also have its own .codex/config.toml, which Codex only loads for trusted projects.

How do I pass an API key to an MCP server in Codex? For an HTTP server, set bearer_token_env_var to the name of an environment variable such as OX_API_KEY. The key itself never goes in config.toml; Codex reads it from the environment at startup.

Do Codex MCP servers work in the IDE extension? Yes. The Codex CLI, the IDE extension and the ChatGPT desktop app on the same machine share one MCP configuration, so a server added in one shows up in the others.

Can I use Codex as an MCP server for Claude Code? Not anymore: the codex mcp-server command has been removed. OpenAI points integrations to the Codex app server, which uses its own JSON-RPC protocol rather than MCP. Adding external MCP servers to Codex with codex mcp still works.

What does it cost to try the 0x.cloud MCP server with Codex? Connecting and a dry_run quote create nothing. An hourly s2-4 then costs about $0.109520 an hour (about $0.55 for 5 hours), runs in Warsaw, and deleting it returns the unused balance.