Connect MCP servers to Codex

Codex connects to MCP servers that run locally over STDIO or remotely over streamable HTTP. In the CLI, run codex mcp add <name> -- <command>. In the desktop app or IDE extension, open Settings, then MCP servers, then Add server. All three store servers in config.toml under [mcp_servers.<name>] and share the configuration.

Add a server from the CLI

codex mcp add <server-name> --env VAR1=VALUE1 -- <stdio server command>

For example, OpenAI’s docs use Context7, a documentation server:

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

Then use codex mcp list to see configured servers, codex mcp login <name> for OAuth servers, and /mcp inside the TUI.

Add a server in the desktop app or IDE extension

  1. Open Settings, or the gear menu in the extension, then MCP servers.
  2. Select Add server, choose STDIO or Streamable HTTP, and enter the command or URL.
  3. Save, then Restart the app or extension.

Configure in config.toml

STDIO server:

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

HTTP server with a bearer token taken from an environment variable:

[mcp_servers.figma]
url = "https://mcp.figma.com/mcp"
bearer_token_env_var = "FIGMA_OAUTH_TOKEN"

Useful per-server options include enabled, required, startup_timeout_sec (default 10), tool_timeout_sec (default 60), enabled_tools and disabled_tools, and default_tools_approval_mode, which takes auto, prompt, writes, or approve.

Be selective

Every MCP server adds tools that Codex can call. Connect servers you trust, limit them to the tools you need with enabled_tools, and set default_tools_approval_mode = "prompt" for anything that can write or send data. Keep secrets in environment variables, not in a config.toml you might commit.

Questions people ask

How do I see which MCP servers are active?

Run codex mcp list in a terminal, or type /mcp inside the Codex TUI or the desktop app composer.

A server needs OAuth. How do I log in?

Run codex mcp login <server-name>, or select Authenticate next to the server in the app or extension.

Sources

We link to the official source for every instruction on this page. If anything here disagrees with them, trust the official source and tell us.