关于 OpenAI Codex MCP Server
将 OpenAI Codex CLI 封装为 MCP 服务,供 Claude Code 等 MCP 客户端调用。它提供代码任务、交互会话、多模态输入和可配置的自动化级别。
主要功能
- 01代码生成、解释与调试
- 02重构、测试与文档生成
- 03图像输入支持
- 04支持多个 AI 提供方
- 05三种自动化审批模式
- 06交互式会话
适用场景
- 01生成或修复代码
- 02检查代码安全问题
- 03根据图像实现界面
- 04启动交互式代码会话
MCP 相关
通过 MCP 暴露 Codex CLI 的功能,包括 codex_agent 和 codex_interactive 工具。支持 stdio 与 SSE 传输,供 MCP 客户端连接。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
OpenAI Codex MCP 服务
将 OpenAI Codex CLI 封装为 MCP(模型上下文协议)服务,以便与 Claude 集成。
🚀 功能
此 MCP 服务提供以下工具:
-
codex_agent:功能全面的工具,可使用 OpenAI Codex CLI 的所有功能- 代码生成、解释、调试和重构
- 安全分析、测试创建和文档生成
- 多模态支持(图像输入)
- 支持多个 AI 提供商
- 3 级自动化模式(建议/自动编辑/全自动)
-
codex_interactive:用于启动交互式会话的工具
🔌 支持的模式
- stdio 模式:使用标准输入/输出(适用于 Claude Desktop)
- SSE 模式:使用服务器发送事件(适用于 Web API)
📋 前提条件
-
OpenAI Codex CLI:
npm install -g @openai/codex -
Python 3.12 或更高版本
-
环境设置:将
.env.example复制为.env并进行配置
🛠️ 安装
1. 克隆仓库
git clone https://github.com/Tomatio13/openai-codex-mcp.git
cd openai-codex-mcp
2. 设置
./setup.sh
3. 启动服务
stdio 模式(适用于 Claude Desktop)
./run.sh
SSE 模式(适用于 Web API)
./run_sse.sh [port] [host]
# Examples:
./run_sse.sh 8080 0.0.0.0 # Port 8080, listen on all interfaces
./run_sse.sh # Default: localhost:8000
手动启动
# stdio mode
python codex_server.py --mode stdio
# SSE mode
python codex_server.py --mode sse --port 8000 --host localhost
也可以通过一条命令完成设置并启动:
./setup_and_run.sh
手动安装
# Install dependencies
pip install -e .
# Start server
python codex_server.py
🔧 Claude 配置
stdio 模式(推荐)
要在 Claude Desktop 中使用 MCP 服务,请将以下内容添加到配置文件中:
macOS
~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"openai-codex": {
"command": "python",
"args": ["/path/to/openai-codex-mcp/codex_server.py", "--mode", "stdio"],
"env": {
"PATH": "/usr/local/bin:/usr/bin:/bin"
}
}
}
}
Windows
%APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"openai-codex": {
"command": "python",
"args": ["C:\\path\\to\\openai-codex-mcp\\codex_server.py", "--mode", "stdio"],
"env": {
"PATH": "C:\\Program Files\\nodejs;C:\\Windows\\System32"
}
}
}
}
SSE 模式
在 SSE 模式下,可以通过 HTTP 端点访问 MCP 服务:
# Start server
./run_sse.sh 8000
# Available endpoints
# GET http://localhost:8000/sse - SSE connection
# POST http://localhost:8000/message - Send message
💡 使用方法
在 Claude Desktop 中配置 MCP 服务后,可以按以下方式使用这些工具:
基本代码生成
@openai-codex codex_agent prompt="Create a Python function to calculate Fibonacci numbers"
针对特定任务进行优化
@openai-codex codex_agent prompt="Explain this code" task_type="code-explanation"
@openai-codex codex_agent prompt="Fix the bug in utils.py" task_type="debugging" model="o4-preview"
@openai-codex codex_agent prompt="Check for security vulnerabilities" task_type="security"
自动化级别设置
# Suggestions only (default, safest)
@openai-codex codex_agent prompt="Refactor this code" approval_mode="suggest"
# Auto-edit (automatic file read/write, command execution requires confirmation)
@openai-codex codex_agent prompt="Explain this codebase" approval_mode="auto-edit"
# Full auto (fully automatic execution in network-disabled sandbox)
@openai-codex codex_agent prompt="Create and run tests" approval_mode="full-auto"
多模态(图像输入)
@openai-codex codex_agent prompt="Implement this UI design" images=["design.png"] task_type="code-generation"
使用不同的 AI 提供商
@openai-codex codex_agent prompt="Review this code" provider="azure" model="gpt-4.1"
@openai-codex codex_agent prompt="Explain this" provider="ollama" model="llama3"
交互式会话
@openai-codex codex_interactive initial_prompt="Tell me about the project structure" approval_mode="auto-edit"
🎯 任务类型
使用 task_type 参数,生成针对特定任务优化的提示词:
general:常规编码协助(默认)code-generation:生成新代码code-explanation:解释现有代码debugging:查找并修复错误refactoring:改进代码结构testing:编写或修复测试security:安全分析与修复documentation:生成或改进文档
🤖 AI 提供商
通过 provider 参数支持以下 AI 提供商:
openai:OpenAI(默认)azure:Azure OpenAIgemini:Google Geminiollama:Ollama(本地模型)mistral:Mistral AIdeepseek:DeepSeekxai:xAIgroq:Groq
🔒 审批模式
suggest:仅提出更改建议,所有操作都需要审批(最安全)auto-edit:可自动读取和写入文件,执行 shell 命令时会询问full-auto:在禁用网络的沙盒中完全自主运行(功能最强大)
🛡️ 安全性
full-auto模式在禁用网络的沙盒中运行,以确保安全- 文件操作仅限于当前工作目录
- 除非处于
full-auto模式,否则所有 shell 命令都需要明确审批
🐛 故障排除
常见问题
-
“codex command not found”
npm install -g @openai/codex -
脚本权限被拒绝
chmod +x *.sh -
Python 版本问题
- 确保已安装 Python 3.12+
- 使用虚拟环境:
python3 -m venv venv && source venv/bin/activate
-
MCP 连接问题
- 检查 Claude Desktop 配置文件语法
- 确认文件路径为绝对路径
- 配置更改后重启 Claude Desktop
📝 许可证
MIT License with Attribution——详情请参阅 LICENSE 文件。
🤝 贡献
欢迎贡献!请随时提交 Pull Request。
📞 支持
如果遇到任何问题或有疑问,请在 GitHub 上提出 issue。
为 Claude + OpenAI Codex 社区倾心打造 ❤️
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。