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
安装
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/ -vResources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/benzkittisak/claude-codex-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server