OpenAI Codex CLI is a lightweight coding agent that runs locally, providing multimodal inputs, rich approvals workflow, and terminal-based AI-assisted development
Model Context Protocol (MCP) server management allows you to add, remove, and configure external tools and capabilities for Codex CLI.
codex mcp [OPTIONS] [SUBCOMMAND]Run Codex as an MCP server for integration with other tools.
codex mcp serveList all configured MCP servers.
codex mcp list [OPTIONS]--json # Output server list as JSONShow details for a specific MCP server.
codex mcp get [OPTIONS] <NAME><NAME> # Name of the MCP server to display--json # Output server configuration as JSONAdd a new MCP server configuration.
codex mcp add [OPTIONS] <NAME> -- <COMMAND>...<NAME> # Name for the MCP server configuration
<COMMAND>... # Command to launch the MCP server--env <KEY=VALUE> # Environment variables to set when launching (can be used multiple times)Remove an MCP server configuration.
codex mcp remove <NAME><NAME> # Name of the MCP server configuration to remove# Run Codex as an MCP server
codex mcp serve# List all configured servers (table format)
codex mcp list
# List all configured servers (JSON format)
codex mcp list --json
# Add a simple server
codex mcp add docs-server -- python -m http.server 8000
# Add a server with environment variables
codex mcp add database-tool \
--env DATABASE_URL=postgresql://localhost/mydb \
--env API_KEY=secret123 \
-- db-mcp-server --port 3000
# Add a complex server with multiple args
codex mcp add file-processor \
--env WORKDIR=/tmp/processing \
--env MAX_WORKERS=4 \
-- python /path/to/processor.py --mode server --timeout 30
# Get server details (human-readable)
codex mcp get docs-server
# Get server details (JSON)
codex mcp get docs-server --json
# Remove a server
codex mcp remove docs-serverThe list command shows configured servers in table format:
Name Command Args Env
docs-server python -m http.server 8000 -
database-tool db-mcp-server --port 3000 DATABASE_URL=postgresql://localhost/mydb, API_KEY=secret123When using --json flag, output follows this structure:
[
{
"name": "docs-server",
"command": "python",
"args": ["-m", "http.server", "8000"],
"env": null,
"startup_timeout_ms": null
},
{
"name": "database-tool",
"command": "db-mcp-server",
"args": ["--port", "3000"],
"env": {
"API_KEY": "secret123",
"DATABASE_URL": "postgresql://localhost/mydb"
},
"startup_timeout_ms": null
}
]MCP server configurations are stored in ~/.codex/config.toml under the [mcp_servers] section:
[mcp_servers.docs-server]
command = "python"
args = ["-m", "http.server", "8000"]
[mcp_servers.database-tool]
command = "db-mcp-server"
args = ["--port", "3000"]
[mcp_servers.database-tool.env]
DATABASE_URL = "postgresql://localhost/mydb"
API_KEY = "secret123"Server names must:
my-server, tool_v2, server123my server, tool@home, über-toolEnvironment variables must be specified in KEY=VALUE format:
# Valid formats
--env DATABASE_URL=postgresql://localhost/mydb
--env PORT=3000
--env ENABLE_DEBUG=true
# Multiple environment variables
codex mcp add myserver \
--env VAR1=value1 \
--env VAR2=value2 \
-- command argsCommon error scenarios:
Once configured, MCP servers are automatically available in Codex sessions:
Install with Tessl CLI
npx tessl i tessl/npm-openai--codex