Model Context Protocol (original) (raw)

Model Context Protocol (MCP) is a protocol for connecting models to additional tools and context. It’s a great option for you to provide Codex access to documentation for different libraries or have it interact with some of your other developer tools like your browser or Figma.

MCP servers are supported by both the Codex CLI and the Codex IDE extension.

MCP configuration for Codex is stored within the ~/.codex/config.toml configuration file alongside other Codex configuration options.

Configuration is shared between the CLI and the IDE extension. So once you have configured your MCP servers, you can seamlessly switch between the two Codex clients.

To configure your MCP servers, you have two options:

  1. Using the CLI: If you have the Codex CLI installed, you can use the codex mcp command to configure your MCP servers.
  2. Modifing the config file directly: Alternatively, you can modify the config.toml file directly.

Configuration - CLI

Add a MCP server

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

For example, to add Context7 (a free MCP server for developer documentation), you can run the following command:

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

Other CLI commands

To see all available MCP commands, you can run codex mcp --help.

Terminal UI (TUI)

Once you have launched codex and are running the TUI, you can use /mcp to see your actively connected MCP servers.

Configuration - config.toml

For more fine grained control over MCP server options, you can manually edit the ~/.codex/config.toml configuration file. If you are using the IDE extension, you can find the config file by clicking the gear icon in the top right corner of the extension and then clicking MCP settings > Open config.toml.

Each MCP server is configured with a [mcp_servers.<server-name>] table in the config file.

STDIO servers

Streamable HTTP servers

Other configuration options

config.toml Examples

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

[mcp_servers.context7.env]
MY_ENV_VAR = "MY_ENV_VALUE"
[features]
rmcp_client = true

[mcp_servers.figma]
url = "https://mcp.figma.com/mcp"
bearer_token_env_var = "FIGMA_OAUTH_TOKEN"
http_headers = { "X-Figma-Region" = "us-east-1" }
[mcp_servers.chrome_devtools]
url = "http://localhost:3000/mcp"
enabled_tools = ["open", "screenshot"]
disabled_tools = ["screenshot"] # applied after enabled_tools
startup_timeout_sec = 20
tool_timeout_sec = 45
enabled = true

There is an ever growing list of useful MCP servers that can be helpful while you are working with Codex.

Some of the most common MCPs we’ve seen are:

Additionally, to connecting Codex to MCP servers, you can also run Codex as an MCP server. This way you can connect it to other MCP clients such as an agent you are building using the OpenAI Agents SDK.

To start Codex as an MCP server, you can use the following command:

codex mcp-server

You can launch a Codex MCP server with the Model Context Protocol Inspector:

npx @modelcontextprotocol/inspector codex mcp-server

Send a tools/list request and you will see that there are two tools available:

codex - Run a Codex session. Accepts configuration parameters matching the Codex Config struct. The codex tool takes the following properties:

Property Type Description
prompt (required) string The initial user prompt to start the Codex conversation.
approval-policy string Approval policy for shell commands generated by the model: untrusted, on-failure, never.
base-instructions string The set of instructions to use instead of the default ones.
config object Individual config settings that will override what is in $CODEX_HOME/config.toml.
cwd string Working directory for the session. If relative, resolved against the server process’s current directory.
include-plan-tool boolean Whether to include the plan tool in the conversation.
model string Optional override for the model name (e.g. o3, o4-mini).
profile string Configuration profile from config.toml to specify default options.
sandbox string Sandbox mode: read-only, workspace-write, or danger-full-access.

codex-reply - Continue a Codex session by providing the conversation id and prompt. The codex-reply tool takes the following properties:

Property Type Description
prompt (required) string The next user prompt to continue the Codex conversation.
conversationId (required) string The id of the conversation to continue.

Trying it Out

Codex often takes a few minutes to run. To accommodate this, adjust the MCP inspector’s Request and Total timeouts to 600000ms (10 minutes) under ⛭ Configuration.

Use the MCP inspector and codex mcp-server to build a simple tic-tac-toe game with the following settings:

Property Value
approval-policy never
sandbox workspace-write
prompt Implement a simple tic-tac-toe game with HTML, Javascript, and CSS. Write the game in a single file called index.html.

Click “Run Tool” and you should see a list of events emitted from the Codex MCP server as it builds the game.