Codex to OpenCode MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Codex to OpenCode MCP Server Run OpenCode to refactor the payment module and run its unit tests"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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.
Related MCP server: codex-mcp
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 listThe 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-aiIf 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.serverWhen 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.serverThen verify registration:
codex mcp listRestart 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 |
|
| Executable name or absolute path |
|
| JSON array inserted after the executable (useful for wrappers/tests) |
|
| Add OpenCode's |
|
| Tail bytes retained independently for stdout/stderr |
|
| 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.pyThe 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.
Available Tools
2 toolsopencode_checkCheck the local OpenCode installationARead-onlyIdempotent
Resolve the configured OpenCode executable and report its version.
Inputs: no named parameters. Returns: OpenCode executable diagnostic result.
opencode_executeExecute a coding task with OpenCodeADestructive
Delegate one repository coding task to OpenCode.
OpenCode runs non-interactively in the supplied directory, may read and modify files, execute terminal commands, run tests, and use Git. The result contains OpenCode's final text, observed tool calls, diagnostics, and the final Git working-tree diff. The Git diff is a post-run snapshot and can include changes that existed before this call.
Inputs: task (required), working_directory (required), model, timeout, +1 more. Returns: Structured result of one OpenCode execution.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The two tools have clearly distinct roles: opencode_execute delegates a coding task, while opencode_check resolves the executable and reports its version. There is no realistic confusion between performing an action and checking the installation.
Both tools use the same opencode_ prefix followed by a concise imperative verb, maintaining a consistent snake_case pattern. Though the prefix is a product name, the convention is uniform and predictable.
Two tools is at the low end of typical server scope and feels thin for a coding integration. However, the narrow focus on delegating a single task plus a health check is reasonable enough to be borderline appropriate.
The server covers its core purpose: opencode_execute handles task delegation, and opencode_check verifies the underlying executable. Obvious lifecycle tools such as cancellation or querying current task status are absent, but they fall outside the stated minimal purpose.
Maintenance
Related MCP Connectors
Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Work on your own computers from Claude or ChatGPT: run commands, edit and search files.
Source-checked CLI guides and model-aware planning for Claude Code, Codex, and Grok Build.
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceLets Codex delegate coding and repository work to an installed Claude Code CLI with permission-aware inspect/write access, model and effort selection, resumable and cloud-attached sessions, and durable synchronous or asynchronous jobs.MIT
- AlicenseAqualityCmaintenanceEnables MCP-compatible coding agents to execute the local Codex CLI as a coding agent, including code reviews, session resume/fork, and CLI diagnostics.911 npmMIT
- AlicenseBqualityBmaintenanceEnables MCP clients such as Claude Code, Codex CLI, and Cursor-agent to delegate bounded coding tasks to a local OpenCode v2.x installation via a single opencode_execute tool, returning the model's response, git diff/status summary, exit code, and session ID.120 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables Codex to delegate coding tasks to a locally installed AI coding CLI over MCP, returning results, cost and turn metadata, and reusable session IDs for follow-up work.174 npmMIT