Setup guide for OpenAI's Codex CLI.
Codex CLI is OpenAI's command-line AI coding assistant. It supports MCP servers via stdio transport and reads project instructions from AGENTS.md.
-
Codex CLI installed:
npm install -g @openai/codex
-
OpenAI API key configured:
export OPENAI_API_KEY=sk-... -
OpenCode MCP Server built:
git clone https://github.com/Traves-Theberge/opencode-mcp.git cd opencode-mcp npm install npm run build
Add the MCP server using the Codex CLI:
codex mcp add opencode -- node /path/to/opencode-mcp/dist/index.jsSet environment variables:
codex mcp add opencode \
--env OPENCODE_SERVER_URL=http://localhost:4096 \
--env OPENCODE_DEFAULT_PROJECT=/path/to/your/project \
-- node /path/to/opencode-mcp/dist/index.jsVerify the configuration:
codex mcp listEdit ~/.codex/config.toml:
[mcp_servers.opencode]
command = "node"
args = ["/path/to/opencode-mcp/dist/index.js"]
[mcp_servers.opencode.env]
OPENCODE_SERVER_URL = "http://localhost:4096"
OPENCODE_DEFAULT_PROJECT = "/path/to/your/project"
OPENCODE_LOG_LEVEL = "info"Note: Replace
/path/to/opencode-mcpwith the actual path where you cloned the repository.
For project-specific configuration, create .codex/config.toml in your project root:
[mcp_servers.opencode]
command = "node"
args = ["/path/to/opencode-mcp/dist/index.js"]
[mcp_servers.opencode.env]
OPENCODE_SERVER_URL = "http://localhost:4096"
OPENCODE_DEFAULT_PROJECT = "."Codex CLI reads the AGENTS.md file from your project root for instructions. This file is included in the OpenCode MCP Server repository and provides:
- Tool usage guidelines
- When to use each tool
- Best practices for the MCP server
-
Start OpenCode server:
opencode serve
-
Launch Codex CLI:
codex
-
Test with a simple prompt:
Use opencode_run to list the files in the current directory -
Check MCP server status:
codex mcp list
Use opencode_run to implement a REST API endpoint for user authentication
Use opencode_agent_delegate with the plan agent to review the security of my auth module
Use opencode_file_search to find all uses of the deprecated function
Codex CLI currently only supports stdio transport for MCP servers. Remote MCP servers (HTTP/SSE) are not supported yet.
- Verify the path to
dist/index.jsis correct - Ensure Node.js is in your PATH
- Check the config file syntax (valid TOML)
- Ensure OpenCode server is running:
curl http://localhost:4096/health
- Check
OPENCODE_SERVER_URLenvironment variable - Verify firewall settings
Set OPENCODE_DEFAULT_PROJECT to your project path:
[mcp_servers.opencode.env]
OPENCODE_DEFAULT_PROJECT = "/absolute/path/to/your/project"Enable verbose logging:
[mcp_servers.opencode.env]
OPENCODE_LOG_LEVEL = "debug"| Setting | Description | Default |
|---|---|---|
command |
Command to run MCP server | Required |
args |
Arguments for the command | [] |
env.OPENCODE_SERVER_URL |
OpenCode server URL | http://localhost:4096 |
env.OPENCODE_DEFAULT_PROJECT |
Default project directory | Required |
env.OPENCODE_TIMEOUT |
Request timeout (ms) | 120000 |
env.OPENCODE_LOG_LEVEL |
Log level | info |
- Codex CLI Documentation
- Codex MCP Documentation
- AGENTS.md - Project instructions for Codex