codex-async-mcp
codex-async-mcp
本地 MCP 服务器,异步封装 codex CLI — 立即返回 job_id 而不是阻塞,因此 Claude 永远不会触发 MCP 协议超时 (-32001)。
要求
Python 3.11+
已安装
codexCLI 并位于$PATH中 (v0.125.0+)Claude Code CLI
Related MCP server: codex-mcp-server
安装
cd ~/payroll-mcp # or wherever this repo lives
pip install -e ".[dev]"验证:
python -c "from codex_async_mcp.server import mcp; print(mcp.name)"
# → codex-async-mcp注册到 Claude
全局(所有项目)
claude mcp add codex-async -s user -- python -m codex_async_mcp.server仅限项目
cd ~/payrollservice-thailand # or any project
claude mcp add codex-async -- python -m codex_async_mcp.server验证
claude mcp list
# codex-async: python -m codex_async_mcp.server - ✓ Connected添加工具权限 (settings.local.json)
{
"permissions": {
"allow": [
"mcp__codex-async__codex_start",
"mcp__codex-async__codex_poll",
"mcp__codex-async__codex_list",
"mcp__codex-async__codex_cancel"
]
}
}工具
工具 | 描述 |
| 在后台启动 codex → 立即返回 |
| 检查状态 + 输出尾部日志 |
| 列出最近的任务(最新的在前) |
| 终止正在运行的任务 |
approval_policy 值
值 | Codex 标志 | 行为 |
|
| 只读沙盒,不进行写入 |
|
| 自动应用编辑 |
|
| 无提示,无沙盒 |
对于 Claude 自动化,请始终使用 full-auto — suggest 模式会等待交互式输入,而这在子进程中永远不会发生。
使用示例
codex_start(
prompt="In app/services/prorate_calculation_service.rb line 96, change format(...) to number_to_currency(...)",
cwd="/Users/bbgummybear/payrollservice-thailand",
approval_policy="full-auto"
)
# → { job_id: "f3a9b2", status: "running", pid: 12345 }
codex_poll(job_id="f3a9b2")
# → { status: "running", output: "Reading file..." }
codex_poll(job_id="f3a9b2")
# → { status: "done", exit_code: 0, output: "Applied changes to prorate_calculation_service.rb" }任务状态
任务存储在 ~/.codex-async/jobs/{job_id}/ 中:
~/.codex-async/jobs/f3a9b2/
meta.json ← status, pid, timestamps, exit_code
output.txt ← stdout + stderr from codexmeta.json 结构:
{
"job_id": "f3a9b2",
"status": "running | done | error | cancelled",
"prompt": "...",
"cwd": "/path/to/repo",
"approval_policy": "full-auto",
"pid": 12345,
"started_at": "2026-04-29T10:00:00+00:00",
"finished_at": null,
"exit_code": null
}故障排除
claude mcp list 中出现 codex-async: ... - ✗ Failed
找不到 Python 或包未安装在正确的环境中。
# Check which python Claude is using
which python
# If using conda, register with the full path
claude mcp add codex-async -s user -- /Users/bbgummybear/miniconda3/bin/python -m codex_async_mcp.server
# Verify the package is installed in that environment
/Users/bbgummybear/miniconda3/bin/python -c "import codex_async_mcp; print('ok')"codex_start 后立即出现 status: "error"
Codex 启动失败。检查原始输出:
cat ~/.codex-async/jobs/<job_id>/output.txt常见原因:
输出消息 | 修复 |
|
|
| Codex 版本 < 0.125.0 — 运行 |
|
|
status: "running" 持续存在,永不结束
子进程挂起(等待输入或陷入循环)。
# Check if the process is still alive
ps aux | grep codex
# Check live output
tail -f ~/.codex-async/jobs/<job_id>/output.txt
# Cancel the job
codex_cancel(job_id="<job_id>")最常见的原因:使用了 approval_policy="suggest",它会暂停等待交互式批准。请改用 "full-auto"。
服务器重启后任务显示 status: "running"
MCP 服务器在重启时丢失了内存中的 Popen 注册表。下一次 codex_poll 调用将检测到 PID 已死并自动更新状态。
codex_poll(job_id="<job_id>")
# → { status: "done", ... } ← auto-resolved on first poll旧任务占满磁盘
# View all jobs sorted by date
ls -lt ~/.codex-async/jobs/
# Delete jobs older than 7 days
find ~/.codex-async/jobs -maxdepth 1 -type d -mtime +7 -exec rm -rf {} +项目结构
codex-async-mcp/
├── README.md
├── pyproject.toml
├── src/
│ └── codex_async_mcp/
│ ├── __init__.py
│ ├── server.py # MCP entry point, tool definitions
│ ├── job_manager.py # spawn / poll / cancel / list
│ └── config.py # JOBS_DIR, CODEX_BIN, defaults
└── tests/
└── test_job_manager.py运行测试
pytest tests/ -vAvailable Tools
4 toolscodex_cancelA
Cancel a running codex job by sending SIGTERM to the subprocess.
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes | The job_id returned by codex_start. |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden. It discloses that cancellation is done by sending SIGTERM to the subprocess, which is a key behavioral trait. It does not cover edge cases like job already finished, but the main behavior is well communicated.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single 12-word sentence, front-loaded with the action, and contains no wasted words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's simplicity (one parameter, single action), the description is nearly complete. It could mention what happens if the job is not running, but the output schema likely handles error responses.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema already describes the only parameter (job_id) with 100% coverage. The description adds no new semantic information beyond what the schema provides.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb ('Cancel') and resource ('running codex job'), and clearly distinguishes from siblings like codex_list, codex_poll, and codex_start.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implicitly states when to use (to cancel a running job with a job_id from codex_start) but does not explicitly state when not to use or provide alternative scenarios. However, the simplicity of the action mitigates the need for extensive guidelines.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
codex_listA
List recent codex jobs with their status and prompt summaries.
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Max number of jobs to return (most recent first). Default: 20. |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations provided, so description carries full burden. It only states it lists jobs with status and summaries, but lacks details on pagination, ordering (though limit param says 'most recent first'), rate limits, or side effects. The description is too minimal for full transparency.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Single sentence, no redundant words, front-loaded with the core action. Every word earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the presence of an output schema (status and prompt summaries mentioned), the description is somewhat complete for a simple list operation. However, it lacks details on error handling, empty results, or additional behavioral context that would fully inform an agent.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100% for the single parameter 'limit', and the schema itself provides a description including default and ordering. The tool description adds no extra meaning beyond what the schema already conveys.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Clearly states the tool lists recent codex jobs, including status and prompt summaries. The verb 'list' and resource 'recent codex jobs' are specific and distinguish from sibling tools (cancel, poll, start) which are different actions.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No explicit guidance on when to use or avoid this tool. The purpose is implied by the name and description, but no alternatives or exclusions are mentioned. Siblings have distinct purposes, so usage is inferred but not clarified.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
codex_pollA
Poll the status and output of a running (or finished) codex job.
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes | The job_id returned by codex_start. | |
| tail_lines | No | How many trailing lines of output to return. Default: 100. |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The description states the purpose but lacks details on behavioral traits such as whether the tool is idempotent or safe to call repeatedly. Since annotations are absent, the description carries the burden, and it only provides minimal transparency.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, front-loaded sentence with no extraneous words. It efficiently conveys the tool's purpose.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the presence of an output schema, the description does not need to explain return values. It covers the essential purpose and scope, though it could mention that the tool can be called multiple times safely.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, and the description adds no additional meaning beyond what the schema already provides for the two parameters. The description's mention of 'output' hints at tail_lines, but this is redundant with the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'Poll' and the resource 'status and output of a running (or finished) codex job', which is specific and distinguishes it from sibling tools like codex_start, codex_cancel, and codex_list.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage after a job is started, but does not explicitly provide when-not-to-use or alternatives. The context is clear enough for an agent to infer appropriate usage.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
codex_startA
Start a codex task asynchronously in the background.
Returns a job_id immediately — does not block or timeout. Use codex_poll(job_id) to check progress.
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The task description to pass to codex. | |
| cwd | Yes | Absolute path to the working directory for codex. | |
| approval_policy | No | One of 'suggest', 'auto-edit', 'full-auto'. Default: 'suggest'. | suggest |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations provided, so description carries full burden. Discloses async, non-blocking, immediate return of job_id. Does not mention side effects or auth, but core behavior is adequately covered.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences, no wasted words. Front-loaded with purpose and key behavior. Highly efficient.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Has output schema. Describes async nature and returns job_id. Could mention cancellation via sibling codex_cancel, but sufficient for a simple start tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so baseline 3. Description does not add meaning beyond schema; each parameter is defined in schema. No extra context provided.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Clearly states the verb 'Start', resource 'codex task', and key behavior 'asynchronously in the background'. Distinguishes from siblings by mentioning that codex_poll is used to check progress.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Provides explicit guidance to use codex_poll for progress checking. Implicitly tells when to use this tool (async tasks) but lacks explicit when-not-to-use or alternatives beyond polling.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
4 tool updates
v0.1.0- First observed
codex_cancel - First observed
codex_list - First observed
codex_poll - First observed
codex_start
TDQS
Scored across 4 tools
Each tool has a distinct purpose: start, list, poll, and cancel. There is no overlap in functionality, and the descriptions clearly differentiate them.
All tools follow a consistent 'codex_verb' pattern using snake_case, making it predictable for an agent to infer tool behavior from the name.
Four tools cover the essential operations for managing async jobs (start, list, poll, cancel) without redundancy or missing critical actions.
The tool set covers the full lifecycle of an async job: initiating (start), monitoring (poll, list), and termination (cancel). No obvious gaps are present.
Maintenance
Related MCP Connectors
Hosted MCP server for task-first delegation to remote workstations and workers.
MCP server for the FFmpeg Micro video transcoding API — create, monitor, download transcodes.
MCP server for mandates, delegation, policy-gated execution, credential grants, and audit.
Personal assistant MCP server with search, execute, packages, jobs, secrets, and integrations.
Related MCP Servers
- AlicenseAqualityDmaintenanceMCP server for Codex CLI — tmux persistence, git worktree isolation, async dispatch.470 PyPI1MIT
- AlicenseNot gradedqualityDmaintenanceWraps OpenAI Codex CLI as an MCP server, exposing 8 Codex tools (exec, review, skill list, skill run, status, poll, list jobs, kill) as named tools for use with pi or codex.949 npmISC
- AlicenseAqualityAmaintenanceMCP server that wraps Codex CLI as a subprocess, exposing code execution, web search, and structured output as Model Context Protocol tools.865 npm3MIT
- AlicenseNot gradedqualityAmaintenanceA local STDIO MCP server that bridges MCP clients to the Codex CLI by sending instructions to a configured workspace, exposing task run, status, and result tools with a read-only sandbox and no remote transport.133MIT