opencode MCP server

opencode MCP server

Lets Claude Code offload cheap, mechanical tasks to opencode's free models for codebase summaries, exploration, web research, and bulk edits, saving paid tokens.

Category
访问服务器

README

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
delegate Run one task on a free model. mode:"read" (default) is enforced read-only; mode:"write" may edit files under dir. Supports named sessions (multi-turn), file attachments, per-call model/timeout, and opencode_config to hand the worker extra MCP servers.
list_sessions Named sessions with opencode ids, dirs, turn counts, token/cost tallies.
forget_session Drop a name from local bookkeeping (opencode's server-side session survives).
ping Liveness + doctor: resolves the binary, reports version, round-trips one prompt.
models List model ids (free only by default — free ids rotate).

Safety model

The worker is a cheap model; the guardrails assume it will occasionally do something dumb.

  • Read-only by default. mode:"read" maps to opencode --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. dir must 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 set OPENCODE_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_changed and tools_used come 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.py

Windows (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.py

Windows 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-trip

Configuration (env vars, all optional)

Var Default Meaning
OPENCODE_MCP_BIN auto-detect Path to the opencode executable. Auto-detection: PATH, then the real opencode.exe behind npm .cmd shims on Windows, then ~/.opencode/bin/opencode.
OPENCODE_MCP_MODEL opencode/deepseek-v4-flash-free Default model id.
OPENCODE_MCP_STATE ~/.local/state/opencode-mcp / %LOCALAPPDATA%\opencode-mcp Where sessions.json lives.
OPENCODE_MCP_TIMEOUT 180 Default per-call timeout (s); per-call timeout_sec clamps to 10–570.
OPENCODE_MCP_MAX_TEXT 40000 Truncate the worker's answer beyond this many chars (truncated: true).
OPENCODE_MCP_ALLOWED_DIRS unset If set, write-mode dir must live under one of these roots.

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, $0

Design 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 json emits JSONL events; the answer is the concatenation of text parts, tokens/cost arrive in step-finish parts, file writes are completed tool parts (write/edit/patch/multiedit) with state.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 models tool exists so the orchestrator can self-correct when the default disappears.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选