opencode MCP server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
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: opencode-mcp
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.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Give spare Claude Code or Codex usage to open source. Your agent opens pull requests. No money.
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.
Search the official docs of Claude Code, Cursor, OpenAI Codex and MCP, refreshed daily.
Related MCP Servers
- AlicenseAqualityDmaintenanceLets your primary coding agent delegate grunt work to a cheaper model via OpenCode, enabling cost-effective task distribution.51MIT
- AlicenseNot gradedqualityBmaintenanceLets Claude Code delegate tasks to the OpenCode CLI, choosing cost-effective models by intelligence tier and tracking usage.23,789 npm1MIT
- AlicenseAqualityDmaintenanceLets Claude Code delegate coding tasks to external models running on a local opencode serve, preserving main agent tokens for planning and review.866 npm1MIT
- AlicenseAqualityBmaintenanceEnables delegating Claude Code subagent tasks to cheaper opencode models, while keeping the main Claude Code session connected directly to Anthropic.52,659 npm2MIT