MCP server wrapper for the OpenAI Codex CLI that lets Claude Code (and any MCP‑compatible client) use Codex locally via stdio.
graph LR
A[Claude Code / MCP Client] --> B[Codex MCP Server]
B --> C[codex]
B --> L[listTools]
B --> S[listSessions]
B --> X[deleteSession]
B --> T[sessionStats]
B --> P[ping]
B --> H[help]
B --> M[listModels]
C --> F[Codex CLI]
F --> G[OpenAI API]
style A fill:#FF6B35
style B fill:#4A90E2
style C fill:#00D4AA
style L fill:#00D4AA
style S fill:#00D4AA
style X fill:#00D4AA
style T fill:#00D4AA
style P fill:#00D4AA
style H fill:#00D4AA
style M fill:#00D4AA
style F fill:#FFA500
style G fill:#FF9500
- OpenAI Codex CLI installed & configured
- Install:
npm i -g @openai/codexorbrew install codex - Setup:
codex loginor setOPENAI_API_KEY
- Install:
- Claude Code (or another MCP client)
claude mcp add codex-cli -- npx -y @comfucios/codex-mcp-serverAdd to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"codex-cli": {
"command": "npx",
"args": ["-y", "@comfucios/codex-mcp-server"]
}
}
}- Graceful shutdown — Handles SIGINT/SIGTERM so clients don’t see abrupt disconnects.
- Pagination — Large outputs are chunked; use
nextPageToken/pageToken. Default size viaCODEX_PAGE_SIZE. - Session memory — Pass
sessionIdto keep context; sessions expire afterCODEX_SESSION_TTL_MSand trim when exceedingCODEX_SESSION_MAX_BYTES. - Tool discovery — Use
listToolsto get all tools with schemas (handy for client introspection). - Image input — The
codextool supportsimagepaths (single or array) for code/diagram analysis. - Model control — Pass
modelto select gpt‑5 with reasoning effort:minimal,low,medium(default),high(e.g."gpt-5 high").
Configure via env vars (shell or .env):
OPENAI_API_KEY— Required by Codex CLI unless you’ve runcodex login.CODEX_PAGE_SIZE— Default page size (default:40000, min1000, max200000).CODEX_SESSION_TTL_MS— Session time‑to‑live in ms (default:3600000, i.e. 1 hour).CODEX_SESSION_MAX_BYTES— Max transcript bytes before trimming (default:400000).
- Codex CLI not found
- Install
@openai/codexglobally or via Homebrew. - Ensure
codex --versionworks and the install directory is on yourPATH.
- Install
- Missing API key
- Run
codex loginor setOPENAI_API_KEY.
- Run
- No Codex config file
- Create one in
~/.codex/config.toml|.yaml|.json(for use withlistModels).
- Create one in
- Session expired
- Sessions expire after
CODEX_SESSION_TTL_MS. Use a newsessionIdor increase TTL.
- Sessions expire after
- Large output truncated
- Use
pageTokento fetch subsequent pages or raiseCODEX_PAGE_SIZE.
- Use
All tools return consistent, structured errors:
{
"isError": true,
"content": [{ "type": "text", "text": "Error message here" }]
}Ask Codex to analyze code, generate solutions, or explain diagrams/images.
Common parameters
prompt(string, required on first call unless paging)pageSize(number, optional)pageToken(string, optional)sessionId(string, optional)resetSession(boolean, optional)model(string, optional —"gpt-5 minimal|low|medium|high")image(string or string[])approvalPolicy,sandbox,workingDirectory,baseInstructions(advanced)
Examples
Basic:
{ "prompt": "Explain this TypeScript function" }Image input:
{ "prompt": "Explain this diagram", "image": "diagram.png" }Advanced options:
{
"prompt": "Run this code in a sandbox",
"sandbox": true,
"workingDirectory": "/tmp/safe",
"baseInstructions": "Always comment code."
}listSessions— list active sessions (with metadata)deleteSession— delete a session by IDsessionStats— detailed stats for a sessionlistModels— list models discovered from your~/.codexconfiglistTools— machine‑readable tool list & schemasping— echo testhelp—codex --helppassthrough
Code analysis
Use the codex tool to review this TypeScript function and suggest improvements
Bug fixing
Use codex to help debug this error: [error message]
Code generation
Ask codex to create a React component that handles file uploads
Paging
- First call:
{ "tool": "codex", "prompt": "...", "pageSize": 10000 }- Next page:
{ "tool": "codex", "pageToken": "<nextPageToken>" }# Install dependencies
npm install
# Development mode
npm run dev
# Build
npm run build
# Start built server
npm startUses Jest (unit + light integration).
npm testSee docs/tools.md, docs/usage.md, and docs/configuration.md for details.