If your Codex CLI configuration (~/.codex/config.toml or ~/.config/codex/config.toml) uses an env_key for a model provider, the MCP server must have access to that environment variable to pass it to the codex sub-process.
Example Configuration:
If your config defines env_key = "PROVIDER_API_KEY", you must ensure the environment variable PROVIDER_API_KEY is available to the MCP server.
Recommended: Set env in MCP Client Configuration
Add an env object to your MCP server configuration. This is the most secure method.
Alternative A: Pass via server startup arguments
Use the --env flag when running the server via uvx.
Alternative B: Use Codex CLI to add the MCP server
Use codex mcp add with the --env flag.
Security Note: Using command-line arguments (Alternative A and B) may expose your keys in the local process list. Method A (client configuration) is preferred.
{
"mcpServers": {
"codex-subagent": {
"type": "stdio",
"command": "uvx",
"args": ["codex-as-mcp@latest"],
"env": {
"PROVIDER_API_KEY": "KEY_VALUE"
}
}
}
}
uvx codex-as-mcp@latest --env PROVIDER_API_KEY=KEY_VALUE
codex mcp add codex-subagent --env PROVIDER_API_KEY=KEY_VALUE -- uvx codex-as-mcp@latest