Codex MCP Server
Codex MCP Server (version 1.4.10) is a crucial bridge component designed to integrate OpenAI's Codex CLI with AI agents like Claude Code, providing robust AI-powered code analysis, generation, and review capabilities directly within a developer's editor or IDE. Functioning as an MCP (Model Context Protocol) server wrapper, it translates requests from client applications into commands for the underlying Codex CLI, which then interacts with the OpenAI API. The project maintains an active development pace with frequent patch releases, as evidenced by recent fixes addressing issues like hanging processes and `codex -C` bugs. Its key differentiators include enabling multi-turn conversations with session support, advanced code review features for uncommitted changes or branches, and specialized tools like web search with customizable depth. It requires the globally installed Codex CLI (v0.75.0+) and an authenticated OpenAI API key for operation. The server itself is designed for execution as a command-line process rather than programmatic import into other JavaScript applications.
Common errors
-
Error: Command failed with exit code 1: codex login
cause The OpenAI Codex CLI is not authenticated or the API key is invalid.fixRun `codex login --api-key "your-openai-api-key"` in your terminal to authenticate the Codex CLI. Ensure your API key is correct and active. -
Command not found: codex
cause The OpenAI Codex CLI (`@openai/codex`) is not installed globally or is not in your system's PATH.fixInstall the Codex CLI globally: `npm i -g @openai/codex` or `brew install codex` if applicable. -
AI response process hung or timed out.
cause Older versions of codex-mcp-server could suffer from hanging child processes due to stdin not being closed.fixUpgrade `codex-mcp-server` to v1.4.10 or newer to get the fix for hanging processes. -
Error: `review` command failed or produced unexpected output.
cause Issues with the `review` command and stderr handling were present in earlier versions.fixUpgrade `codex-mcp-server` to v1.3.1 or newer, which includes fixes for the `review` command and improved stderr handling.
Warnings
- breaking The default model used by the `codex` tool was updated to 'codex 5.3' in v1.4.0. This might alter AI behavior or response characteristics if client applications implicitly relied on older defaults.
- gotcha Prior to v1.4.10, spawned processes could hang, leading to unresponsive sessions. This was addressed by ensuring stdin is closed on child processes.
- gotcha Versions prior to v1.4.3 had a bug where the `codex -C` command's `workingDirectory` was not correctly honored due to how the `cwd` was set for spawned processes.
- deprecated The `structuredContent` and `_meta` fields were removed from tool responses in v1.3.2, with `structuredContent` later gated behind `STRUCTURED_CONTENT_ENABLED` in v1.3.4. Relying on these fields in older client integrations might cause issues.
- breaking The package requires OpenAI's `Codex CLI v0.75.0+` to be installed globally and an OpenAI API key for authentication. Operation will fail without these prerequisites.
Install
-
npm install codex-mcp-server -
yarn add codex-mcp-server -
pnpm add codex-mcp-server
Imports
- Server Execution
import { startServer } from 'codex-mcp-server'npx -y codex-mcp-server
- MCP Client Integration
import { createClient } from 'codex-mcp-server'claude mcp add codex-cli -- npx -y codex-mcp-server
- MCP Configuration (JSON/TOML)
import type { McpConfig } from 'codex-mcp-server'{ "command": "npx", "args": ["-y", "codex-mcp-server"] }
Quickstart
npm i -g @openai/codex codex login --api-key "your-openai-api-key" # Add to Claude Code or other MCP-compatible editor/client claude mcp add codex-cli -- npx -y codex-mcp-server # Example usage in your editor/AI client (after server is running) // Ask codex to explain this function // Use codex to refactor this code for better performance // Use review to check my uncommitted changes // Use websearch with query "TypeScript 5.8 new features"