opencode-mcp

opencode-mcp

Bridges MCP clients to OpenCode's headless API, enabling AI to delegate autonomous coding tasks like building features, debugging, and refactoring across multiple projects.

Category
访问服务器

README

opencode-mcp

npm version license node npm downloads

Give any MCP client the power of OpenCode.

opencode-mcp is an MCP server that bridges your AI tools (Claude, Cursor, Windsurf, VS Code, etc.) to OpenCode's headless API. It lets your AI delegate real coding work — building features, debugging, refactoring, running tests — to OpenCode sessions that autonomously read, write, and execute code in your project.

80 tools | 10 resources | 6 prompts | Multi-project | Auto-start

Why Use This?

  • Delegate coding tasks — Tell Claude "build me a REST API" and it delegates to OpenCode, which creates files, installs packages, writes tests, and reports back.
  • Parallel work — Fire off multiple tasks to OpenCode while your primary AI keeps working on something else.
  • Any MCP client — Works with Claude Desktop, Claude Code, Cursor, Windsurf, VS Code Copilot, Cline, Continue, Zed, Amazon Q, and any other MCP-compatible tool.
  • Zero setup — The server auto-starts the OpenCode HTTP server in-process via the official @opencode-ai/sdk if one isn't already running. No manual steps.

Quick Start

Prerequisite: OpenCode must be installed. curl -fsSL https://opencode.ai/install | bash or npm i -g opencode-ai or brew install sst/tap/opencode

Claude Code:

claude mcp add opencode -- npx -y opencode-mcp

Claude Desktop / Cursor / Windsurf / Cline / Continue (add to your MCP config):

{
  "mcpServers": {
    "opencode": {
      "command": "npx",
      "args": ["-y", "opencode-mcp"]
    }
  }
}

That's it. Restart your client and OpenCode's tools will be available.

See Configuration for all client configs (VS Code Copilot, Zed, Amazon Q, etc.) and environment variables.

How It Works

MCP Client  <--stdio-->  opencode-mcp  <--HTTP-->  OpenCode Server
(Claude, Cursor, etc.)   (this package)            (in-process via @opencode-ai/sdk,
                                                    or external opencode serve)

Your MCP client calls tools over stdio. This server translates them into HTTP requests to the OpenCode headless API. If no OpenCode server is reachable at OPENCODE_BASE_URL, one is started in-process via the official @opencode-ai/sdk. The directory parameter on every tool routes that request to a specific project via the x-opencode-directory header, so a single MCP instance can fan out across many project roots.

Key Tools

The 80 tools are organized into tiers. Start with the workflow tools — they handle the common patterns in a single call.

Workflow Tools (13) — Start Here

Tool What it does
opencode_setup Check server health, providers, and project status. Use first.
opencode_ask Create session + send prompt + get answer. One call.
opencode_reply Follow-up message in an existing session
opencode_run Send a task and wait for completion (session + async send + polling)
opencode_fire Fire-and-forget: dispatch a task, return immediately
opencode_check Compact progress report for a running session (status, todos, files changed)
opencode_conversation Get formatted conversation history
opencode_sessions_overview Quick overview of all sessions
opencode_context Project + VCS + config + agents in one call
opencode_review_changes Formatted diff summary for a session
opencode_wait Poll an async session until it finishes
opencode_provider_test Quick-test whether a provider is working
opencode_status Health + providers + sessions + VCS dashboard

Recommended Patterns

Quick question:

opencode_ask({ prompt: "Explain the auth flow in this project" })

Build something and wait:

opencode_run({ prompt: "Add input validation to POST /api/users", maxDurationSeconds: 300 })

Parallel background tasks:

opencode_fire({ prompt: "Refactor the auth module to use JWT" })
→ returns sessionId immediately
opencode_check({ sessionId: "..." })
→ check progress anytime

All Tool Categories

Category Count Description
Workflow 13 High-level composite operations
Session 20 Create, list, fork, share, abort, revert, permissions
Message 6 Send prompts, execute commands, run shell
File & Search 6 Search text/regex, find files/symbols, read files
System 13 Health, VCS, LSP, MCP servers, agents, logging
TUI Control 9 Remote-control the OpenCode terminal UI
Provider & Auth 6 List providers/models, set API keys, OAuth
Config 3 Get/update configuration
Project 3 List, inspect, and initialize projects
Events 1 Poll real-time SSE events

Resources (10)

Browseable data endpoints — your client can read these without tool calls:

URI Description
opencode://project/current Current active project
opencode://config Current configuration
opencode://providers Providers with models
opencode://agents Available agents
opencode://commands Available commands
opencode://health Server health and version
opencode://vcs Version control info
opencode://sessions All sessions
opencode://mcp-servers MCP server status
opencode://file-status VCS file status

Prompts (6)

Guided workflow templates your client can offer as selectable actions:

Prompt Description
opencode-code-review Review diffs from a session
opencode-debug Step-by-step debugging workflow
opencode-project-setup Get oriented in a new project
opencode-implement Have OpenCode build a feature
opencode-best-practices Setup, tool selection, monitoring, and pitfalls
opencode-session-summary Summarize what happened in a session

Multi-Project Support

Every tool accepts an optional directory parameter to target a different project. No restarts needed.

opencode_ask({ directory: "/home/user/mobile-app", prompt: "Add navigation" })
opencode_ask({ directory: "/home/user/web-app", prompt: "Add auth" })

Use opencode_project_init to scaffold a new project directory (or open a preexisting one) before the first call, so the OpenCode server registers it as a project:

opencode_project_init({ path: "/home/user/new-project" })
// → "Successfully initialized project directory at: /home/user/new-project"

opencode_run({ directory: "/home/user/new-project", prompt: "Set up a Vite + React app" })

Environment Variables

All optional. Only needed if you've changed defaults on the OpenCode server.

Variable Default Description
OPENCODE_BASE_URL http://127.0.0.1:4096 OpenCode server URL
OPENCODE_SERVER_USERNAME opencode HTTP basic auth username
OPENCODE_SERVER_PASSWORD (none) HTTP basic auth password (enables auth when set)
OPENCODE_AUTO_SERVE true Auto-start an in-process OpenCode server (via @opencode-ai/sdk) if none is reachable at OPENCODE_BASE_URL
OPENCODE_DEFAULT_PROVIDER (none) Default provider ID when not specified per-tool (e.g. anthropic)
OPENCODE_DEFAULT_MODEL (none) Default model ID when not specified per-tool (e.g. claude-sonnet-4-5)

Development

git clone https://github.com/AlaeddineMessadi/opencode-mcp.git
cd opencode-mcp
npm install
npm run build
npm start        # run the MCP server
npm run dev      # watch mode
npm test         # 328 tests

Smoke Testing

End-to-end test against a running OpenCode server:

npm run build && node scripts/mcp-smoke-test.mjs

Documentation

References

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选