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., "@opencode MCP serversummarize the structure of this project"
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.
opencode MCP server
A small, dependency-light MCP (stdio) server that lets Claude Code delegate cheap, mechanical work to opencode's free models — codebase summaries, exploration, web research, boilerplate, first drafts, contained bulk edits — so paid tokens go where they matter.
Python 3.10+, stdlib + the official mcp SDK. Runs on Linux and Windows.
Tools
Tool | Purpose |
| Run one task on a free model. |
| Named sessions with opencode ids, dirs, turn counts, token/cost tallies. |
| Drop a name from local bookkeeping (opencode's server-side session survives). |
| Liveness + doctor: resolves the binary, reports version, round-trips one prompt. |
| List model ids (free only by default — free ids rotate). |
Related MCP server: CodexMCP
Safety model
The worker is a cheap model; the guardrails assume it will occasionally do something dumb.
Read-only by default.
mode:"read"maps toopencode --agent plan. Verified behavior: file writes and bash mutations are refused (nothing ever hit disk in testing); read-only shell commands and network (websearch) still work — read mode is not offline.Write mode is confined.
dirmust be an absolute, existing directory; the filesystem root, the home directory itself, and system paths (/etc,/usr,/var, …,C:\Windows,C:\Program Files*) are refused, including their subtrees. Optionally setOPENCODE_MCP_ALLOWED_DIRS(pathsep-separated roots) to allowlist where write mode may operate.Never
--auto. opencode's own permission prompts stay denied in non-interactive runs.Everything is reported.
files_changedandtools_usedcome back on every call; point write mode at git-tracked dirs so you can diff/revert.Hard timeout with tree-kill (opencode spawns child processes): POSIX process-group kill, Windows
taskkill /T /F. Cancelling the MCP call kills the worker too. Timeouts return partial results and keep the session resumable.One call per session name at a time; parallel calls on different sessions are fine.
Install & register
cd /root/agent-mcp
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
# register with Claude Code (user scope):
claude mcp add -s user opencode -- /root/agent-mcp/.venv/bin/python /root/agent-mcp/server.pyWindows (PowerShell):
cd C:\path\to\agent-mcp
py -3 -m venv .venv
.venv\Scripts\pip install -r requirements.txt
claude mcp add -s user opencode -- C:\path\to\agent-mcp\.venv\Scripts\python.exe C:\path\to\agent-mcp\server.pyWindows smoke check (3 commands):
opencode --version # CLI reachable?
.venv\Scripts\python -m unittest discover -s tests # parser/guards/kill-path
.venv\Scripts\python tests\e2e_client.py # live free-model round-tripConfiguration (env vars, all optional)
Var | Default | Meaning |
| auto-detect | Path to the opencode executable. Auto-detection: PATH, then the real |
|
| Default model id. |
|
| Where |
|
| Default per-call timeout (s); per-call |
|
| Truncate the worker's answer beyond this many chars ( |
| unset | If set, write-mode |
Giving the worker MCP tools
Pass opencode_config (absolute path) to delegate, pointing at e.g.:
{
"mcp": {
"gbk-fs": {
"type": "local",
"command": ["/root/gbk-fs/.venv/bin/python3", "-m", "gbk_fs"],
"enabled": true
}
}
}Verified live: the free model discovers and calls such tools (they surface to
it as gbk-fs_list_files, etc.).
Tests
.venv/bin/python -m unittest discover -s tests # offline: real captured fixtures
.venv/bin/python tests/e2e_client.py # live: needs network, ~1-2 min, $0Design notes / gotchas (hard-won)
The task prompt is piped via stdin (write, close). Never pass it in argv: a
--separator makes opencode drop the message and hang waiting on stdin, and Windows caps argv at 32 KB.Resume sessions with
-s <ses_id>(never--continue).opencode run --format jsonemits JSONL events; the answer is the concatenation oftextparts, tokens/cost arrive instep-finishparts, file writes are completedtoolparts (write/edit/patch/multiedit) withstate.input.filePath.Pipes are forced to UTF-8 (
errors="replace") — Windows would otherwise default to cp125x. stderr goes to a temp file to avoid two-pipe deadlock.Free model ids rotate; the
modelstool exists so the orchestrator can self-correct when the default disappears.
This server cannot be deployed
Maintenance
Related MCP Connectors
No-data MCP handoff for local Claude Code to Codex harness moves. $49 lifetime.
Agent personas for Claude. 16 tools, 13 personas, 3 workflows. Zero extra API cost. Free.
Claude Code / MCP skills for the dev pipeline: discover, spec, design, build, ship, operate.
Live SEO workflow tools for Claude Code, Codex, and AI agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables Claude to delegate coding tasks to local Ollama models, reducing API token usage by up to 98.75% while leveraging local compute resources. Supports code generation, review, refactoring, and file analysis with Claude providing oversight and quality assurance.330 npm24AGPL 3.0
- FlicenseNot gradedqualityCmaintenanceEnables Claude to offload mechanical, output-heavy tasks like boilerplate, type generation, and summarization to OpenAI while keeping reasoning in-context.-
- AlicenseAqualityBmaintenanceLets your primary coding agent delegate grunt work to a cheaper model via OpenCode, enabling cost-effective task distribution.5MIT
- AlicenseNot gradedqualityBmaintenanceLets Claude Code delegate tasks to the OpenCode CLI, choosing cost-effective models by intelligence tier and tracking usage.16,503 npmMIT