mcp-opencode
An MCP server that lets an AI coding agent delegate implementation work to the OpenCode CLI, choosing an explicit provider + model on every call.
README
mcp-opencode
An MCP server that lets an AI coding agent (Claude Code, Codex, or any MCP client) delegate implementation work to the OpenCode CLI — choosing an explicit provider + model on every call.
Use it to orchestrate with one model while offloading the actual code-writing to another: plan in Claude, implement with GLM 5.2, Kimi, DeepSeek, a local Ollama model, or anything else OpenCode can reach.
Provider-agnostic. This server contains no provider-specific logic. It passes your
provider/modelstring straight toopencode run -m, so it works with every provider OpenCode supports (75+ via models.dev, plus local models). Whatever you've authenticated in OpenCode, you can use here.
Why
- Model per task. A cheap model for mechanical edits, a strong one for hard changes — decided per call, not baked into config.
- Real cost/token reporting returned with every run.
- Multi-turn. Continue a session to iterate on the same working tree.
- Safe by construction.
cwdis confined to an allowlist; the child process tree is killed cleanly on timeout/abort/cost-cap; secrets are redacted from anything echoed back.
Prerequisites
- Node.js ≥ 20
- The OpenCode CLI installed and on
PATH, with at least one provider authenticated (opencode auth login). Runopencode modelsto see what's available to you.
Register
No install step needed — npx fetches and runs the published package.
Claude Code:
claude mcp add -s user opencode \
-e OPENCODE_MCP_ROOTS="$HOME/Projects" \
-- npx -y mcp-opencode
Codex:
codex mcp add opencode \
--env OPENCODE_MCP_ROOTS="$HOME/Projects" \
-- npx -y mcp-opencode
Restart the client (or run claude mcp list / codex mcp list) to confirm it
connects. The tools appear as opencode_run, opencode_reply, opencode_models.
Build from source (for development)
git clone https://github.com/shreeraman96/mcp-opencode.git
cd mcp-opencode
npm install
npm run build
npm test # unit tests
npm run smoke # optional: live test against a real free OpenCode model
Then register with node /absolute/path/to/mcp-opencode/dist/index.js instead of
the npx command above.
Tools
opencode_run — start a new session
| field | type | notes |
|---|---|---|
prompt |
string | required — the task |
model |
string | required — provider/model, e.g. fireworks-ai/accounts/fireworks/models/glm-5p2 |
cwd |
string | required — must resolve inside an allowed root (see below) |
agent |
'build' | 'plan' |
default 'build' (plan is read-only) |
variant |
string | optional model variant / reasoning effort (high, max, minimal) |
timeoutSec |
int 30–3600 | default 900 |
maxCostUsd |
number | optional — kill the run and return partial output if exceeded |
Returns status, sessionID, model, elapsed time, tokens/cost, a git-derived
changed-files summary (when cwd is a repo), and the assistant output.
opencode_reply — continue a session
Takes a sessionID (ses_…) from a prior run plus a new prompt, model,
cwd, and agent. model is required on every call — there is no silent
inheritance from the original run, by design.
opencode_models
No input. Runs opencode models and returns the available list.
Example (Claude Code)
Delegate to OpenCode: call
opencode_runwith modelfireworks-ai/accounts/fireworks/models/glm-5p2, cwd~/Projects/myapp, agentbuild, and prompt "add input validation to routes/user.ts".
Swap the model string for anthropic/claude-sonnet-4-5, openai/gpt-oss-120b,
opencode/big-pickle (free), or any local model — nothing else changes.
Configuration
| env var | default | purpose |
|---|---|---|
OPENCODE_MCP_ROOTS |
$HOME/Projects |
colon-separated allowlist of directories cwd may resolve inside |
OPENCODE_MCP_ALLOW_AUTO |
unset | set to 1 to add OpenCode's --auto flag for agent=build runs (see below) |
cwd allowlist
cwd is resolved with fs.realpath (symlinks followed) and must land inside one
of the OPENCODE_MCP_ROOTS directories. Requests outside the allowlist are
rejected before opencode is ever spawned.
Permission model
OpenCode's build agent already runs edit/bash/webfetch non-interactively;
the plan agent is read-only. This server relies on those built-in agent
defaults and does not inject a custom permission config.
Note: passing a custom
permissionblock viaOPENCODE_CONFIGwas found to hangopencode runin a non-TTY environment (an unanswerableaskprompt), so that path is deliberately avoided. Seesrc/policy.ts.
--auto (OpenCode's "auto-approve anything not explicitly denied", which the CLI
itself flags as dangerous) is off by default and only added when you set
OPENCODE_MCP_ALLOW_AUTO=1 and the call uses agent: 'build'.
How it works
src/run.tsspawnsopencodedetached in its own process group, so the whole subprocess tree is killed as a unit (SIGTERM → 5s grace → SIGKILL) on timeout, client abort, or amaxCostUsdbreach. Process exit is treated as the authoritative completion signal.src/parse.tsstreams the--format jsonoutput line-by-line without ever buffering the raw stream; assistant text is capped to head(40k)+tail(10k) chars past 50k total.src/queue.tsserializes runs that share the same resolvedcwd; different working trees run concurrently.src/policy.tsholds the cwd allowlist, model/session validation, secret redaction, and error classification.
For long runs, the server emits MCP progress notifications every 15s (when the client supplies a progress token), which resets the client's idle timeout.
License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。