Skip to main content

MCP server for Codex CLI with tmux persistence, git worktree isolation, and async dispatch.

Project description

codex-mcp-server

MCP server for Codex CLI — tmux persistence, git worktree isolation, async dispatch.

English | 简体中文


特性

  • tmux 持久化 — 所有任务运行在 tmux session 中,网络断开、窗口关闭后任务继续执行
  • git worktree 隔离full-access 模式自动创建独立 worktree,并行任务互不干扰
  • 阻塞 + 异步双模式codex 同步等待结果,codex_dispatch 立即返回后台运行
  • 多轮对话 (resume) — 通过 session_id 延续上一次 Codex 会话
  • 文件系统持久化 — 任务元数据存储在 ~/.codexmcp/tasks/,服务重启后可恢复
  • 工作区日志 — 自动在 <cwd>/.codex-tasks/ 创建 symlink,IDE 中直接查看日志

工具

工具 作用 适合场景
codex 阻塞执行,等待完成后返回结果 代码审阅、短任务、并行模块实现
codex_dispatch 后台分派,立即返回 task_id 长任务(数十分钟到数小时)
codex_status 查询任务状态和进度 追踪后台任务、获取结果
codex_cancel 取消运行中的任务 终止不需要的任务

前置要求

  • Python 3.12+
  • codex CLI 已安装且在 PATH 中
  • tmux 已安装(所有模式必须)
  • git 已安装(full-access 模式必须)
codex --version
tmux -V
git --version

安装

Claude Code

claude mcp add codex -s user --transport stdio -- \
  uvx codex-mcp-server

验证:

claude mcp list

Cursor / 通用 MCP 配置

{
  "command": "uvx",
  "args": ["codex-mcp-server"]
}

从 GitHub 源码安装(开发用)

pip install git+https://github.com/GuDaStudio/codexmcp.git

快速上手

1. 代码审阅(阻塞,只读)

{
  "tool": "codex",
  "arguments": {
    "prompt": "审阅 src/auth/ 目录的代码质量和安全性",
    "cwd": "/workspace/my-project",
    "topic": "review-auth",
    "sandbox": "read-only"
  }
}

2. 并行模块实现(阻塞,写入)

并发调用多个 codex,每个使用不同 topic

{
  "tool": "codex",
  "arguments": {
    "prompt": "实现用户注册模块...",
    "cwd": "/workspace/my-project",
    "topic": "impl-register",
    "sandbox": "full-access"
  }
}

每个 full-access 任务自动创建独立的 git worktree 和分支 agent/<topic>

3. 长任务后台分派

{
  "tool": "codex_dispatch",
  "arguments": {
    "prompt": "重构整个项目为异步架构...",
    "cwd": "/workspace/my-project",
    "topic": "refactor-async",
    "sandbox": "full-access"
  }
}

立即返回 task_id。之后用 codex_status 查看进度。

4. Resume 多轮对话

首次执行返回 session_id。修改代码后继续:

{
  "tool": "codex",
  "arguments": {
    "prompt": "我已修改了代码,请重新审阅",
    "cwd": "/workspace/my-project",
    "topic": "review-auth-r2",
    "sandbox": "read-only",
    "session_id": "thread_abc123"
  }
}

参数说明

参数 类型 必填 说明
prompt str 任务指令
cwd Path 工作目录(绝对路径)
topic str 任务标识。用于 tmux session 名、worktree 分支名、task_id
sandbox read-only / full-access 权限模式。read-only 不建 worktree;full-access 创建 worktree 隔离
session_id str 恢复之前的 Codex 会话(多轮对话)

返回结构

阻塞 codex 完成后返回:

{
  "success": true,
  "task_id": "codex-impl-feature",
  "session_id": "thread_abc123",
  "result": "Codex 的最终回复文本",
  "exit_code": 0,
  "elapsed_seconds": 45.2,
  "usage": {"input_tokens": 5000, "output_tokens": 1200},
  "worktree_dir": "/workspace/project-agent-impl-feature",
  "agent_branch": "agent/impl-feature",
  "base_branch": "main",
  "diff_stat": "3 files changed, 42 insertions(+), 10 deletions(-)",
  "commits_ahead": 2
}
  • session_id 用于 resume
  • worktree 相关字段仅 full-access 模式返回

环境变量

通过 MCP 服务进程环境变量配置:

变量 说明 示例
CODEX_PROFILE codex 配置文件名 fast
CODEX_REASONING_EFFORT 推理强度 highxhigh

日志

位置 路径
工作区 symlink <cwd>/.codex-tasks/<topic>/codex-exec.log
主存储 ~/.codexmcp/tasks/<task_id>/codex-exec.log
实时查看 tmux attach -t codex-<topic>

开发

git clone https://github.com/GuDaStudio/codexmcp.git
cd codexmcp
pip install -e .

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codex_mcp_server-1.0.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codex_mcp_server-1.0.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file codex_mcp_server-1.0.0.tar.gz.

File metadata

  • Download URL: codex_mcp_server-1.0.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for codex_mcp_server-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c6c3eec9541a30bac5770dadd8ecd7fe4f80f6a1991ef6b7968e953fac6f8fd7
MD5 3dd853c87f6a81a6674ceb86113ac643
BLAKE2b-256 0352a9c1597794d5a40d090ebd0aee559df19aa73c52c4cb518bba946630b5b5

See more details on using hashes here.

File details

Details for the file codex_mcp_server-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for codex_mcp_server-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e555a9219b162ebf1a2e2df83f2f487acc2020757f754897898e081a25bfa38
MD5 605c900193ea26e49450acbf8da5d2ef
BLAKE2b-256 eedba84e65d25b4ec9ed4ec14d50dab2a5b2b57550a9a904673db455a4da3747

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page