Skip to main content
Glama

Agent-CodexCLI-MCP-SKILL

English | 简体中文

Agent-CodexCLI-MCP-SKILL (MCP server & Skill identifier: agent-codexcli) is an MCP server and Agent Skill that lets any MCP-compatible AI agent orchestrate your local OpenAI Codex CLI as an execution engine — with session reuse, async polling, mid-flight steering, bounded process-tree cleanup, Git diff tracking, and quota safeguards.

Features

  • Session Reuse (session_id): Resume existing Codex threads (codex exec resume) to preserve conversation context, prompt cache, and saved session permissions (unless explicitly overridden).

  • Async Execution & Progress Notifications: Long-running tasks return a lightweight running payload (task_id, status, session_id, elapsed_ms) once wait_seconds elapses, emitting MCP progress notifications every 15 seconds when the client supplies a progressToken. Poll with codex_wait or check via codex_status.

  • Foreground Live Terminal Viewer opens by default when a desktop terminal is available. Pass foreground: false to run in the background.

  • Incremental Conversational Output appears in new_messages on running and terminal summaries. codex_status can peek at unread updates between polls.

  • Mid-Flight Steering (codex_steer): Interrupt an active run (once its session_id is available) and immediately resume the same session_id with updated instructions (mode: "interrupt", default), or enqueue a follow-up (mode: "queue").

  • Focused Reviews (codex_review): Run codex exec review (read-only by default; accepts a sandbox override) against uncommitted changes, a base branch, a specific commit, or custom instructions.

  • Process-Tree & Pipe Cleanup: Terminates Codex and child processes on Windows (taskkill + CIM creation-time bounds) and POSIX (detached process group -pid), with bounded pipe-drain timeouts so leaked descriptors cannot hang callers.

  • Safe Executable Discovery & Git Summaries: Resolves git and codex from trusted absolute PATH entries (ignoring working-directory/relative PATH entries and disabling core.fsmonitor), and captures baseline snapshots before writable runs for best-effort changed_files and git_diff_stat reporting.

  • Quota & Reset-Card Safeguards: Automatically stops tasks on HTTP 429 or structured/text quota exhaustion (status: "rate_limited") and includes a best-effort prompt guard against accidental /usage or quota reset-card triggers.

Related MCP server: codex-app-server-mcp

Prerequisites

  • Node.js >= 22.0.0

  • Git on PATH (required for snapshot-based change reporting and Git tests)

  • Codex CLI (@openai/codex) installed locally and authenticated (for example via codex login or your configured provider in ~/.codex/config.toml)

Installation & Build

git clone https://github.com/ZqwerR/Agent-CodexCLI-MCP-SKILL.git
cd Agent-CodexCLI-MCP-SKILL
npm install
npm run build

MCP Client Setup

Interactive Configuration Wizard

Run npm run setup from the source checkout, or agent-codexcli setup if the CLI is installed. Press Enter to keep the displayed value. The wizard saves viewer settings, wait budgets, the sandbox for new runs, model and reasoning effort overrides, and the reset-card guard. It prints a ready-to-paste mcp_config.json snippet that points to dist/index.js and the selected config file.

The precedence is per-call arguments > environment variables > config.json > built-in defaults. The server reads the file at startup. Restart your MCP server after changing saved settings.

  • Windows uses %APPDATA%/agent-codexcli/config.json and falls back to %LOCALAPPDATA%/agent-codexcli/config.json.

  • On macOS and Linux, an absolute XDG_CONFIG_HOME selects $XDG_CONFIG_HOME/agent-codexcli/config.json. Otherwise the path is ~/.config/agent-codexcli/config.json.

  • CODEX_CONFIG_PATH selects a different file. Use agent-codexcli setup --config <path> to select one from the wizard.

  • Use agent-codexcli setup --show to see the saved and effective server settings, or agent-codexcli setup --reset to delete the saved file. With npm, pass flags after --, as in npm run setup -- --show.

Generic MCP Client

Add agent-codexcli to your MCP client configuration (replace /path/to/Agent-CodexCLI-MCP-SKILL with your cloned directory):

{
  "mcpServers": {
    "agent-codexcli": {
      "command": "node",
      "args": ["/path/to/Agent-CodexCLI-MCP-SKILL/dist/index.js"]
    }
  }
}

Installing the Agent Skill

Copy skills/agent-codexcli to your agent's skills directory (for example ~/.agents/skills/agent-codexcli or ~/.gemini/config/skills/agent-codexcli) so your orchestrator agent follows the recommended workflow automatically.


Antigravity Setup & Best Practices

Antigravity uses a 180-second (3m0s) default per-call MCP timeout and exposes timeoutSeconds in server configuration. Choose the Antigravity preset in the wizard or set both wait budgets to 165 seconds in ~/.gemini/config/mcp_config.json as shown below. This leaves room for launch, Git snapshot, and interrupt steering overhead.

{
  "mcpServers": {
    "agent-codexcli": {
      "command": "node",
      "args": ["C:/path/to/Agent-CodexCLI-MCP-SKILL/dist/index.js"],
      "env": {
        "CODEX_DEFAULT_WAIT_SECONDS": "165",
        "CODEX_DEFAULT_POLL_WAIT_SECONDS": "165"
      }
    }
  }
}
  • For strict host deadlines, pass wait_seconds: 0 to get task_id immediately, then poll with bounded codex_wait(task_id, wait_seconds: 150).

  • Avoid passing wait_seconds >= 180 inside Antigravity unless you also raised timeoutSeconds in mcp_config.json.

  • Copy skills/agent-codexcli to ~/.gemini/config/skills/agent-codexcli to enable /agent-codexcli.

  • On Windows, see Sandbox, Permissions & Windows Compatibility before opting into danger-full-access.


Foreground Live Terminal Viewer & Toggle

codex_run, codex_review, and interrupt-mode codex_steer can open a separate terminal with live task output. On Windows the launcher prioritizes native PowerShell via conhost.exe and does not require Windows Terminal. macOS uses Terminal, and Linux auto-detects a supported terminal emulator. In CI, headless sessions, or when launch fails, the task continues in the background.

Pass foreground: false for a background run or foreground: true to request the viewer for a single call. The viewer stays open after completion by default. Enable auto-close and set its delay in the wizard or with the environment variables below. On macOS, foregroundAutoClose exits the viewer and shell. Terminal.app closes the window according to the profile’s “When the shell exits” setting. Once the viewer connects, manually closing it during a run cancels the task by default. Set CODEX_FOREGROUND_CLOSE_CANCELS_TASK=0 to let the task continue when the viewer closes.

Incremental Unread Conversational Output

Running and terminal summaries include new_messages when unread conversational agent_message text is available. Each poll includes up to 4,000 characters total, keeping the newest messages. Consuming calls such as codex_run and codex_wait mark omitted overflow as delivered too. Inspect log_path for the full history. codex_status, with or without a task_id, peeks at the same updates without consuming them. Use final_message for the completed task’s final reply.

Model & Reasoning Effort Inheritance

By default, Agent-CodexCLI-MCP-SKILL does NOT force a model or reasoning effort:

  • With no resolved model or reasoning effort override, agent-codexcli omits --model, review_model, and model_reasoning_effort so Codex CLI directly inherits your local ~/.codex/config.toml (including custom providers, auth, MCPs, and plugins). Enter inherit in the wizard to clear a saved override.

  • A model override from a call, an environment variable, or config.json makes codex_run and interrupt codex_steer pass --model=.... codex_review sets both --model=... and -c review_model=....

  • Reported model and reasoning_effort fields in task summaries reflect requested overrides (and are omitted when inherited from ~/.codex/config.toml).

Sandbox, Permissions & Windows Compatibility

  • New codex_run tasks default to workspace-write across all platforms. Change the default in the wizard or with CODEX_DEFAULT_SANDBOX, or pass sandbox per call. Passing an explicit sandbox flag on new runs overrides named Codex permission profiles from config.toml.

  • Resuming sessions (codex_run(session_id=...)): When sandbox is omitted on resume, agent-codexcli omits -c sandbox_mode=... so Codex preserves the session's saved permissions instead of silently widening a read-only session.

  • codex_review defaults to read-only independently of CODEX_DEFAULT_SANDBOX (and accepts an explicit sandbox override if needed).

  • Windows Trusted-Use Note: Codex CLI's workspace-write sandbox on Windows can break child commands or file/tool calls. After troubleshooting workspace-write in trusted repositories, you can explicitly opt in by passing sandbox: "danger-full-access" on codex_run or setting "CODEX_DEFAULT_SANDBOX": "danger-full-access" in your MCP server env.

Operational Notes, Logs & Safeguards

  • Rate-Limit Circuit Breaker: If Codex outputs HTTP 429 or structured/text quota errors (insufficient_quota, usage_limit_reached, etc.), agent-codexcli terminates the process tree and preserves status: "rate_limited" (rate_limited: true) with rate_limit_reason. Do not automatically retry; report the reason to the user.

  • Best-Effort Reset-Card Prompt Guard: Prompts instructing Codex to run /usage or redeem a quota reset card are blocked by default (negated mentions like "Do not run /usage" and normal paths like docs/usage.md are allowed). Opt out with CODEX_DISABLE_RESET_CARD_GUARD=1 (or true).

  • codex_steer queue Mode: Uses saved session settings, rejects per-call model, reasoning_effort, sandbox, and foreground overrides, and passes the message via CLI flags (--message=...), which are visible to local process inspection and subject to platform command-line length limits.

  • Git Change Summaries: Best-effort snapshots can capture concurrent external workspace edits; untracked files appear in changed_files without appearing in git_diff_stat.

  • Diagnostic Logs: Per-task .log files are stored in a private user state directory by default (%LOCALAPPDATA%/agent-codexcli/logs on Windows; $XDG_STATE_HOME/agent-codexcli/logs or ~/.local/state/agent-codexcli/logs on macOS/Linux). Logs contain raw prompts, command output, and diagnostics and may include sensitive project data; retention is bounded by CODEX_MAX_LOG_FILES (default 100).

Tool Reference

Tool

Purpose

Key Parameters

codex_run

Start a new Codex task or resume a session_id

prompt, cwd, session_id, sandbox, model, reasoning_effort, wait_seconds, foreground, worktree, add_dirs, images, skip_git_repo_check

codex_review

Run codex exec review (read-only by default)

cwd, uncommitted, base, commit, prompt, title, sandbox, model, reasoning_effort, wait_seconds, foreground

codex_wait

Wait for a running task to complete or return minimal running status

task_id, wait_seconds

codex_status

Non-blocking check of one task or list of all tracked tasks, with a read-only peek at new_messages

task_id (optional)

codex_steer

Interrupt & resume a session (default) or enqueue a follow-up

prompt, task_id / session_id, mode (interrupt | queue), cwd, sandbox, model, reasoning_effort, wait_seconds, foreground (interrupt only), queue_resume

codex_cancel

Terminate a running task and its child process tree

task_id

Environment Variables

Variable

Default

Effect

CODEX_DEFAULT_MODEL

(unset — inherits ~/.codex/config.toml)

Default --model (and review_model for reviews) override when not specified per call.

CODEX_DEFAULT_REASONING_EFFORT

(unset — inherits ~/.codex/config.toml)

Default model_reasoning_effort override when not specified per call.

CODEX_DEFAULT_SANDBOX

workspace-write

Default sandbox for new codex_run tasks (workspace-write, danger-full-access, or read-only).

CODEX_DEFAULT_WAIT_SECONDS

300

Initial sync wait for codex_run, codex_review, and interrupt codex_steer (0–600; e.g. 165 in Antigravity).

CODEX_DEFAULT_POLL_WAIT_SECONDS

180

Wait budget for codex_wait (0–600; e.g. 165 in Antigravity).

CODEX_FOREGROUND

true

Open the foreground viewer by default when a terminal is available.

CODEX_FOREGROUND_AUTO_CLOSE

false

Close the viewer automatically after the task finishes.

CODEX_FOREGROUND_AUTO_CLOSE_DELAY_SECONDS

8

Delay before auto-close (0–60 seconds).

CODEX_FOREGROUND_CLOSE_CANCELS_TASK

true

Cancel a running task when its viewer is closed manually.

CODEX_CONFIG_PATH

Platform user config path

Override the path to config.json.

CODEX_CLI_PATH

Auto-detected

Explicit path or absolute-PATH command for codex / codex.exe / npm codex.js.

CODEX_LOG_DIR

Private user state dir

Directory for per-task .log diagnostics (established before spawning Codex).

CODEX_MAX_TASKS

50

Number of completed tasks retained in memory (5–500).

CODEX_MAX_CONCURRENT_TASKS

8

Maximum simultaneous active Codex tasks (1–50).

CODEX_MAX_LOG_FILES

100

Maximum retained codex_*.log files in CODEX_LOG_DIR (0 disables pruning, max 10000).

CODEX_EXTRA_RATE_LIMIT_PATTERNS

(empty)

Comma-separated regexes or substrings for custom provider rate-limit detection.

CODEX_DISABLE_RESET_CARD_GUARD

0

Set to 1 or true to disable the best-effort /usage & reset-card prompt guard.

Development & Testing

npm install
npm run typecheck
npm run build
npm test

npm test runs TypeScript type-checking, compiles dist/, and executes the regression suite in tests/regression.test.mjs using tests/fake-codex.mjs.

License

MIT

Available Tools

6 tools
codex_cancelB

Terminate a running Codex background task and its child process tree.

Inputs: task_id (required).

codex_reviewA

Run a code review with Codex CLI (codex exec review), read-only by default (accepts sandbox override). Defaults: sandbox="read-only", model=(inherited from ~/.codex/config.toml), reasoning_effort=(inherited from ~/.codex/config.toml), wait_seconds=300. When model is specified (or CODEX_DEFAULT_MODEL is set), it also sets Codex's review_model override. If no review target (uncommitted/base/commit/prompt) is provided, defaults to uncommitted changes.

Inputs: cwd (required), base, model, title, +8 more.

codex_runA

Run Codex CLI (Executor) on a task or continue an existing Codex session via session_id. Inherits ~/.codex/config.toml (model, reasoning effort, custom provider, auth, MCPs, plugins, notify), disables unbounded_connection_retries, and applies a best-effort reset-card prompt guard (opt out via CODEX_DISABLE_RESET_CARD_GUARD=1 or true). Defaults for new runs: model=(inherited from ~/.codex/config.toml), reasoning_effort=(inherited from ~/.codex/config.toml), sandbox="workspace-write", wait_seconds=300. When session_id is provided and sandbox is omitted, saved session permissions are preserved instead of reapplying CODEX_DEFAULT_SANDBOX. Progress notifications are emitted every 15s when the client supplies a progressToken. If execution exceeds wait_seconds, returns status="running" with task_id so you can call codex_wait / codex_status / codex_cancel. If status="rate_limited", STOP immediately and ask the user; never retry or trigger a reset card.

Inputs: cwd (required), prompt (required), model, images, +7 more.

codex_statusA

Non-blocking check of a specific Codex task_id, or omit task_id to list all active and recent Codex tasks managed by this server.

Inputs: task_id.

codex_steerA

Send a new or updated instruction to an in-progress or existing Codex session. Two modes:

  • "interrupt" (DEFAULT): Cancels the running Codex task (if active and session_id is known) and resumes the same session_id with the new prompt so Codex stops obsolete work right away.

  • "queue": Enqueues a follow-up independently via CLI arguments (subject to platform command-line length and process visibility limits) using saved session settings; rejects per-call model, reasoning_effort, and sandbox overrides. Use only when explicitly requested. Applies the best-effort reset-card prompt guard unless CODEX_DISABLE_RESET_CARD_GUARD=1 or true.

Inputs: prompt (required), cwd, mode, model, +9 more.

codex_waitA

Wait up to wait_seconds (default 180) for a background Codex task to finish. Returns minimal status ({task_id, status, session_id, elapsed_ms}) while still running, and full structured output once finished. Emits progress notifications every 15s when the client supplies a progressToken.

Inputs: task_id (required), wait_seconds.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 6 tools

    Disambiguation4/5

    codex_run and codex_steer can both target an existing session, but the descriptions separate continuing a run from interrupting/steering it. wait, status, cancel, and review are clearly differentiated, leaving only minor overlap around session continuation.

    Naming Consistency5/5

    All six tools use the codex_ prefix plus a concise snake_case action (run, review, wait, status, steer, cancel), making names highly predictable. status is a noun rather than a verb, but it still fits the consistent action-style pattern.

    Tool Count5/5

    Six tools map neatly to launching, reviewing, monitoring, waiting on, steering, and cancelling Codex CLI work. There is no obvious padding, and the count is well-scoped for an async CLI execution wrapper.

    Completeness4/5

    The set covers the core async execution lifecycle and a read-only review path, with status also serving as a list operation. Minor gaps remain: no dedicated output/history retrieval beyond wait/status, and session management is only implicit through run and steer.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables MCP-compatible coding agents to execute the local Codex CLI as a coding agent, including code reviews, session resume/fork, and CLI diagnostics.
      9
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables Claude Code or any MCP client to delegate hands-on coding work to OpenAI Codex over a persistent app-server process, keeping long-lived threads with follow-ups, async polling, approvals, steering, and interrupts. Supports native code review, resuming existing sessions, structured output, and parallel worktree-isolated tasks.
      10
      42 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Wraps the Codex engine in a local stdio MCP server so any MCP-capable agent can run coding turns as tools, with blocking runs, start/poll progress, command approvals, interrupts, thread resume, and token usage. It also supports custom OpenAI-compatible providers, letting teams blocked by signup, payment, or network limits still use the engine.
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Bridges the OpenAI Codex CLI app-server to MCP clients, letting agents launch and resume Codex coding sessions within a chosen workspace under configurable sandbox and approval policies. It exposes tools for sending prompts, long-polling task progress and live command output, approving or canceling runtime requests, and listing or reading past session history.
      5
      MIT