About Codex Mcp Server
Codex MCP Server is an MCP server that connects Claude, Cursor and other AI assistants to the OpenAI Codex CLI for code analysis, review and refactoring. It targets developers who want to call Codex CLI from MCP clients, with multi-turn sessions and sandboxed edits.
Key features
- 01File analysis using @ references
- 02Multi-turn sessions with workspace isolation
- 03Sandbox and approval policy controls
- 04Structured OLD/NEW patch output
- 05Local Ollama and LM Studio model support
- 06Batch runs and verify-and-retry workflows
Use cases
- 01Asking Claude or Cursor to analyze project architecture and dependencies
- 02Running non-interactive code reviews on pending changes
- 03Applying batch refactoring as structured patches
MCP support
The project runs as an MCP server and exposes tools such as ask-codex, review-changes and do-act to MCP clients, executing the actual work through Codex CLI.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
npx -y @trishchuk/codex-mcp-toolCODEX_MCP_CWDOverride working directory for all tool callsCODEX_SESSION_TTL_MSSession time-to-live in milliseconds (default: 86400000 = 24h)CODEX_MAX_SESSIONSMaximum concurrent sessions (default: 50)Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.
Tools
13Saved tool list · updated 3w ago
| Parameter | Type | Required | Description |
|---|---|---|---|
| prompt | string | Yes | Task or question. Use @ to include files (e.g., '@largefile.ts explain'). |
| model | string | No | Optional model override. Known: gpt-5.6, gpt-5.6-sol, gpt-5.6-terra, gpt-5.6-luna, gpt-5.5, gpt-5.4, gpt-5.4-mini. If omitted, uses your Codex CLI default (~/.codex/config.toml). Specify only to override. |
| sandbox | boolean | No | Quick automation mode: enables workspace-write with approval=never. Sandboxing remains active. |
| fullAuto | boolean | No | Compatibility alias for workspace-write with approval=never (not --yolo) |
| approvalPolicy | enum | No | Approval: never, on-request, untrustednever | on-request | untrusted |
| approval | enum | No | Approval policy: untrusted, on-request, nevernever | on-request | untrusted |
| sandboxMode | enum | No | Access: read-only, workspace-write, danger-full-accessread-only | workspace-write | danger-full-access |
| yolo | boolean | No | ⚠️ Bypass all safety (dangerous) |
| cd | string | No | Working directory |
| workingDir | string | No | Working directory for execution |
| changeMode | boolean | No | Return structured OLD/NEW edits for refactoring |
| chunkIndex | number | No | Chunk index (1-based) |
| chunkCacheKey | string | No | Cache key for continuation |
| image | any | No | Optional image file path(s) to include with the prompt |
| config | any | No | Configuration overrides as 'key=value' string or object |
| profile | string | No | Configuration profile to use from ~/.codex/config.toml |
| timeout | number | No | Maximum execution time in milliseconds (optional) |
| includeThinking | boolean | No | Include reasoning/thinking section in response |
| includeMetadata | boolean | No | Include configuration metadata in response |
| search | boolean | No | Enable web search using native --search flag (v0.52.0+). Requires network access - automatically sets sandbox to workspace-write if not specified. |
| oss | boolean | No | Use local Ollama server (convenience for -c model_provider=oss). Requires Ollama running locally. Automatically sets sandbox to workspace-write if not specified. |
| localProvider | enum | No | Specify which local provider to use (lmstudio or ollama). Automatically enables --oss if not set. If omitted with --oss, uses config default or shows selection.lmstudio | ollama |
| enableFeatures | array | No | Enable feature flags (repeatable). Equivalent to -c features.<name>=true |
| disableFeatures | array | No | Disable feature flags (repeatable). Equivalent to -c features.<name>=false |
| addDirs | array | No | Additional writable directories beyond workspace (e.g., ["/tmp", "/var/log"]). Useful for monorepos and multi-directory projects. |
| toolOutputTokenLimit | number | No | Maximum tokens for tool outputs (100-10,000). Controls response verbosity. |
| reasoningEffort | enum | No | Reasoning depth. Omit to use the CLI default. max/ultra are model-dependent GPT-5.6 options; ultra may delegate to subagents.low | medium | high | xhigh | max | ultra |
| sessionId | string | No | Session ID for conversation continuity. Enables native Codex resume. |
| resetSession | boolean | No | Clear session context before execution. Starts fresh conversation. |
| outputSchema | any | No | JSON Schema path or inline schema to constrain output format (Codex CLI v0.95.0+) |
| personality | enum | No | Communication style: pragmatic (concise, machine-friendly) or friendly (conversational). Codex CLI v0.94.0+pragmatic | friendly |
| skipGitRepoCheck | boolean | No | Skip git repository validation. Useful for non-git directories (Codex CLI v0.75.0+) |
| outputLastMessage | string | No | Write final Codex message to file path. Useful for CI/CD result capture (Codex CLI v0.95.0+) |
| strictConfig | boolean | No | Fail when config.toml contains fields unknown to the installed Codex CLI |
| ephemeral | boolean | No | Run without persisting Codex session files to disk |
| ignoreUserConfig | boolean | No | Ignore $CODEX_HOME/config.toml for this run; authentication is still loaded |
| ignoreRules | boolean | No | Ignore user and project execpolicy .rules files for this run |
| bypassHookTrust | boolean | No | DANGEROUS: run enabled hooks without persisted hook trust |
| responseMode | enum | No | Response verbosity: "clean" returns only the final answer (default), "full" returns the complete execution log including thinking, tool calls, and agent activityclean | full |
Details
From the project READMECodex MCP Server
MCP server connecting Claude/Cursor to Codex CLI. Enables code analysis via @ file references, multi-turn conversations, sandboxed edits, and structured change mode.
Features
- File Analysis — Reference files with
@src/,@package.jsonsyntax - Multi-Turn Sessions — Conversation continuity with workspace isolation
- Native Resume — Uses
codex resumefor context preservation (CLI v0.36.0+) - Local OSS Models — Run with Ollama or LM Studio via
localProvider - Web Search — Research capabilities with
search: true - Sandbox Mode — Safe automation with explicit sandbox and approval policies
- Change Mode — Structured OLD/NEW patch output for refactoring
- Brainstorming — SCAMPER, design-thinking, lateral thinking frameworks
- Health Diagnostics — CLI version, features, and session monitoring
- Cross-Platform — Windows, macOS, Linux fully supported
Quick Start
claude mcp add codex-cli -- npx -y @trishchuk/codex-mcp-tool
Prerequisites: Node.js 18+, Codex CLI installed and authenticated.
Configuration
{
"mcpServers": {
"codex-cli": {
"command": "npx",
"args": ["-y", "@trishchuk/codex-mcp-tool"]
}
}
}
Config locations: macOS: ~/Library/Application Support/Claude/claude_desktop_config.json | Windows: %APPDATA%\Claude\claude_desktop_config.json
Usage Examples
// File analysis
'explain the architecture of @src/';
'analyze @package.json and list dependencies';
// With specific model
'use codex with model gpt-5.6-sol to analyze @algorithm.py';
// Multi-turn conversations (v1.4.0+)
'ask codex sessionId:"my-project" prompt:"explain @src/"';
'ask codex sessionId:"my-project" prompt:"now add error handling"';
// Brainstorming
'brainstorm ways to optimize CI/CD using SCAMPER method';
// Sandbox mode
'use codex sandbox:true to create and run a Python script';
// Web search
'ask codex search:true prompt:"latest TypeScript 5.7 features"';
// Local OSS model (Ollama)
'ask codex localProvider:"ollama" model:"qwen3:8b" prompt:"explain @src/"';
Tools
| Tool | Description |
|---|---|
ask-codex | Execute Codex CLI with files, models, sessions, and safety controls |
batch-codex | Run multiple atomic Codex tasks sequentially or concurrently |
review-changes | Run the native non-interactive Codex review command |
do-act | Execute, verify with a shell command, and retry fixes |
image-gen | Generate or edit images with Codex's built-in image_gen tool |
brainstorm | Generate ideas with structured creative frameworks |
list-sessions | View, delete, or clear MCP conversation mappings |
list-skills | List skills visible from the selected workspace |
health | Diagnose CLI installation, version, features, and sessions |
fetch-chunk | Retrieve a chunk from cached change-mode output |
ping | Test the MCP connection |
help | Return current codex --help output |
version | Report Codex CLI, Node.js, platform, and package versions |
timeout-test | Exercise keepalive and timeout behavior |
Image generation
image-gen drives Codex's built-in image_gen tool, so it uses your ChatGPT
login and needs no OPENAI_API_KEY. That tool only accepts a prompt and
reference image paths: Codex picks the image model and pixel size, and there
are no size, quality, format or mask arguments. image-gen therefore puts all
steering into a structured prompt (use case, asset type, style, composition,
exact text, reference roles, edit invariants, aspect ratio, presets) and tells
the Codex host model to relay it instead of improvising.
// New image, 16:9, exact Cyrillic headline, copied into the project
'image-gen prompt:"YouTube cover about AI coding agents" aspect:"wide" text:"АГЕНТИ БЕЗ ХАОСУ" presets:["thumbnail","exact-text"] outputPath:"assets/cover.png"';
// Edit: change only the headline, keep everything else
'image-gen editImage:"assets/cover.png" prompt:"Replace the headline text" text:"ЧАСТИНА 2" preserve:["people and background"] outputPath:"assets/cover.png"';
Images are saved by Codex under $CODEX_HOME/generated_images/<thread>/ and
copied to outputPath when given; an existing file is kept and the copy is
written as a -v2 sibling unless overwrite: true. The result reports each
file's dimensions and alpha channel, so a transparentBackground request that
came back opaque is flagged.
Models
By default the model parameter is omitted and Codex CLI applies the
default model from your ~/.codex/config.toml (for example model = "gpt-6.1-sol").
Pass model only when you need to override the configured default for a
single call. Reasoning depth is calibrated per tool:
ask-codex— uses the Codex CLI default reasoning (medium). Increase it only when the task needs more planning or checking.brainstorm,do-act,review-changes— defaultreasoningEffort: "high"(creative ideation, act-check-fix loops, and code review benefit from deeper reasoning).
| Model | Recommendation |
|---|---|
gpt-6.1-sol | Latest workhorse for coding and everyday work (CLI 0.159+) |
gpt-6-astra | Frontier intelligence for the most demanding work |
gpt-6-sol | Previous-generation workhorse |
gpt-6-luna | Fast and affordable; easier, repeatable tasks |
gpt-5.6-sol | Older-generation workhorse |
gpt-5.6-terra | Older balanced model for straightforward work |
gpt-5.6-luna | Older fast, efficient model |
gpt-5.5 | Legacy — Codex steers callers to gpt-5.6-sol |
Sol, Astra and Terra models expose max and ultra reasoning; Luna models top
out at max, and gpt-5.5 at xhigh. ultra may delegate work to subagents;
most tasks should remain on medium or high. Pass a concrete slug — the bare
moving aliases gpt-6 and gpt-5.6 are rejected by the API. gpt-6.1-sol is
rejected by Codex CLI 0.157.x with the same 400 an unknown slug gets; upgrade
with npm install -g @openai/codex@latest.
Key Features
Session Management (v1.4.0+)
Multi-turn conversations with workspace isolation:
{ "prompt": "analyze code", "sessionId": "my-session" }
{ "prompt": "continue from here", "sessionId": "my-session" }
{ "prompt": "start fresh", "sessionId": "my-session", "resetSession": true }
Environment:
CODEX_SESSION_TTL_MS- Session TTL (default: 24h)CODEX_MAX_SESSIONS- Max sessions (default: 50)
Codex CLI version
Requires Codex CLI 0.95.0 or newer. On older versions the server fails
with an explicit upgrade message rather than silently dropping unsupported
flags. Upgrade with npm install -g @openai/codex@latest; run the health tool
to see the detected version.
Troubleshooting: "codex not found"
MCP clients launched from a GUI (Dock, Finder, Start menu) inherit a minimal
PATH that excludes Homebrew, nvm, and volta directories, so codex may work
from a terminal but not from the app. The server searches those locations
automatically; if it still cannot find the CLI, pin it explicitly:
{ "env": { "CODEX_CLI_PATH": "/opt/homebrew/bin/codex" } }
Find the value with which codex. Run the health tool to see which
executable was resolved and how.
Local OSS Models (v1.6.0+)
Run with local Ollama or LM Studio instead of OpenAI:
// Ollama
{ "prompt": "analyze @src/", "localProvider": "ollama", "model": "qwen3:8b" }
// LM Studio
{ "prompt": "analyze @src/", "localProvider": "lmstudio", "model": "my-model" }
// Auto-select provider
{ "prompt": "analyze @src/", "oss": true }
Requirements: Ollama running locally with a model that supports tool calling (e.g. qwen3:8b).
Advanced Options
| Parameter | Description |
|---|---|
model | Model selection |
sessionId | Enable conversation continuity |
sandbox | Compatibility automation: workspace-write + never |
search | Enable web search |
changeMode | Structured OLD/NEW edits |
addDirs | Additional writable directories |
toolOutputTokenLimit | Cap response verbosity (100-10,000) |
reasoningEffort | low, medium, high, xhigh, max, ultra |
oss | Use local OSS model provider |
localProvider | Local provider: lmstudio or ollama |
strictConfig | Fail on unknown Codex configuration keys |
ephemeral | Do not persist Codex session files |
ignoreUserConfig | Ignore $CODEX_HOME/config.toml |
ignoreRules | Ignore execpolicy .rules files |
CLI Compatibility
Validated against Codex CLI 0.144.3. The server keeps older feature guards,
but current releases are recommended. Notable current behavior:
--full-autoand approval policyon-failurehave been removed by Codex CLI.- MCP
sandbox: true/fullAuto: trueremain compatibility aliases for--sandbox workspace-write --ask-for-approval never; they do not bypass the sandbox. - Native
--searchis used without the deprecatedweb_search_requestfeature. - Current
execflags include--strict-config,--ephemeral,--ignore-user-config, and--ignore-rules.
Troubleshooting
codex --version # Check CLI version
codex login # Authenticate
Use health tool for diagnostics: 'use health verbose:true'
Migration
v2.5.x → v2.6.0: Codex CLI 0.159.2 model sync and a new image-gen tool.
Added gpt-6.1-sol (needs Codex CLI 0.159+), gpt-6-sol and gpt-6-luna.
Breaking: dropped gpt-5.4-mini, which now returns HTTP 400.
v2.4.x → v2.5.0: Codex CLI 0.153.4 compatibility pass; added
gpt-6-astra. Breaking: dropped gpt-5.4 and the moving alias gpt-5.6
(both now rejected with HTTP 400), and removed the untrusted approval policy,
which Codex CLI 0.153.x no longer parses.
v2.3.x → v2.4.0: Codex CLI 0.144.3 compatibility audit; added GPT-5.6
Sol/Terra/Luna, max/ultra reasoning, current exec flags, native-only search,
and safe compatibility handling for the removed --full-auto flag and
on-failure approval policy.
v2.2.x → v2.3.0: gpt-5.5 as new default, added gpt-5.4-mini, dropped retired models (gpt-5.3-codex-spark, gpt-5.2-codex, gpt-5.1-codex-max, gpt-5.1-codex-mini).
v2.0.x → v2.1.0: gpt-5.4 as new default model, updated fallback chain.
v1.5.x → v1.6.0: Local OSS model support (localProvider, oss), gpt-5.3-codex default model, xhigh reasoning effort.
v1.3.x → v1.4.0: New sessionId parameter, list-sessions/health tools, structured error handling. No breaking changes.
License
MIT License. Not affiliated with OpenAI.
Documentation | Issues | Inspired by jamubc/gemini-mcp-tool
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.