AI agents

Codex CLI

Codex CLI and MCP servers

How to connect an MCP (Model Context Protocol) server to Codex, in two minutes.

Add a server

Stdio server (a local command):

codex mcp add context7 -- npx -y @upstash/context7-mcp

Streamable HTTP server (a URL):

codex mcp add figma --url https://mcp.figma.com/mcp --bearer-token-env-var FIGMA_OAUTH_TOKEN

Manage servers:

codex mcp list [--json]            # list configured servers
codex mcp get <name> [--json]      # show one server's config
codex mcp remove <name>            # delete a definition
codex mcp login <name>             # OAuth login (streamable HTTP servers that support OAuth)
codex mcp logout <name>            # remove stored OAuth credentials

Servers are stored in ~/.codex/config.toml, so adding via CLI and editing the file directly are equivalent.

The config.toml form

[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
env_vars = ["LOCAL_TOKEN"]          # forward these env vars from your shell

[mcp_servers.context7.env]
MY_ENV_VAR = "MY_ENV_VALUE"         # set literal env vars

[mcp_servers.figma]
url = "https://mcp.figma.com/mcp"
bearer_token_env_var = "FIGMA_OAUTH_TOKEN"
http_headers = { "X-Figma-Region" = "us-east-1" }

A concrete example: Chrome DevTools with tuned timeouts and approvals

[mcp_servers.chrome_devtools]
url = "http://localhost:3000/mcp"
enabled_tools = ["open", "screenshot"]
default_tools_approval_mode = "prompt"
startup_timeout_sec = 20            # default 10
tool_timeout_sec = 45               # default 60

[mcp_servers.chrome_devtools.tools.open]
approval_mode = "approve"
output_token_limit = 30000

Other useful keys: enabled (toggle a server off without deleting it), required (fail startup — and make codex exec exit with an error — if the server can’t initialize), disabled_tools, and per-tool approval_mode (auto|prompt|writes|approve) and output_token_limit.

Notes

  • MCP servers can also be project-scoped in .codex/config.toml — applied only for trusted projects (see Codex CLI configuration).
  • Inside the TUI, /mcp lists configured tools; /mcp verbose shows server diagnostics.
  • Codex reads each server’s MCP instructions field as server-wide guidance.
  • Codex can also act as an MCP server for other tools: codex mcp-server (stdio).

Last verified: 2026-09-07

Official sources:

AI coding tools evolve quickly. If you find outdated information, please open an issue or pull request.