Codex to OpenCode MCP Server
Codex to OpenCode MCP Server
Ein kleiner lokaler MCP-Server (Model Context Protocol), mit dem Codex Programmierarbeiten an OpenCode delegieren kann. Er nutzt das offizielle MCP-Python-SDK, den stdio-Transport und einen asynchronen OpenCode-Subprozess.
Werkzeuge
opencode_execute
opencode_execute(
task: str,
working_directory: str,
model: str | None = None,
reasoning_effort: str | None = None,
timeout: int = 1800,
)Führt diesen Befehl ohne Shell aus:
opencode run --format json --dir <working_directory> --auto [--model <model>] [--variant <reasoning_effort>] <task>reasoning_effort wird auf die anbieterspezifische Option --variant von OpenCode abgebildet. Übliche Werte sind minimal, low, medium, high und max, aber die verfügbaren Varianten werden vom ausgewählten Anbieter und Modell bestimmt. Der MCP-Server akzeptiert bewusst jeden nicht‑leeren Wert, statt eine anbieterspezifische Aufzählung zu erzwingen.
Beispiel:
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,
)Er liefert eine strukturierte Ausgabe, die Folgendes enthält:
Erfolg, Timeout, Exit-Code und verstrichene Zeit;
OpenCode-Sitzungs-ID und finale Zusammenfassung des Assistenten;
abgeschlossene OpenCode-Toolaufrufe und Fehler;
begrenzte stdout/stderr-Erfassungen;
abschließend
git status --short,git diff --statund einen begrenzten Unified-Diff.
Die Git-Felder sind Momentaufnahmen nach der Ausführung. Sie können Änderungen enthalten, die bereits vor dem Aufruf vorhanden waren. Textinhalte nicht versionierter Dateien werden als Patches für neue Dateien dargestellt; binäre nicht versionierte Dateien werden mit Pfad und Größe gemeldet.
opencode_check
Ermittelt die konfigurierte OpenCode-Programmdatei und führt opencode --version aus, ohne die Umgebung zu verändern.
Related MCP server: codex-mcp
Installation
Voraussetzungen: Python 3.11+, Git (optional für Diff-Berichte) und 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 muss separat installiert und authentifiziert sein. Überprüfen Sie dies zuerst:
opencode --version
opencode auth listDie OpenCode-Desktopanwendung und die OpenCode-CLI sind unter Windows getrennte Einstiegspunkte. Ein Aufruf von OpenCode.exe --version, der die GUI öffnet und nichts ausgibt, ist keine brauchbare CLI. Installieren Sie bei Bedarf die offizielle CLI:
npm install -g opencode-aiWenn opencode nicht im PATH liegt, setzen Sie OPENCODE_MCP_COMMAND auf den absoluten Programmdateipfad. Bei npm-Installationen unter Windows bevorzugen Sie die native Datei unter node_modules\opencode-ai\bin\opencode.exe; der Server erkennt und umgeht den opencode.cmd-Wrapper außerdem automatisch.
Codex verbinden
Fügen Sie den Server über die Codex-CLI hinzu, um die Konfiguration nicht von Hand bearbeiten zu müssen:
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.serverWenn OpenCode bereits im PATH ist, lassen Sie die Option --env weg:
codex mcp add opencode -- C:\path\to\opencode-mcp\.venv\Scripts\python.exe -m opencode_mcp.serverÜberprüfen Sie anschließend die Registrierung:
codex mcp listStarten Sie Codex nach der Änderung der MCP-Konfiguration neu. Der Server schreibt Protokollmeldungen nur nach stdout und sendet Logs an stderr, wie es für stdio-MCP-Server erforderlich ist.
Konfiguration
Umgebungsvariable | Standardwert | Bedeutung |
|
| Name der ausführbaren Datei oder absoluter Pfad |
|
| JSON-Array nach der ausführbaren Datei (nützlich für Wrapper/Tests) |
|
| Fügt das Berechtigungs‑Flag |
|
| Für stdout/stderr getrennt zurückbehaltene Endbytes |
|
| Auf stderr geschriebene Log‑Ebene des Servers |
Wird die automatische Genehmigung deaktiviert, weist OpenCode Berechtigungen ab, die es nicht interaktiv abfragen kann:
$env:OPENCODE_MCP_AUTO_APPROVE = "false"Debugging
Führen Sie die automatisierten Tests aus:
.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 .Führen Sie den Server unter dem MCP Inspector aus:
uv run --python 3.11 --with-editable ".[dev]" mcp dev src\opencode_mcp\server.pyDer Timeout des MCP-Tools sollte etwas länger sein als der an opencode_execute übergebene timeout; andernfalls könnte Codex die MCP-Anfrage abbrechen, bevor der Server OpenCode beenden und Diagnoseinformationen zurückgeben kann.
Sicherheitsmodell
opencode_execute ist bewusst ein schreibfähiges, potenziell destruktives Werkzeug. Es gewährt OpenCode dieselben Dateisystem- und Prozessrechte wie diesem MCP-Server. Die Implementierung:
ruft für einen OpenCode-Aufgaben keine Shell auf;
verlangt einen vorhandenen absoluten Arbeitsverzeichnis-Pfad;
begrenzt die erfasste Ausgabe, um den Codex-Kontext zu schützen;
zeigt den OpenCode-Prozessbaum beendet bei Timeout oder MCP-Abbruch;
deaktiviert die automatische OpenCode-Aktualisierung während delegierter Läufe;
markiert das MCP-Tool als nicht idempotent und potenziell destruktiv.
Verwenden Sie beim Delegieren nicht vertrauenswürdiger Aufgaben oder Repositorys ein eingeschränktes Betriebssystemkonto oder eine Sandbox.
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.
Related MCP Connectors
Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Let ChatGPT and Claude read and edit files, search and run commands on your own computer.
Use your own Windows, Mac or Linux computer from ChatGPT, Claude, Cursor or Gemini CLI: run commands, read, write and search files, run long processes. Your computer only makes an outgoing connection (no open ports or VPN). Read-only mode, allowed folders, blocked commands and an action log keep you in control. Free plan available.
Context, runtime and review for AI coding agents. One local install.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceLets 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
- AlicenseAqualityDmaintenanceEnables MCP-compatible coding agents to execute the local Codex CLI as a coding agent, including code reviews, session resume/fork, and CLI diagnostics.9MIT
- 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.18 npmMIT
- AlicenseAqualityBmaintenanceEnables 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.1MIT