codex-as-mcp
Allows MCP clients to spawn autonomous Codex CLI agents from OpenAI for code generation and execution tasks.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@codex-as-mcp refactor the authentication module to use JWT"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
codex-as-mcp
codex-as-mcp is a small Model Context Protocol (MCP) server that lets MCP clients (Claude Code, Cursor, etc.) delegate work to the Codex CLI.
It exposes two tools that run Codex in the server's current working directory:
spawn_agent(prompt: str)spawn_agents_parallel(agents: list[dict])
Under the hood, each agent runs something like:
codex exec --cd <server cwd> --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox -.
The prompt is sent through stdin and then closed. This avoids command-line quoting/length issues and prevents Codex from accidentally reading from the MCP server's JSON-RPC stdin pipe.
Note: --dangerously-bypass-approvals-and-sandbox disables sandboxing and confirmation prompts. Use this server only in repos you trust.
Use it in Claude Code
There are two tools in codex-as-mcp

You can spawn parallel codex subagents using prompt.

Here's a sample Codex session delegating two tasks in parallel.

Related MCP server: codex-mcp
Quick start
1. Install Codex CLI
Requires Codex CLI >= 0.46.0
npm install -g @openai/codex@latest
codex login
# Verify installation
codex --versionMake sure Codex CLI can run non-interactively on your machine (provider + credentials in ~/.codex/config.toml, or via the provider-specific env var it references).
Example: third-party provider + env_key
If you're using a third-party provider, configure it in Codex config.toml and point model_provider at it. When a provider uses env_key, Codex CLI expects that env var to be present when it runs.
Example:
model_provider = "custom_provider"
[model_providers.custom_provider]
name = "custom_provider"
base_url = "https://..."
wire_api = "responses"
env_key = "PROVIDER_API_KEY"
show_raw_agent_reasoning = trueWhen using codex-as-mcp, make sure the MCP server process has that env var set, so it can pass it through to the spawned codex process. The env var name must match the env_key value above (here: PROVIDER_API_KEY).
Option A (recommended): set env in your MCP client config (if supported)
{
"mcpServers": {
"codex-subagent": {
"type": "stdio",
"command": "uvx",
"args": ["codex-as-mcp@latest"],
"env": {
"PROVIDER_API_KEY": "KEY_VALUE"
}
}
}
}Option B: pass env via server args
uvx codex-as-mcp@latest --env PROVIDER_API_KEY=KEY_VALUEOption C: add via Codex CLI (codex mcp add)
codex mcp add codex-subagent --env PROVIDER_API_KEY=KEY_VALUE -- uvx codex-as-mcp@latestSecurity note: passing secrets via command-line args may be visible via process lists on your machine; prefer option A when possible.
2. Configure MCP
Add to your .mcp.json:
{
"mcpServers": {
"codex-subagent": {
"type": "stdio",
"command": "uvx",
"args": ["codex-as-mcp@latest"]
}
}
}Or use Claude Desktop commands:
claude mcp add codex-subagent -- uvx codex-as-mcp@latestIf you're configuring Codex CLI directly (for example ~/.config/codex/config.toml), add:
[mcp_servers.subagents]
transport = "stdio"
command = "uvx"
args = ["codex-as-mcp@latest"]
# Increase if you see ~60s tool-call timeouts when running longer Codex tasks.
# tool_timeout_sec = 600Tools
spawn_agent(prompt: str)– Spawns an autonomous Codex subagent using the server's working directory and returns the agent's final message.spawn_agents_parallel(agents: list[dict])– Spawns multiple Codex subagents in parallel; each item must include apromptkey and results include either anoutputor anerrorper agent.
Maintainer live smoke test
The default CI uses unit tests and a fake subprocess path so it can run safely without credentials. Maintainers can additionally run the manually triggered Live Codex smoke GitHub Actions workflow with a real provider by setting repository secret CODEX_LIVE_API_KEY and providing a Responses-compatible base_url/model in the workflow inputs.
Note: current Codex CLI rejects wire_api = "chat"; chat-completions-only providers such as direct DeepSeek API need either native Codex support for that wire API or a Responses-compatible proxy.
Troubleshooting
spawn_agent times out after ~60s
If you see an error like:
tool call failed for `subagents/spawn_agent`
timed out awaiting tools/call after 60s
deadline has elapsedThis is typically a client-side MCP tool-call timeout. spawn_agent does not return until the spawned codex exec process finishes, which can take longer than 60 seconds.
Fix: increase the tool-call timeout in your MCP client.
Codex CLI
In your Codex config (~/.codex/config.toml or ~/.config/codex/config.toml), set a higher tool_timeout_sec for the MCP server:
[mcp_servers.subagents]
transport = "stdio"
command = "uvx"
args = ["codex-as-mcp@latest"]
tool_timeout_sec = 600MCP Inspector / mcp dev
If you're testing locally with the MCP Inspector, increase request timeouts (or run ./test.sh, which exports these):
export MCP_SERVER_REQUEST_TIMEOUT=300000
export MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS=true
export MCP_REQUEST_MAX_TOTAL_TIMEOUT=28800000Available Tools
2 toolsspawn_agentB
Spawn a Codex agent to work inside the current working directory.
The server resolves the working directory via ``os.getcwd()`` so it inherits
whatever environment the MCP process currently has.
Args:
prompt: All instructions/context the agent needs for the task.
Returns:
The agent's final response (clean output from Codex CLI).
Inputs: prompt (required). Returns: result
spawn_agents_parallelA
Spawn multiple Codex agents in parallel.
Each spawned agent reuses the server's current working directory
(``os.getcwd()``).
Args:
agents: List of agent specs, each with a 'prompt' entry.
Example: [
{"prompt": "Create math.md"},
{"prompt": "Create story.md"}
]
Returns:
List of results with 'index', 'output', and optional 'error' fields.
Inputs: agents (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The two tools are clearly distinguished by singular vs. parallel operation, with descriptions explicitly stating that spawn_agents_parallel handles multiple agents at once. However, both share the core 'spawn agent' purpose, so they could be confused if the agent doesn't read carefully.
Both tools use consistent snake_case with the verb 'spawn' followed by a noun, and the parallel tool adds a clear '_parallel' suffix. The naming pattern is predictable and easy to follow.
With only two tools, the server feels minimal. While the focus is narrow (spawning Codex agents), two tools is on the thin side and could arguably be combined into one with a loop.
The server covers the fundamental operations: spawning a single agent or multiple in parallel. Minor gaps include lack of configuration options (e.g., working directory or model), but these are not essential for the core purpose.
Maintenance
Related MCP Connectors
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
No-data MCP handoff for local Claude Code to Codex harness moves. $49 lifetime.
Hand tasks, bugs and finished work to AI coding agents, and get back a write-up with evidence.
Related MCP Servers
- AlicenseAqualityBmaintenanceEnables MCP clients like Claude Code and Codex to delegate coding tasks to Cursor's CLI agent, which implements changes in the workspace and returns clean, structured results for review.3462 npm9MIT
- AlicenseAqualityCmaintenanceEnables MCP-compatible coding agents to execute the local Codex CLI as a coding agent, including code reviews, session resume/fork, and CLI diagnostics.912 npmMIT
- FlicenseCqualityCmaintenanceEnables Codex to delegate already-scoped coding tasks to Claude Code and manage the resulting execution and fresh read-only review sessions, returning deterministic PASS/FAIL results through a local MCP interface.719-
- AlicenseAqualityBmaintenanceEnables Cursor's main agent to delegate development tasks to Claude CLI subagents via MCP, supporting synchronous, asynchronous, and parallel task execution with monitoring and control.7ISC