YouTip LogoYouTip

Codex Mcp

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 enables standardized interaction between AI models and external tools and services. Through MCP servers, you can extend Codex's capabilities: !(#) * Connect to file system * Access databases * Integrate project management tools * Call external APIs > MCP is built on the open (https://modelcontextprotocol.io/), supporting 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: !(#) ### Configuration File Location MCP servers are configured in the `mcp_servers` section of `~/.codex/config.toml`. ### stdio Type Servers ## Configure 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 Servers ## Configure HTTP MCP Server [mcp_servers.docs] # MCP HTTP server endpoint url = "https://docs.example.com/mcp" # HTTP headers to include http_headers = { Authorization = "Bearer token" } * * * ## MCP Tool Configuration ### Limit Available Tools You can limit the tools exposed by MCP servers: ## Tool Whitelist/Blacklist [mcp_servers.filesystem] # List of allowed tools enabled_tools = ["read_file", "write_file", "list_directory"] # List of denied tools (applied after enabled_tools) disabled_tools = > Using tool restrictions can improve security by only exposing the tools you need. ### Timeout Configuration ## Configure Timeout [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 parameter 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" # HTTP headers populated 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" # Credentials storage location mcp_oauth_credentials_store = "keyring" # file | keyring | auto * * * ## MCP Tool Permissions You can set permissions for each tool of each MCP server separately: ## Configure Tool Permissions [mcp_servers.docs.tools.search] # Permission mode: ask | approve | deny approval_mode = "approve" | Permission Mode | Description | | --- | --- | | `ask` | Ask before each execution (default) | | `approve` | Auto-approve | | `deny` | Auto-deny | > Be careful when configuring tool permissions, ensuring you only grant auto-approval permissions 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 servers npm search @modelcontextprotocol/server # Install MCP servers npm install -g @modelcontextprotocol/server-filesystem > OpenAI officially provides various MCP servers. Check the (https://github.com/modelcontextprotocol/servers) for the complete list. * * * ## Troubleshooting ### Server Startup Failure 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 the credentials storage configuration is correct. > Use `codex --verbose` to view detailed MCP debugging information. * * * ## FAQ ### Q: MCP server cannot start? Check if the command is correctly installed and try running the command manually to confirm there are no errors. ### Q: Where to configure tool permissions? Configure in the `mcp_servers..tools.` section of the configuration file. ### Q: How to disable an MCP server? Add `enabled = false` in the configuration or delete the configuration directly. ### Q: How many MCP servers are supported? There is no strict limit, but it is recommended to only configure the servers you actually need.
← Codex NoninteractiveCodex Subagents β†’