Getting Started·
beginner
·8 min read·Jul 10, 2026·Updated Oct 10, 2026
By Rad Tome·Lead AI Systems Architect·How we verify this

Configure MCP Servers in OpenAI Codex CLI

Complete 2026 config.toml setup, CLI commands, and troubleshooting for connecting MCP servers to OpenAI Codex CLI.

OpenAI CodexCodex MCPMCPConfigurationconfig.tomlSetup
Interactive Tool
1-Click Export

Generate & Validate Multi-Client MCP Config

One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.

Open in Generator

Configure MCP Servers in Codex CLI

Connecting the OpenAI Codex CLI to external tools, databases, and APIs relies on the Model Context Protocol (MCP). Codex manages server discovery and persistent tool registration through its centralized config.toml manifest, supporting both local child processes (stdio) and remote Server-Sent Events (sse) endpoints.

Prerequisites

  • ▸OpenAI Codex CLI (v2.0.0 or higher). Verify with codex --version.
  • ▸Node.js 18+ (for npx servers) or Python 3.10+ / uv (for uvx servers).
  • ▸Access to an active internet connection or local database instances.

Locating Your config.toml File

The Codex CLI reads its configuration from a centralized config.toml file. Depending on your operating system, locate or create this file in the following default directory:

  • ▸Windows: %USERPROFILE%\.codex\config.toml (or %APPDATA%\Codex\config.toml)
  • ▸macOS: ~/.codex/config.toml (or ~/Library/Application Support/Codex/config.toml)
  • ▸Linux: ~/.codex/config.toml (or ~/.config/codex/config.toml)

Tip: You can inspect your active config file path anytime by running:

bash
codex config path

TOML Configuration Schema

MCP servers in Codex CLI are defined under the [mcp_servers.<name>] table (the legacy [mcpServers.<name>] syntax is also supported for backward compatibility).

Base Structure

toml
[mcp_servers.<server_name>]
command = "executable"
args = ["arg1", "arg2"]

  [mcp_servers.<server_name>.env]
  KEY_NAME = "value"
FieldTypeRequiredDescription
commandstringYesThe executable binary to spawn (npx, node, uvx, python, docker).
argsarrayNoCommand-line arguments passed to the server process.
envtableNoSecure environment variables (tokens, credentials, connection strings).

How to Check Enabled MCP Servers in Codex

To inspect which MCP servers are currently enabled, active, or failing in your Codex CLI session, run:

bash
codex mcp list

Interpreting the Output

text
SERVER NAME       TRANSPORT   STATUS       TOOLS   RESOURCES
filesystem        stdio       Connected    5       2
github            stdio       Connected    7       0
postgres          stdio       Failed       0       0
  • ▸Connected: The MCP handshake (initialize -> initialized) succeeded. Tools are exposed to Codex and ready for autonomous invocation.
  • ▸Failed: The process crashed or timed out during handshake. Check logs immediately with codex mcp logs <server_name>.
  • ▸Disabled: The server is present in config.toml but toggled off or inactive.

To inspect specific tools exposed by a connected server:

bash
codex mcp tools github

Adding Servers via CLI One-Liners (codex mcp add)

Instead of editing config.toml manually, you can register servers dynamically from your terminal using codex mcp add:

bash
# Add GitHub MCP server with personal access token
codex mcp add --name github --command "npx -y @modelcontextprotocol/server-github" --env GITHUB_PERSONAL_ACCESS_TOKEN=ghp_your_token_here

# Add PostgreSQL MCP server with connection URL
codex mcp add --name postgres --command "npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@/mydb"

# Add Cloudflare MCP server
codex mcp add --name cloudflare --command "npx -y @cloudflare/mcp-server-cloudflare" --env CLOUDFLARE_API_TOKEN=your_token_here

Codex will validate the connection handshake immediately upon addition.


Production Config Recipes

Here are ready-to-copy snippets for the most requested MCP servers in OpenAI Codex CLI:

1. GitHub MCP Server (@modelcontextprotocol/server-github)

Allows Codex to create pull requests, read repository files, search code, and manage issues.

toml
[mcp_servers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]

  [mcp_servers.github.env]
  GITHUB_PERSONAL_ACCESS_TOKEN = "ghp_xxxxxxxxxxxxxxxxxxxx"

2. Cloudflare MCP Server (@cloudflare/mcp-server-cloudflare)

Deploy Workers, query D1 databases, manage KV namespaces, and inspect edge logs directly from Codex.

toml
[mcp_servers.cloudflare]
command = "npx"
args = ["-y", "@cloudflare/mcp-server-cloudflare"]

  [mcp_servers.cloudflare.env]
  CLOUDFLARE_API_TOKEN = "cf_token_xxxxxxxxxxxx"
  CLOUDFLARE_ACCOUNT_ID = "account_id_xxxxxxxxxxxx"

3. PostgreSQL MCP Server (@modelcontextprotocol/server-postgres)

Query database schemas, inspect tables, and execute read-only queries safely.

toml
[mcp_servers.postgres]
command = "npx"
args = [
  "-y",
  "@modelcontextprotocol/server-postgres",
  "postgresql://mcp_user:password@/production_db"
]

4. MySQL MCP Server (mysql-mcp-server)

toml
[mcp_servers.mysql]
command = "npx"
args = [
  "-y",
  "mysql-mcp-server@0.1.4",
  "mysql://user:password@/mydb"
]

There is no @modelcontextprotocol/server-mysql package. mysql-mcp-server provides read-only access and is maintained at github.com/dpflucas/mysql-mcp-server.

5. Local Filesystem MCP Server (@modelcontextprotocol/server-filesystem)

Gives Codex scoped read/write access to project directories without unbounded file access. Pass the absolute path to the directory you want to expose — narrow it to the specific project rather than your home directory:

toml
[mcp_servers.filesystem]
command = "npx"
args = [
  "-y",
  "@modelcontextprotocol/server-filesystem@2026.8.31",
  "/absolute/path/to/your-project"
]

6. Community Codex Server (@nothing1024/codex-mcp-server)

For community extensions and custom agent tools:

toml
[mcp_servers.codex-bridge]
command = "npx"
args = ["-y", "@nothing1024/codex-mcp-server"]

Troubleshooting "Codex CLI Giving MCP Errors"

1. spawn npx ENOENT (Executable Not Found)

  • ▸Symptom: codex mcp list shows Failed with Error: spawn npx ENOENT.
  • ▸Cause: Codex CLI is running in a shell environment where npx or node is not in the system PATH.
  • ▸Fix: On Windows, specify the full absolute path to npx.cmd:
    toml
    command = "C:\\Program Files\\nodejs\\npx.cmd"
    On macOS/Linux:
    toml
    command = "/usr/local/bin/npx"

2. Server Crashes or Exits Immediately

  • ▸Symptom: Server starts but immediately transitions to Failed.
  • ▸Diagnosis: Run codex mcp logs <server_name> to view stderr output.
  • ▸Common Fix: Missing required environment variables. Verify token names match the server spec exactly (e.g. GITHUB_PERSONAL_ACCESS_TOKEN, not GITHUB_TOKEN).

3. Restarting an MCP Server

When updating config.toml or rotating API credentials, reload the server without restarting Codex:

bash
codex mcp restart <server_name>

To reload all servers at once:

bash
codex mcp reload

Interactive Workbench & Config Generator

Generate tailored multi-client configurations for Claude, Cursor, Windsurf, and OpenAI Codex CLI in one click using our interactive tools:

Technical Changelog

Weekly Protocol Diffs & Verified Drops

New server guides, benchmarks, and security audits. No spam. Unsubscribe anytime.

Zero marketing spam. 1-click unsubscribe anytime.

Ready to Deploy?

Build your full agent toolstack in the Visual Generator

Combine Configure with databases, search APIs, and memory graphs in a single configuration file.

Customize in Generator
Developer Verification & Feedback
0 reports

Did this setup guide work with your AI host?

Help test this configuration across Claude, Cursor, and Codex CLI. Be the first to report:

Configure MCP Servers in OpenAI Codex CLI FAQ

What is the Configure MCP Servers in OpenAI Codex CLI?

Complete 2026 config.toml setup, CLI commands, and troubleshooting for connecting MCP servers to OpenAI Codex CLI.

How do I configure Configure MCP Servers in OpenAI Codex CLI in Claude Desktop or Cursor?

You can copy the configuration JSON from our guide or launch the interactive MCP Codex Config Generator at https://mcp-codex.com/generator to export valid configs in 1 click.

Can I use Configure MCP Servers in OpenAI Codex CLI with the OpenAI Codex CLI?

Yes, OpenAI Codex CLI supports Model Context Protocol. You can add it directly to ~/.codex/config.toml or pass arguments to codex mcp add.

RT

Written by Rad Tome

Lead AI Systems Architect & Maintainer, MCP Codex

@RadTome

Specializing in Model Context Protocol (MCP) integrations, autonomous AI agent orchestration, and distributed developer toolchains. Researches and benchmarks production MCP client-server architectures across OpenAI Codex, Claude, and Cursor.

Editorial Integrity: Package names are checked against the npm registry and repositories against the GitHub API. Where a package could not be verified, the guide says so instead of giving you a command to run.

Related Guides