codex-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@codex-mcp Review the current branch for bugs and security vulnerabilities"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Codex MCP
A lightweight Model Context Protocol (MCP) server that exposes the local Codex CLI (codex) to MCP-compatible coding agents.
The project intentionally keeps the architecture small: MCP tools validate inputs, a thin CLI adapter executes codex exec (and friends), and codex_raw provides an escape hatch for CLI options that are added in future Codex releases.
Features
Run Codex as a local coding agent through MCP (
codex exec).Run non-interactive code reviews (
codex exec review).Resume or fork previous sessions (
codex exec resume/codex exec fork).Control common CLI options such as model, sandbox policy, approval behavior, extra directories, images, and output handling.
Inspect version, login status, and diagnostics (
codex doctor).Pass arbitrary CLI arguments through
codex_rawfor forward compatibility.No shell execution: arguments are passed directly to the
codexprocess (shell: false).Optional server-wide model override via an environment variable (see below).
Related MCP server: codex-mcp-server
Requirements
Node.js 18+
Codex CLI installed and authenticated (
codex login)codexavailable onPATHAn MCP-compatible client
If codex is not on PATH, set CODEX_MCP_CMD to the executable path.
CODEX_MCP_CMD=/custom/path/codexWindows PowerShell:
$env:CODEX_MCP_CMD = "C:\path\to\codex.exe"Forcing a specific model
Every tool that runs the agent (codex_run, codex_review, codex_resume, codex_fork, and codex_raw when its first argument is exec) accepts a model input. If you set the CODEX_MCP_MODEL environment variable on the MCP server process, it overrides the model for every such call, regardless of what the caller (or a raw argument list) requests. This is useful when you want to pin the server to a single model — for cost control, quota limits, or consistency — no matter what any individual tool call asks for.
CODEX_MCP_MODEL=your-model-idThe override is applied last, after stripping any -m/--model flag or -c model=... config override already present in the constructed arguments, so it always wins. It is never applied to subcommands that don't accept a model (--version, login status, help, doctor, ...), so those keep working normally even when the override is set.
Quick Start
The recommended setup is through npm. You do not need to clone this repository or install the MCP server manually.
Claude Code
claude mcp add --scope user codex -- npx -y codex-mcpVerify the server:
claude mcp listIf codex is not on PATH, or you want to pin the model:
claude mcp add --scope user \
--env CODEX_MCP_CMD=/custom/path/codex \
--env CODEX_MCP_MODEL=your-model-id \
codex -- npx -y codex-mcpGemini CLI
gemini mcp add --scope user codex npx -y codex-mcpVerify:
gemini mcp listCursor
{
"mcpServers": {
"codex": {
"command": "npx",
"args": ["-y", "codex-mcp"]
}
}
}Windsurf
{
"mcpServers": {
"codex": {
"command": "npx",
"args": ["-y", "codex-mcp"]
}
}
}Cline / Roo Code / Other MCP Clients
{
"command": "npx",
"args": ["-y", "codex-mcp"]
}If the client supports environment variables, CODEX_MCP_CMD and CODEX_MCP_MODEL can be set there as well.
Local Development
git clone https://github.com/alvarosw/codex-mcp.git
cd codex-mcp
npm install
npm startNo build step is required.
Testing
npm test runs a static syntax check only — it makes no network calls and costs nothing.
npm run test:live drives the real MCP server end to end over stdio against a real, authenticated Codex CLI (in a throwaway temp git repo it creates and cleans up). It exercises every tool, including verifying that CODEX_MCP_MODEL (if set) wins over a deliberately wrong model passed in a tool call or smuggled into codex_raw arguments. This makes real model calls and is not run automatically — you need codex login completed first, and it will consume real quota/tokens against whichever model resolves for the call:
CODEX_MCP_MODEL=your-model-id npm run test:liveCODEX_MCP_MODEL is optional for this script; without it, the override-specific assertions are skipped and the rest of the suite still runs against your account's default configured model.
Tools
codex_run
Run Codex as an agent non-interactively (codex exec) with common CLI controls: prompt, model, sandbox policy, approval routing, extra directories, images, working directory, ephemeral/persisted sessions, and raw passthrough args.
Example:
{
"prompt": "Review the authentication implementation and identify security issues.",
"cwd": "/workspace/project",
"sandbox": "workspace-write",
"addDirs": ["/workspace/shared"]
}codex_review
Runs codex exec review non-interactively against the current repository. Supports uncommitted, base, commit, and title, plus a custom review prompt.
codex_resume
Resumes a previous session (codex exec resume) by sessionId, or the most recent one if omitted, optionally sending a new prompt.
codex_fork
Forks a previous session (codex exec fork) by sessionId into a new session, optionally sending a prompt.
codex_version
Returns the installed Codex CLI version.
codex_login_status
Runs codex login status to check authentication state.
codex_doctor
Runs codex doctor --json for install, auth, config, and connectivity diagnostics.
codex_help
Shows CLI help. A command can be provided for command-specific help.
codex_raw
Runs codex with an arbitrary argument array. This is the compatibility escape hatch for flags or commands not covered by the convenience tools. The model override, if set, still applies when the first argument is exec.
Example:
{
"args": ["mcp", "list"]
}Architecture
src/
├── index.js # MCP server and tool registration
├── tools.js # Tool behavior and response formatting (JSONL event parsing)
└── codex.js # Thin process adapter for the codex CLI + model-override enforcementDependency direction:
MCP transport
↓
tool handlers
↓
codex CLI adapter
↓
local codex executableThere is intentionally no service container, repository layer, or framework abstraction. The project has one external process boundary and keeps that boundary explicit.
Tools that invoke codex exec* request --json internally so output can be parsed reliably; each tool's text response is the agent's final message(s), with the full parsed event stream, command executions, token usage, and thread id available in structuredContent for programmatic consumers.
Security Notes
codex_raw can execute arbitrary Codex CLI arguments with the permissions of the user running the MCP server. The server itself does not invoke a shell, so tool arguments are not shell-interpreted, but codex still has whatever permissions its sandbox and approval settings grant it.
dangerouslyBypassApprovalsAndSandbox skips all confirmation prompts and sandboxing. Only use it when you explicitly trust the task and an already-isolated workspace.
Environment variables passed through the env field are inherited by the codex process. Avoid sending secrets through MCP tool arguments unless necessary.
License
MIT
Available Tools
9 toolscodex_doctorA
Run Codex's built-in diagnostics (codex doctor --json): install, auth, config, and connectivity health.
Inputs: cwd, env, timeoutMs.
codex_forkB
Fork a previous Codex session (codex exec fork) into a new session and optionally send a prompt.
Inputs: sessionId (required), cwd, env, model, +9 more.
codex_helpB
Show Codex CLI help, optionally for a specific subcommand.
Inputs: cwd, env, command, timeoutMs.
codex_login_statusB
Check Codex CLI authentication status (codex login status).
Inputs: cwd, env, timeoutMs.
codex_rawA
Run the Codex CLI with an arbitrary argument array. Escape hatch for options not covered by the other tools. The server's model-override environment variable, if set, still applies.
Inputs: args (required), cwd, env, timeoutMs.
codex_resumeB
Resume a previous Codex session non-interactively (codex exec resume) and optionally send a new prompt.
Inputs: all, cwd, env, model, +10 more.
codex_reviewB
Run a non-interactive Codex code review (codex exec review) against the current repository.
Inputs: cwd, env, base, model, +12 more.
codex_runB
Run the Codex agent non-interactively (codex exec) with common CLI controls.
Inputs: prompt (required), cd, cwd, env, +13 more.
codex_versionA
Return the installed Codex CLI version.
Inputs: cwd, env, timeoutMs.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Tools are mostly distinct: review, resume, run, and fork each target specific Codex execution modes, while version, login_status, doctor, help, and raw cover ancillary actions. There is slight overlap between run, resume, and fork, but descriptions clarify the differences effectively.
All tools share the consistent codex_ prefix and snake_case naming. The second part is a mix of verbs (review, resume, run, fork) and nouns (version, login_status, doctor, help, raw), but the overall pattern is predictable and readable, with minor deviation from a strict verb_noun convention.
With 9 tools, the set is well-scoped for a CLI wrapper server. It covers primary execution modes, status checks, diagnostics, help, and an escape hatch without unnecessary bloat. The count falls comfortably in the ideal 3-15 range.
The surface covers the main Codex workflows (run, review, resume, fork) and essential auxiliary actions (version, status, doctor, help). The codex_raw tool provides an arbitrary argument escape hatch, mitigating gaps for uncovered CLI options. Minor omissions like explicit auth configuration are not critical due to raw access.
Maintenance
Related MCP Connectors
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Connect ChatGPT and Claude to your Mac, Windows or Linux with secure MCP remote access.
Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables MCP clients to spawn and control Codex CLI and Claude Code sessions on the host machine, with session management and filesystem access.4MIT
- AlicenseCqualityDmaintenanceBridges MCP clients with local Codex CLI to execute autonomous coding tasks, manage threads, and inspect history via SQLite state.131,488 npm4Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables Grok Build to orchestrate the local Codex CLI for code reviews, adversarial reviews, task rescue, session transfer, and background job management through MCP tools.1Apache 2.0
- AlicenseAqualityCmaintenanceEnables Codex to delegate coding tasks to an OpenCode CLI locally, returning structured results such as exit codes, session summaries, tool calls, and git diffs.2MIT