Codex MCP Server Configuration
MCP (Model Context Protocol) allows Codex to integrate with external tools and services.
This section details how to configure and use MCP servers.
What is MCP?
MCP is an open protocol that allows AI models to interact with external tools and services in a standardized way. Through MCP servers, you can extend Codex's capabilities:
- Connect to the file system
- Accessing the Database
- Integrate project management tools
- Call external APIs
MCP is built on the open Model Context Protocol and supports standardized integration across different tools.
MCP Basic Configuration
Codex Configuration Menu
You can manage or add MCP services through the settings menu:

Connect to custom MCP:

Config file locations
MCP servers are configured in the ~/.codex/config.toml 's mcp_servers section.
stdio Type Server
Configure a stdio MCP server
[mcp_servers.filesystem]
Server startup command
command = "npx"
Arguments passed to the command
args = ["-y", "@modelcontextprotocol/server-filesystem", "./docs"]
Server working directory
cwd = "/path/to/workdir"
Pass environment variables
env = {
NODE_ENV = "production"
}
HTTP Type Server
Configure an HTTP MCP server
[mcp_servers.docs]
MCP HTTP server endpoint
url = "https://docs.example.com/mcp"
Included HTTP headers
http_headers = {
Authorization = "Bearer token"
}
MCP Tool Configuration
Restrict available tools
You can restrict the tools exposed by an MCP server:
Tool allowlist/denylist
[mcp_servers.filesystem]
Allowed tool list
enabled_tools = ["read_file", "write_file", "list_directory"]
Denied tool list (applied after enabled_tools)
disabled_tools = ["delete_file"]
Using tool restrictions can improve security by exposing only the tools you need.
Timeout Configuration
Configure timeouts
[mcp_servers.slow_server]
command = "python"
args = ["-m", "slow_server"]
Startup timeout (seconds, default 10)
startup_timeout_sec = 30
Per-tool call timeout (seconds, default 60)
tool_timeout_sec = 120
MCP Authentication Configuration
OAuth Configuration
Configure OAuth
[mcp_servers.protected]
url = "https://api.example.com/mcp"
Requested OAuth scopes
scopes = ["read", "write"]
OAuth resource parameters
oauth_resource = "codex-integration"
Bearer token environment variable
bearer_token_env_var = "EXAMPLE_API_TOKEN"
HTTP Header Configuration
Configure HTTP headers
[mcp_servers.api]
url = "https://api.example.com/mcp"
Populate HTTP headers from environment variables
env_http_headers = {
X_API_KEY = "MY_API_KEY"
}
Static HTTP headers
http_headers = {
X_Custom_Header = "value"
}
OAuth Callback Configuration
Configure OAuth callback
Fixed callback port
mcp_oauth_callback_port = 8080
Custom callback URL
mcp_oauth_callback_url = "https://my-devbox.example.com/callback"
Credential storage location
mcp_oauth_credentials_store = "keyring" # file | keyring | auto
MCP tool permissions
You can set permissions individually for each MCP server's tools:
Configure Tool Permissions
[mcp_servers.docs.tools.search]
Permission mode: ask | approve | deny
approval_mode = "approve"
| Permission modes | Description |
|---|---|
ask |
Ask before each execution (default) |
approve |
Auto-approve |
deny |
Automatically reject |
Be careful when configuring tool permissions, and ensure you only grant auto-approval to tools you trust.
Common MCP servers
File System Server
File System MCP
[mcp_servers.filesystem]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "./docs"]
GitHub Server
GitHub MCP
[mcp_servers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = {
GITHUB_PERSONAL_ACCESS_TOKEN = "your-token-here"
}
PostgreSQL Server
PostgreSQL MCP
[mcp_servers.postgres]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:pass@localhost/db"]
Common MCP servers
You can install more MCP servers via npm:
# Search MCP server
npm search @modelcontextprotocol/server
# Install MCP server
npm install -g @modelcontextprotocol/server-filesystem
OpenAI officially provides a variety of MCP servers; see GitHub repository for the complete list.
Troubleshooting
Server fails to start
Check the following:
- Whether the command and arguments are correct
- Whether necessary dependencies are installed
- Whether environment variables are set correctly
Tool call timeout
Increase the timeout:
tool_timeout_sec = 120
Authentication issues
Ensure the OAuth callback port is not occupied and credential storage is configured correctly.
Use
codex --verboseYou can view detailed MCP debugging information.
Common questions
Q: The MCP server fails to start?
Check whether the command is installed correctly, and try running the command manually to confirm there are no errors.
Q: Where are tool permissions configured?
In the configuration file's mcp_servers. section.
Q: How do I disable a specific MCP server?
Add to the configuration enabled = false or simply delete the configuration.
Q: How many MCP servers are supported?
There is no strict limit, but it is recommended to configure only the servers you actually need.