opencode-mcp-bridge
An MCP server that lets any AI tool delegate tasks to the OpenCode CLI as a subagent, with multi-session orchestration, event tracking, and task contracts.
README
opencode-mcp-bridge

A Model Context Protocol (MCP) server that lets any AI tool (Claude Code, Antigravity, VS Code, Cursor, Windsurf, JetBrains, Claude Desktop, etc.) delegate tasks to the OpenCode CLI as a subagent — driven entirely through OpenCode's own opencode serve HTTP/SSE API, with async push events, task contracts, context tracking, checkpoints, and multi-session orchestration.
Agent instructions live in
AGENTS.md— or just call theopencode_guidetool once this server is registered; it returns the same guide live from the running server's actual state.
Architecture
The bridge talks to a single, long-lived opencode serve process over plain HTTP:
- One shared process, unlimited sessions.
server-manager.tsspawns and singleton-managesopencode serve(state tracked in~/.opencode-bridge/server.json); everyopencode_startcall just creates a lightweight session on that one server instead of launching a new CLI process per task. Nonode-ptynative binding, no per-task re-authentication. - One event stream, every session. A single SSE connection to
/api/eventcarries events for all sessions, tagged bydurable.aggregateID;http-bridge.tsfans them out to the right local session (session.next.step.started/ended/failed,session.next.tool.called,session.next.text.delta, …) and derives status (running/idle/waiting_input/error) from them — no ANSI scraping, no idle-timer heuristics. - Self-healing. OpenCode's HTTP API does not surface session-runner failures (e.g. a model resolution error) as API-visible errors or events — a failed session just sits at
runningforever, indistinguishable from working. The bridge tails OpenCode's own internal log (~/.local/share/opencode/log/opencode.log) to detect these failures immediately, and runs a stall watchdog (zero tokens generated N seconds after a prompt) as a second line of defense. Because a single such failure has been observed to wedge that server process's entire turn queue, detecting one triggers an automatic restart ofopencode serveso subsequent sessions aren't collateral damage.
Features
- ⚡ Async Events: Writes state transitions (
running,idle,waiting_input,error,stale,contract_violated) to~/.opencode-mcp-events.jsonl. - 🔀 Multi-Session Orchestration: Run up to 3 concurrent OpenCode sessions with dependency ordering (
opencode_batch). - 🗂️ Context Bucket: Tracks every file creation/modification reported by the session's event stream.
- 🛡️ Task Contracts: Enforce duration limits, path scope restrictions, file count caps, and forbidden commands.
- 📸 Checkpoints & Recovery: Auto-save state snapshots every 60s and retry failed sessions from any checkpoint.
- 🎯 Pre-Flight Classifier: Score incoming tasks to decide whether to delegate and recommend the best model.
- 🩺 Failure visibility:
opencode_healthexposeslast_error— the real underlying exception from OpenCode's runner, not just a generic hang. - 🖥️ Server introspection:
opencode_server_health/opencode_server_restartexpose and control the underlyingopencode serveprocess itself, separate from any individual session. - 📖 Self-documenting:
opencode_guidereturns a complete, live behavioral guide (model selection, workflow, gotchas) generated from the running server's actual state — works identically in any MCP host.
Prerequisites
- Node.js v18+
- OpenCode CLI installed and authenticated (
opencode auth login) — runopencode --versionto confirm it's on PATH.
Quick Start
-
Clone and build:
git clone https://github.com/Dheerax/opencode_mcp.git cd opencode_mcp npm install npm run build -
Register as an MCP server:
- Claude Code:
claude mcp add -s user opencode-mcp-bridge -- node /absolute/path/to/opencode_mcp/dist/index.js - Antigravity / VS Code / Cursor / Windsurf:
Add to your MCP server configuration:
{ "mcpServers": { "opencode-mcp-bridge": { "command": "node", "args": ["/absolute/path/to/opencode_mcp/dist/index.js"] } } }
- Claude Code:
-
Run Setup: Invoke the
opencode_setuptool once from your host agent to generate workspace integration instructions, then callopencode_guideto get the full usage guide.
All tools
See AGENTS.md for the complete tool reference table and workflow guide — or call the opencode_guide MCP tool directly, which returns the same content live.
Troubleshooting
If a session's status stays error immediately and opencode_health's last_error mentions ModelUnavailableError for a provider you expect to work (e.g. a google/* model), the provider's cached OAuth token has likely expired. Re-authenticate it directly:
opencode auth logout <provider>
opencode auth login <provider>
This is an OpenCode/provider-auth issue, not something the bridge can fix by itself — it can only detect it, report it via last_error, and recover the server process so it doesn't stay wedged for other sessions.
License
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.