opencode-mcp
Enables asking natural-language questions about any GitHub repository and receiving answers grounded in the actual code, with read-only enforcement and automatic repository fetching.
README
opencode-mcp
MCP server (stdio) exposing an ask_codebase tool: ask a natural-language question about a GitHub repository, get an answer grounded in the real code. READ-ONLY by design.
Built in TypeScript on the official MCP TypeScript SDK, and on opencode running headless as the analysis engine.
How it works
- The server fetches the repo itself — clone if absent, fetch + hard resync otherwise. Fully deterministic: a nonexistent repo fails in seconds with the git error relayed verbatim, zero LLM tokens spent.
- opencode runs headless with
cwd= the repo directory. Noopencode serve, no--attach. The repo's ownAGENTS.md(if any) is loaded as project context. Sessions are opencode-native and scoped per project directory, socontinue_session=truedeterministically means "the latest session of this repo" — cross-repo cross-talk is impossible by construction.
Fetch policy
A clone/fetch runs only when:
- the repo is not in the manifest, or
- its checkout is missing on disk (periodic cleanup), or
- an explicitly requested branch differs from the checked-out one, or
- the last fetch is older than
OPENCODE_REPO_TTL_DAYS(default 3).
Otherwise the existing checkout is used as-is, so the code stays stable across follow-up calls.
Manifest
Known checkouts are tracked in .opencode_mcp_manifest.json (atomic writes, one entry per owner/repo):
{
"owner/repo": {
"dir": "/abs/path",
"branch": "main",
"fetched_at": "2026-07-15T03:21:00Z"
}
}
Read-only enforcement
Two layers:
- A read-only preamble injected into every prompt by this server.
- Your opencode agent config — define an "explore"-style agent with
edit: denyand setOPENCODE_AGENTto force it on every run.
Do not put read-only rules in your global AGENTS.md: it would poison your normal interactive opencode sessions.
Long calls
The hard timeout defaults to 10 minutes and an MCP progress notification is emitted every 15 s (clone/fetch included). Per the MCP spec, clients that reset their request timeout on progress keep the call alive; when the client sends no progressToken, the heartbeat is a no-op. Align the client's own per-call timeout (timeout: in the mcp_servers entry) above the hard one.
Requirements
- Node.js ≥ 20
giton the PATH- opencode CLI (absolute path recommended via
OPENCODE_BIN)
Install
From npm:
npm install -g @mvagnon/opencode-mcp # installs the `opencode-mcp` command
Or run it without installing:
npx -y @mvagnon/opencode-mcp
From source:
npm install
npm run build # server binary: dist/index.js (stdio transport)
Configuration
Declare environment variables in the env: block of the client's mcp_servers entry. Hermes does not pass your full shell env to stdio servers — only PATH, HOME, USER, LANG, LC_ALL, TERM, SHELL, TMPDIR.
| Variable | Default | Purpose |
|---|---|---|
OPENCODE_BIN |
opencode |
opencode binary (absolute path recommended) |
OPENCODE_AGENT |
(none) | opencode agent forced on every run (e.g. explore) |
OPENCODE_REPOS_DIR |
~/codelab/repositories |
Where checkouts live |
OPENCODE_MANIFEST_DIR |
~ |
Directory of .opencode_mcp_manifest.json |
OPENCODE_REPO_TTL_DAYS |
3 |
Re-fetch a repo after this many days |
ASK_CODEBASE_TIMEOUT |
600 |
Hard timeout for the opencode run, in seconds |
Example client entry (Hermes):
mcp_servers:
opencode:
command: npx
args: ["-y", "@mvagnon/opencode-mcp"]
timeout: 660 # keep above ASK_CODEBASE_TIMEOUT
env:
OPENCODE_BIN: /usr/local/bin/opencode
OPENCODE_AGENT: explore
For a from-source checkout, use command: node with args: ["/abs/path/to/opencode-mcp/dist/index.js"] instead.
The ask_codebase tool
| Argument | Type | Description |
|---|---|---|
question |
string |
The natural-language question (e.g. "where is API request auth validated?") |
repo |
string |
Exact GitHub slug owner/repo — no nicknames, no URLs |
branch |
string? |
Optional branch to pin; omit for the default branch |
continue_session |
boolean |
Resume the latest discussion of this repo (default false) |
Use it for architecture questions, where a feature lives, request flow, conventions, design rationale, etc.
Development
npm run lint # eslint
npm run typecheck # tsc --noEmit
npm run build # emit dist/
npm test # node:test unit tests (pure logic)
npm run dev # tsc --watch
Source layout: see AGENTS.md.
Releasing
Releases are fully automated with release-please and npm trusted publishing (OIDC — no npm token stored in the repo):
- Land changes on
mainusing Conventional Commits (feat:,fix:,feat!:…) — they drive the version bump and the changelog. - release-please maintains a release PR that accumulates changes, bumps
package.json, and updatesCHANGELOG.md. - Merging the release PR creates the GitHub release and tag; the
publishjob then publishes to npm via OIDC.
One-time setup (already done once the package exists):
- npm cannot create a package via OIDC, so the first version must be published manually (
npm login && npm publish). - Then on npmjs.com → package → Settings → Trusted Publisher: GitHub Actions, repository
mvagnon/opencode-mcp, workflowrelease.yml.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。