Codex to OpenCode MCP Server
Enables Codex to delegate coding tasks to an OpenCode CLI locally, returning structured results such as exit codes, session summaries, tool calls, and git diffs.
README
Codex to OpenCode MCP Server
A small local MCP (Model Context Protocol) server that lets Codex delegate coding work to
OpenCode. It uses the official MCP Python SDK, the stdio transport, and an asynchronous
OpenCode subprocess.
Tools
opencode_execute
opencode_execute(
task: str,
working_directory: str,
model: str | None = None,
reasoning_effort: str | None = None,
timeout: int = 1800,
)
Runs this command without a shell:
opencode run --format json --dir <working_directory> --auto [--model <model>] [--variant <reasoning_effort>] <task>
reasoning_effort maps to OpenCode's provider-specific --variant option. Common values
include minimal, low, medium, high, and max, but the available variants are defined
by the selected provider and model. The MCP server intentionally accepts any non-empty value
instead of enforcing a provider-specific enum.
Example:
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,
)
It returns structured output containing:
- success, timeout, exit code, and elapsed time;
- OpenCode session ID and final assistant summary;
- completed OpenCode tool calls and errors;
- bounded stdout/stderr captures;
- final
git status --short,git diff --stat, and a bounded unified diff.
The Git fields are post-run snapshots. They can include changes that were already present before the call. Text contents of untracked files are represented as new-file patches; binary untracked files are reported by path and size.
opencode_check
Resolves the configured OpenCode executable and runs opencode --version without modifying
the environment.
Install
Requirements: Python 3.11+, Git (optional for diff reporting), and 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 must be installed and authenticated independently. Verify it first:
opencode --version
opencode auth list
The OpenCode desktop application and the OpenCode CLI are separate entry points on Windows.
An OpenCode.exe --version invocation that opens the GUI and prints nothing is not a usable
CLI. Install the official CLI when needed:
npm install -g opencode-ai
If opencode is not in PATH, set OPENCODE_MCP_COMMAND to its absolute executable path.
On Windows npm installations, prefer the native binary under
node_modules\opencode-ai\bin\opencode.exe; the server also detects and bypasses the
opencode.cmd wrapper automatically.
Connect Codex
Add the server through the Codex CLI, which avoids hand-editing configuration:
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
When OpenCode is already in PATH, omit the --env option:
codex mcp add opencode -- C:\path\to\opencode-mcp\.venv\Scripts\python.exe -m opencode_mcp.server
Then verify registration:
codex mcp list
Restart Codex after changing MCP configuration. The server writes protocol messages only to
stdout and sends logs to stderr, as required for stdio MCP servers.
Configuration
| Environment variable | Default | Meaning |
|---|---|---|
OPENCODE_MCP_COMMAND |
opencode |
Executable name or absolute path |
OPENCODE_MCP_ARGS |
[] |
JSON array inserted after the executable (useful for wrappers/tests) |
OPENCODE_MCP_AUTO_APPROVE |
true |
Add OpenCode's --auto permission flag |
OPENCODE_MCP_MAX_OUTPUT_BYTES |
2097152 |
Tail bytes retained independently for stdout/stderr |
OPENCODE_MCP_LOG_LEVEL |
INFO |
Server log level written to stderr |
Setting auto-approval to false makes OpenCode reject permissions it cannot ask interactively:
$env:OPENCODE_MCP_AUTO_APPROVE = "false"
Debug
Run the automated tests:
.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 .
Run the server under MCP Inspector:
uv run --python 3.11 --with-editable ".[dev]" mcp dev src\opencode_mcp\server.py
The MCP tool timeout should be slightly longer than the timeout passed to
opencode_execute; otherwise Codex may cancel the MCP request before the server can terminate
OpenCode and return diagnostics.
Security model
opencode_execute is intentionally a write-capable, potentially destructive tool. It grants
OpenCode the same filesystem and process permissions as this MCP server. The implementation:
- never invokes a shell for OpenCode tasks;
- requires an existing absolute working-directory path;
- bounds captured output to protect Codex context;
- terminates the OpenCode process tree on timeout or MCP cancellation;
- disables OpenCode auto-update during delegated runs;
- marks the MCP tool as non-idempotent and potentially destructive.
Use a restricted OS account or sandbox when delegating untrusted tasks or repositories.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。