opencode-agent-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@opencode-agent-mcpIn the 'api' workspace, spawn an agent to fix the auth bug."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
opencode-agent-mcp
MCP server that exposes independent OpenCode AI coding agents to upstream Agents (Claude Desktop, Cursor, opencode TUI, custom) over stdio JSON-RPC, with multi-workspace concurrent routing.
Full product specification:
opencode-agent-mcp.md
Overview
In polyglot or monorepo-style codebases, a single fault often spans multiple projects (e.g. a frontend interaction that depends on a backend API and a native mobile shell). The conventional "spawn a subagent to look at the other repo" pattern fails because the subagent inherits the parent agent's workspace, MCP servers, and skills — it does not load the target project's own conventions.
opencode-agent-mcp addresses this by exposing OpenCode as a multi-workspace MCP server:
Upstream agents register any number of workspaces via
set_workspace({name, cwd}).Each workspace maps to a dedicated
OpencodeClientinstance, scoped by thex-opencode-directoryheader so the OpenCode host routes requests to the correct project.Sessions are created, messaged, cancelled, and queried per workspace, with full isolation between workspaces and concurrency within a workspace.
When the inner agent requires approval or clarification, those events are surfaced back to the upstream agent via blocking MCP tools (
wait_for_question/answer_question) for it to decide.
This server is an interim MCP implementation of a more general multi-workspace A2A pattern. The current schema is designed to be migratable: once A2A stabilises, the same conceptual primitives map onto A2A's task / message / artifact triples, and the MCP server can be replaced by an A2A server without breaking the upstream contract.
Dimension | Current MCP implementation | Target A2A model |
Topology | Parent → child (client → server) | Peer-to-peer |
Question flow | Blocking MCP tool emulation | Native request/response |
Protocol surface | JSON-RPC + SSE + blocking tool | Unified A2A message/artifact/task |
Lifecycle | Co-hosted with upstream agent | Independent per agent |
Related MCP server: agent-comm
Quick Start
The package is published on npm and resolvable via npx. No global install is required.
# Verify the package is reachable
npm view opencode-agent-mcp version
# Launch the MCP server directly (foreground; used by Claude Desktop / opencode TUI)
npx -y opencode-agent-mcpTo make the server reachable from Claude Desktop, Cursor, or the opencode TUI, point the MCP client at npx -y opencode-agent-mcp with the appropriate environment variables. See Integration for concrete mcpServers / mcp config snippets.
Pre-flight
npx -y opencode-agent-mcp does not start an OpenCode host on its own — it expects an existing opencode serve (external host mode) or spawns one itself (managed mode). Confirm the desired mode by inspecting the environment variables in Configuration before launching the client.
Installation
Two installation paths are supported; npx is preferred unless the source needs to be modified locally.
Option A — npx (recommended for end users)
# Implicit install via npx on first invocation
npx -y opencode-agent-mcpThe package is fetched to the npx cache on first use and re-used on subsequent invocations. To pin a specific version:
npx -y opencode-agent-mcp@0.1.0Option B — From source (for development or local modification)
git clone <repository-url>
cd opencode-agent-mcp
pnpm install
pnpm run build
node build/index.jsRequirements: Node.js ≥ 18.18.0, pnpm ≥ 8 (or npm ≥ 9 with npm install && npm run build).
Configuration
The server reads the following environment variables. All paths must be absolute on the host.
Variable | Default | Description |
| (unset) | When set, the server runs in external host mode and connects to the given |
|
| Path to the |
|
| Port for the managed host (managed mode only). |
|
| Bind address for the managed host (managed mode only). |
| process CWD | Initial workspace registered as |
|
| One of |
| (stderr) | Optional file path for log output; default is stderr. |
Running
The MCP server speaks stdio JSON-RPC. It is normally launched by an MCP client (Claude Desktop, opencode TUI, etc.) rather than by hand. The sections below assume the client has been configured with one of the snippets in Integration.
For manual smoke-testing:
# External host mode — OpenCode host must be running on :4096
OPENCODE_URL=http://127.0.0.1:4096 \
OPENCODE_DEFAULT_CWD="C:/path/to/aggregated-project" \
npx -y opencode-agent-mcp
# Managed mode — server spawns `opencode serve` itself
OPENCODE_DEFAULT_CWD="C:/path/to/project" \
npx -y opencode-agent-mcpIn managed mode the server spawns opencode serve on startup and terminates it on shutdown. The host process is not reused across MCP restarts.
Integration
The configuration below assumes the package is installed via npx (no global install required). For source installs, replace npx with node and point args at build/index.js.
Claude Desktop
Edit claude_desktop_config.json (Windows: %APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"opencode-agent": {
"command": "npx",
"args": ["-y", "opencode-agent-mcp"],
"env": {
"OPENCODE_URL": "http://127.0.0.1:4096",
"OPENCODE_DEFAULT_CWD": "C:/path/to/aggregated-project"
}
}
}
}opencode TUI
Edit ~/.config/opencode/opencode.json:
{
"mcp": {
"opencode-agent": {
"type": "local",
"command": ["npx", "-y", "opencode-agent-mcp"],
"environment": {
"OPENCODE_URL": "http://127.0.0.1:4096"
}
}
}
}Custom agent (Node.js SDK)
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const client = new Client(
{ name: "my-agent", version: "0.1.0" },
{ capabilities: {} },
);
await client.connect(new StdioClientTransport({
command: "npx",
args: ["-y", "opencode-agent-mcp"],
env: { OPENCODE_URL: "http://127.0.0.1:4096" },
}));
const { tools } = await client.listTools();Multi-workspace Routing
Lifecycle
1. set_workspace({name: "backend", cwd: "C:/repo/backend"})
2. set_workspace({name: "h5", cwd: "C:/repo/h5"})
3. set_workspace({name: "app", cwd: "C:/repo/app", default: false})
4. create_session({workspace: "backend", title: "API regression"})
5. create_session({workspace: "h5", title: "Button handler"})
6. create_session({workspace: "app", title: "Native bridge"})
7. send_message({session_id: <h5_session>, text: "..."})
→ the server resolves the session back to its workspace ("h5")
and dispatches the request via the h5-scoped OpencodeClientSemantics
The
workspaceparameter accepts a workspace name registered viaset_workspace, not a rawcwd. When omitted, the default workspace is used.A
(name, cwd)pair already registered is reused (idempotent). Registering the samenamewith a differentcwdraisesWORKSPACE_NOT_REGISTERED.One
OpencodeClientis instantiated per registered workspace, distinguished by thex-opencode-directoryHTTP header.SessionStorerecordssession_id → workspace_name. Subsequent operations on the session (send_message,cancel_session,answer_question) are routed by that mapping without requiring the caller to re-supplyworkspace.
Topology
Upstream Agent
│
│ create_session({workspace: "h5"})
▼
MCP server (stdio)
│
│ workspaces.get("h5") → OpencodeClient (x-opencode-directory = /repo/h5)
▼
OpenCode host (127.0.0.1:4096)
│
├─ /session?directory=/C:/repo/backend
├─ /session?directory=/C:/repo/h5
└─ /session?directory=/C:/repo/appMCP Tools
Tool | Description |
| List all registered workspaces and the current default. |
| Register a new workspace ( |
| List OpenCode sessions under a workspace. |
| Create a new session in the specified workspace and start its SSE subscription. |
| Send a message synchronously; returns the assistant text, token usage, and completion status. |
| Block until the session reaches |
| Abort the session and stop its SSE subscription. |
| Block until the OpenCode host emits a |
| Forward the upstream agent's decision ( |
Tool schemas are generated from the source code and reported by the server at runtime via the MCP tools/list endpoint.
Testing
Two integration scripts are provided; both assume an OpenCode host reachable at 127.0.0.1:4096.
opencode serve --hostname=127.0.0.1 --port=4096 &
node e2e-test.mjs # single-workspace end-to-end
node multi-workspace-test.mjs # concurrent multi-workspace routingBoth scripts use the official @modelcontextprotocol/sdk client and assert on returned content. The test sessions are created against scratch directories under the platform temp path; no real project state is touched.
Troubleshooting
Symptom | Cause | Resolution |
|
| Start |
| Workspace directory missing on disk | Create the directory or correct the |
| Unknown workspace name supplied | Register the workspace via |
|
| Create the session and send within the same MCP lifetime. |
| OpenCode host version is too old | Upgrade OpenCode to ≥ 1.18.x. |
Garbled protocol output on stdout | logger writing to stdout | Ensure |
License
Contributing
Issues and pull requests are welcome. Please open an issue before submitting non-trivial changes so the design intent can be discussed.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Flicense-qualityAmaintenanceMCP server that bridges coding agents (Claude Code, Codex, Gemini CLI) via ACP for pair programming, enabling agents to consult each other as tools.
- Alicense-qualityDmaintenanceMCP server that enables AI coding agents to communicate, share state, and coordinate work in real time via MCP tools or REST API.895MIT
- Alicense-qualityDmaintenanceA Model Context Protocol (MCP) server that enables remote access to OpenCode AI coding agent, allowing MCP-compatible clients to leverage OpenCode's capabilities.MIT
- AlicenseAqualityFmaintenanceMCP server for running external coding agents as background tasks inside Claude Code. Supports multiple backends including Codex, Grok, GLM, DeepSeek, and more.7MIT
Related MCP Connectors
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Real-time chat hub for AI agents — Claude Code, Cursor, Cline, Codex over MCP or REST.
ArcAgent MCP server for bounty discovery, workspace execution, and verified coding submissions.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/define9/opencode-agent-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server