What are MCP Servers?
MCP servers are processes that expose tools, resources, and prompts that Codex can use. They communicate over the Model Context Protocol, providing:- Custom tools - Extend Codex with domain-specific operations
- Resources - Provide access to external data sources
- Prompts - Add specialized prompt templates
- OAuth integration - Secure authentication for external services
Configuration Location
MCP servers are configured in~/.codex/config.toml under the [mcp_servers] section:
Server Transport Types
MCP servers can connect via two transport mechanisms:Stdio Transport (Local)
Run a local process that communicates over stdin/stdout:Streamable HTTP Transport (Remote)
Connect to a remote MCP server over HTTP:Configuration Options
Executable command to launch the MCP server (stdio only)
Arguments to pass to the command (stdio only)
URL for streamable HTTP MCP server (HTTP only)
Whether the server is enabled. Set to
false to disable without removing config.If
true, Codex will fail to start if this server cannot connectEnvironment variables to set when launching the server (stdio only)
List of environment variable names to inherit from parent process
Working directory for the server process (stdio only)
Environment variable containing bearer token for authentication (HTTP only)
Static HTTP headers to include in requests (HTTP only)
HTTP headers with values from environment variables (HTTP only)
Maximum time to wait for server startup (seconds)
Maximum time to wait for tool execution (seconds)
If set, only these tools are exposed (whitelist)
List of tools to disable (blacklist)
OAuth scopes to request during authentication
OAuth resource identifier for this server
Managing MCP Servers
Codex provides CLI commands for managing MCP server configurations:List Configured Servers
Add a Server
Get Server Details
Remove a Server
OAuth Authentication
Some MCP servers require OAuth authentication. Codex provides built-in OAuth flow support:Login to an MCP Server
- Open your browser to the OAuth authorization page
- Start a local callback server
- Receive the authorization code
- Exchange it for tokens
- Store credentials securely
Logout from an MCP Server
OAuth Credential Storage
Configure where OAuth tokens are stored:Where to store MCP OAuth credentials.Options:
"auto"- Prefer OS keyring, fallback to file"keyring"- Use OS keyring (most secure)"file"- Store in~/.codex/.credentials.json
OAuth Callback Configuration
Fixed port for OAuth callback server. When unset, uses ephemeral port.
Redirect URI to use in OAuth flow. Local listener still binds to 127.0.0.1.
Tool Control
Whitelist Specific Tools
Only enable specific tools from a server:Blacklist Specific Tools
Disable specific tools:If both
enabled_tools and disabled_tools are set, enabled_tools takes precedence (whitelist mode).Example Configurations
Filesystem MCP Server
Provide Codex access to local filesystem:GitHub MCP Server
Integrate with GitHub repositories:Slack MCP Server
Connect to Slack workspace:Database MCP Server
Query PostgreSQL databases:Custom HTTP MCP Server
Connect to a remote custom server:App-Level Tool Controls
Codex also provides app-level controls for MCP tools:Enable or disable the entire app/connector
Whether tools are enabled by default for this app
Default approval mode:
"auto", "prompt", or "approve"Allow tools marked as destructive
Allow tools with open world access hints
Troubleshooting
Server fails to start
Server fails to start
- Check that the command and args are correct
- Verify the executable is in PATH or use absolute path
- Check
startup_timeout_secif server is slow to start - Review server logs (set
DEBUG=mcp:*in env) - Ensure required environment variables are set
OAuth login fails
OAuth login fails
- Verify the server supports OAuth
- Check that callback port is not blocked by firewall
- Ensure browser can reach callback URL
- Try specifying a fixed port with
mcp_oauth_callback_port - Check server OAuth configuration and scopes
Tools not appearing
Tools not appearing
- Verify server is enabled (
enabled = true) - Check if tools are in
disabled_toolslist - If using
enabled_tools, ensure tools are listed - Verify server process is running successfully
- Check that server implements MCP protocol correctly
Tool execution timeouts
Tool execution timeouts
- Increase
tool_timeout_secfor slow operations - Check network connectivity for HTTP servers
- Review server implementation for performance issues
- Verify server is not rate-limited or throttled
Environment variables not working
Environment variables not working
- For stdio servers, use
envsection to set variables - For HTTP servers, use
env_http_headersfor header values - Check environment variable names for typos
- Verify variables are exported in your shell
- Use
env_varsto inherit specific parent environment variables
Security Considerations
Best Practices
- Review server code - Inspect open-source servers before use
- Use tool whitelisting - Enable only necessary tools with
enabled_tools - Disable destructive operations - Set
destructive_enabled = falsefor apps - Use OAuth when available - More secure than static API keys
- Store credentials securely - Prefer keyring over file storage
- Set timeouts - Prevent hung operations with
tool_timeout_sec - Monitor server logs - Watch for unexpected behavior
- Keep servers updated - Update MCP servers regularly
Complete Configuration Example
Next Steps
Configuration Reference
Complete reference of all configuration options
Building MCP Servers
Learn to build your own MCP servers