codex-mcp

codex-mcp

Bridges Claude Code and OpenAI Codex CLI for an interactive plan-execute-review workflow, enabling Claude to interview, design, and review while Codex implements code changes.

Category
访问服务器

README

codex-mcp

CI

MCP server bridging Claude Code and OpenAI Codex CLI for a plan → execute → review workflow:

  1. Interview — Claude clarifies requirements with you
  2. Design & Planning — Claude explores the codebase and writes .codex-flow/PLAN.md
  3. Execution — Codex implements the plan (codex_execute)
  4. Review — Claude reviews the diff and sends findings back into the same Codex session (codex_continue)

Architecture

Claude Code ──(MCP stdio)──▶ codex-mcp (this server)
                                 │ spawns
                                 ▼
                            codex exec --json  (OpenAI Codex CLI)

The server spawns codex exec non-interactively, parses its JSONL event stream, and returns structured results: sessionId, agentMessage, fileChanges, commands, token usage, errors.

Tools

Tool Purpose Key inputs
codex_execute Start a new Codex session executing a task/plan prompt, cwd, sandbox, model?, timeoutMs?, terminal?
codex_continue Resume a session with follow-up (e.g. review feedback) sessionId, prompt, cwd, sandbox, timeoutMs?, terminal?
codex_review Read-only review of uncommitted workspace changes cwd, focus?, model?, timeoutMs?, terminal?
codex_health Check Codex CLI version and login status

Sandbox modes: read-only, workspace-write (default), danger-full-access. codex_review always runs read-only and never modifies files. Default execution timeout: 30 minutes (timeoutMs caps at 2 hours).

Result payload

Every run tool returns structured JSON: sessionId, agentMessage, fileChanges, commands, token usage, errors, plus:

  • diff — the workspace's git status --porcelain and git diff HEAD after the run (patch capped at 64 KB, truncated flag set when cut), so the caller can review changes without re-reading files. null when the cwd is not a git repo.
  • abortedtrue when the run was cancelled from the client (e.g. Esc in Claude Code). The server forwards MCP cancellation to Codex (SIGTERM, then SIGKILL after 5 s). On macOS/Linux the signal goes to Codex's whole process group, so subprocesses it spawned die too; on Windows only the CLI process itself is killed.
  • liveLog — path to the raw JSONL event log when the live terminal view was enabled.

Progress streaming

Clients that send an MCP progressToken (Claude Code does) receive notifications/progress for every meaningful Codex event — session start, file changes, command runs, turn completion — so progress is visible in-session on every platform, even without the terminal window below.

Concurrency

Runs are serialized per workspace: a second codex_execute/codex_continue/codex_review into the same cwd while one is active fails fast with a clear error instead of racing on files and git state. Different workspaces run in parallel fine.

Live progress in a Terminal window

Long Codex runs are otherwise invisible (the MCP call only returns when Codex finishes). Set terminal: true on codex_execute / codex_continue — or export CODEX_MCP_TERMINAL=1 — and the server streams Codex's event stream to <cwd>/.codex-flow/live/<timestamp>.jsonl and opens a terminal window that pretty-tails it — Terminal.app on macOS, a PowerShell window on Windows:

[17:23:22] ● session started: 019f4b…
[17:23:40] ✎ 3 file(s): src/fb_crawler/metrics.py, tests/test_metrics.py, pyproject.toml
[17:24:05] ▸ $ pytest  (exit 0)
[17:24:12] ✓ turn complete (in:27599 out:147)

The structured MCP result is unchanged; the terminal is a best-effort side view (a failed/unavailable viewer never fails the run). The result payload always includes a liveLog path to the raw JSONL, so on platforms without a supported terminal (e.g. Linux) you can tail it yourself.

Platform support

Works on macOS, Windows, and Linux. The Codex run itself is fully cross-platform; the live-progress terminal window is opened per-OS:

OS How the window opens Notes
macOS open -a Terminal <.command> (LaunchServices) Avoids the Apple Events / Automation (TCC) permission that silently blocks osascript from an MCP server. Verified.
Windows powershell.exe … Start-Process No TCC-style gate on Windows. Codex CLI installs as codex.cmd (auto-selected). Mechanism implemented; validate on your Windows host.
Linux first installed emulator (gnome-terminal, konsole, xterm, kitty, alacritty, …) Detected via command -v. If none is found (headless / SSH), no window opens. Mechanism implemented; validate on your distro.

If a window can't open (headless, SSH, missing permission, unknown emulator), the run still succeeds — follow progress via the liveLog path in the result or the in-session MCP progress notifications.

  • CODEX_BIN overrides the Codex binary path/name on any OS (e.g. CODEX_BIN=C:\tools\codex.exe).
  • CODEX_MCP_TERMINAL=1 opens the window by default without passing terminal: true per call.

Prerequisites

  • Node.js ≥ 20
  • OpenAI Codex CLI, authenticated:
    npm i -g @openai/codex
    codex login          # ChatGPT Plus/Pro/Team — or set OPENAI_API_KEY
    

First-time check (if you cloned the repo): run the doctor — it verifies Node, Codex CLI install + login, and Claude Code CLI install, and prints the exact fix for anything missing:

npm run doctor

/codex-flow also re-checks Codex login at the start of every run (Phase 0) and stops with instructions instead of burning a session when you're not logged in.

Security note: this server never reads, stores, or transmits your credentials. Authentication is handled entirely by the Codex CLI itself (~/.codex/); the server just spawns the codex binary and inherits whatever session the CLI already has.

Install as a Claude Code plugin (recommended for teams)

The repo doubles as a Claude Code plugin marketplace bundling the /codex-flow command (interview → plan/architecture → backlog → Codex executes per task → Claude reviews) and the codex MCP server (via npx @anhnguyen0905/codex-mcp). In Claude Code:

/plugin marketplace add anhnguyen0905/codex-mcp
/plugin install codex-flow@codex-mcp

Restart Claude Code when prompted, then run /codex-flow <feature description> in any project. Prerequisite stays the same: Codex CLI installed and logged in (see below).

Install (standalone, one command)

No clone, no build — npx fetches and builds it automatically. Same command on macOS, Windows, and Linux:

# from npm
claude mcp add --scope user codex -- npx -y @anhnguyen0905/codex-mcp

# or straight from this git repo
claude mcp add --scope user codex -- npx -y github:anhnguyen0905/codex-mcp

Verify: claude mcp list should show codex … ✔ Connected. To enable the live terminal by default, export CODEX_MCP_TERMINAL=1 in your shell profile.

For the full workflow command, copy commands/codex-flow.md to ~/.claude/commands/ — or skip both steps entirely and use the plugin install above, which bundles the server and the command.

Usage

In any Claude Code session:

/codex-flow implement dark mode toggle for the settings page

(The slash command lives at ~/.claude/commands/codex-flow.md.)

Or call tools directly: ask Claude to "use codex_execute to ..." — remember to keep the returned sessionId for follow-ups.

Note: long Codex runs can exceed Claude Code's MCP tool timeout. If a call is killed early, raise MCP_TOOL_TIMEOUT (env var, ms) when starting Claude Code.

Development

npm test          # unit tests (vitest)
npm run coverage  # enforces 80% thresholds
npm run test:e2e  # real end-to-end smoke test (spawns real Codex, uses quota)
npm run build     # tsc → dist/

Source layout:

  • src/argsBuilder.ts — validates input, builds codex exec / codex exec resume argv
  • src/codexRunner.ts — spawns the CLI with timeout + kill handling
  • src/eventParser.ts — folds the JSONL event stream into a CodexResult
  • src/server.ts — MCP tool registration (@modelcontextprotocol/sdk), cwd lock, cancellation wiring
  • src/index.ts — stdio entrypoint
  • src/terminal.ts — cross-platform live-progress terminal launcher (macOS/Windows)
  • src/liveView.ts — streams the event log to disk and opens the viewer
  • src/progressFormatter.ts — turns JSONL events into human-readable lines
  • src/progressNotifier.ts — line-buffers stdout into MCP notifications/progress
  • src/workspaceDiff.ts — captures git status + git diff HEAD for the result payload
  • scripts/tail-progress.mjs — the pretty-tail script the terminal window runs

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选