Codex to OpenCode MCP Server
Codex 到 OpenCode MCP 服务器
一个本地小型 MCP(模型上下文协议)服务器,让 Codex 将编码工作委托给 OpenCode。它使用官方 MCP Python SDK、stdio 传输,以及一个异步 OpenCode 子进程。
工具
opencode_execute
opencode_execute(
task: str,
working_directory: str,
model: str | None = None,
reasoning_effort: str | None = None,
timeout: int = 1800,
)在不使用 shell 的情况下运行此命令:
opencode run --format json --dir <working_directory> --auto [--model <model>] [--variant <reasoning_effort>] <task>reasoning_effort 映射到 OpenCode 中提供商特定的 --variant 选项。常见值包括 minimal、low、medium、high 和 max,但可用的 variant 由所选提供商和模型决定。MCP 服务器有意接受任意非空值,而不是强制使用提供商特定的枚举。
示例:
opencode_execute(
task="Implement uncertainty propagation and run the unit tests.",
working_directory="C:\\path\\to\\NuSR",
model="pinche_10/gpt-5.6-sol",
reasoning_effort="high",
timeout=1800,
)它返回包含以下内容的结构化输出:
成功与否、是否超时、退出代码和耗时;
OpenCode 会话 ID 和最终助手摘要;
已完成的 OpenCode 工具调用及错误;
有上限的 stdout/stderr 捕获结果;
最终的
git status --short、git diff --stat,以及有上限的 unified diff。
这些 Git 字段是运行后的快照。它们可能包含调用之前就已存在的更改。未跟踪文件的文本内容会以新文件补丁的形式呈现;未跟踪的二进制文件则会按路径和大小报告。
opencode_check
确定已配置的 OpenCode 可执行文件,然后运行 opencode --version,且不修改环境。
Related MCP server: Claude Code Manager WAN
安装
要求:Python 3.11+、Git(用于 diff 报告,可选)以及 OpenCode。
git clone https://github.com/TAO-MINGYU/codex_to_opencode.git
cd codex_to_opencode
uv venv --python 3.11 .venv
uv pip install --python .venv\Scripts\python.exe -e ".[dev]"OpenCode 必须单独安装并完成身份验证。请先验证:
opencode --version
opencode auth list在 Windows 上,OpenCode 桌面应用和 OpenCode CLI 是两个独立的入口点。调用 OpenCode.exe --version 只会打开 GUI 而不打印任何内容,不算是可用的 CLI。需要时请安装官方 CLI:
npm install -g opencode-ai如果 opencode 不在 PATH 中,请将 OPENCODE_MCP_COMMAND 设置为其可执行文件的绝对路径。在 Windows 的 npm 安装中,优先使用 node_modules\opencode-ai\bin\opencode.exe 下的原生二进制;服务器也会自动检测并跳过 opencode.cmd 包装器。
连接 Codex
通过 Codex CLI 添加服务器,从而避免手动编辑配置:
codex mcp add opencode --env OPENCODE_MCP_COMMAND=C:\path\to\opencode.exe -- C:\path\to\opencode-mcp\.venv\Scripts\python.exe -m opencode_mcp.server当 OpenCode 已在 PATH 中时,省略 --env 选项:
codex mcp add opencode -- C:\path\to\opencode-mcp\.venv\Scripts\python.exe -m opencode_mcp.server然后验证注册:
codex mcp list更改 MCP 配置后重启 Codex。服务器只将协议消息写入 stdout,并将日志发送到 stderr,这正是 stdio MCP 服务器的要求。
配置
环境变量 | 默认值 | 含义 |
|
| 可执行文件名或绝对路径 |
|
| 在可执行文件之后插入的 JSON 数组(用于包装器/测试) |
|
| 添加 OpenCode 的 |
|
| 分别保留的 stdout/stderr 尾部字节数 |
|
| 写入 stderr 的服务器日志级别 |
将自动批准设为 false 会让 OpenCode 拒绝无法交互式请求的权限:
$env:OPENCODE_MCP_AUTO_APPROVE = "false"调试
运行自动化测试:
.venv\Scripts\python.exe -m pytest --cov=opencode_mcp --cov-fail-under=80
.venv\Scripts\python.exe -m ruff check .
.venv\Scripts\python.exe -m ruff format --check .在 MCP Inspector 下运行服务器:
uv run --python 3.11 --with-editable ".[dev]" mcp dev src\opencode_mcp\server.pyMCP 工具的超时时间应略长于传给 opencode_execute 的 timeout;否则 Codex 可能会在服务器终止 OpenCode 并返回诊断信息之前取消 MCP 请求。
安全模型
opencode_execute 是一个可写、可能具有破坏性的工具。它授予 OpenCode 与本 MCP 服务器相同的文件系统和进程权限。其实现:
绝不会为 OpenCode 任务调用 shell;
要求提供已存在的绝对工作目录路径;
限制捕获的输出,以保护 Codex 上下文;
在超时或 MCP 取消时终止 OpenCode 进程树;
在委托运行期间禁用 OpenCode 自动更新;
将该 MCP 工具标记为不可幂等且可能具有破坏性。
在委托不受信任的任务或仓库时,请使用受限的 OS 账户或沙箱。
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables Claude Code to delegate tasks to OpenAI's Codex CLI (GPT-5.4) with structured execution traces, parallel execution, session persistence, and adversarial code review.15MIT
- FlicenseNot gradedqualityCmaintenanceEnables ISLI agents and MCP clients to dispatch natural-language coding and terminal tasks to a locally-installed Claude Code CLI, supporting both one-shot execution and persistent sessions with workspace and security controls.
- AlicenseAqualityAmaintenanceEnables MCP clients like Claude Code and Codex to delegate coding tasks to Cursor's CLI agent, which implements changes in the workspace and returns clean, structured results for review.36994MIT
- AlicenseAqualityCmaintenanceEnables Codex/ChatGPT to coordinate OpenCode agents, managing tasks, sessions, parallel execution, and project context through 25 local tools.2510MIT
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/TAO-MINGYU/codex_to_opencode'
If you have feedback or need assistance with the MCP directory API, please join our Discord server