Actively maintained fork of opencode-mcp-tool with async task execution, concurrency fixes, and comprehensive testing.
A Model Context Protocol (MCP) server that allows AI assistants to interact with the OpenCode CLI. It enables AI assistants to leverage multiple AI models through a unified interface with async task execution for parallel processing and long-running operations.
- Install wizard - Interactive setup with auto-detection from OpenCode's configured model
- Async task architecture - Non-blocking execution with immediate task IDs for background processing
- Fixed concurrent execution - Original had race conditions when multiple tool calls ran simultaneously
- Process pooling - Limits concurrent child processes to prevent resource exhaustion
- Comprehensive test suite - 238 tests covering core functionality, async operations, and concurrency
Goal: Use OpenCode's multi-model capabilities directly in Claude Code with flexible model selection and async task execution.
Before using this tool, ensure you have:
- Node.js (v16.0.0 or higher)
- OpenCode CLI installed and configured
Option 1: Interactive Setup Wizard
# Clone and run setup
git clone https://github.com/ajhcs/Better-OpenCodeMCP.git
cd Better-OpenCodeMCP
npm install && npm run build
node dist/index.js --setupThe wizard will:
- Fetch available models from your OpenCode installation
- Let you pick primary and fallback models
- Configure default agent mode
- Save settings to
~/.config/opencode-mcp/config.json
Option 2: Auto-Detection
If you've used OpenCode before, the server automatically detects your most recently used model. Just run without flags:
node dist/index.jsOption 3: Explicit Model
node dist/index.js --model google/gemini-2.5-pro# After running --setup or with auto-detection
claude mcp add opencode -- node /path/to/Better-OpenCodeMCP/dist/index.js
# Or with explicit model
claude mcp add opencode -- node /path/to/Better-OpenCodeMCP/dist/index.js -- --model google/gemini-2.5-proType /mcp inside Claude Code to verify the opencode MCP is active.
The server resolves the model in this order:
- CLI flag -
--modelif explicitly provided - Config file -
~/.config/opencode-mcp/config.json(created by--setup) - Auto-detect - Your most recently used model in OpenCode
- Interactive - Launches wizard if running in a terminal
- Error - Shows helpful setup instructions
Created by --setup wizard at ~/.config/opencode-mcp/config.json:
{
"model": "google/gemini-2.5-pro",
"fallbackModel": "deepseek/deepseek-chat",
"defaults": {
"agent": "build"
}
}For Claude Desktop, add to your config:
{
"mcpServers": {
"opencode": {
"command": "node",
"args": ["/path/to/Better-OpenCodeMCP/dist/index.js"]
}
}
}Or with explicit model:
{
"mcpServers": {
"opencode": {
"command": "node",
"args": ["/path/to/Better-OpenCodeMCP/dist/index.js", "--model", "google/gemini-2.5-pro"]
}
}
}Configuration File Locations:
- Claude Desktop:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
- macOS:
After updating the configuration, restart your terminal session.
This MCP server uses an async task architecture for non-blocking execution:
1. Start task → opencode → Returns taskId immediately
2. Monitor → opencode_sessions → Check task status
3. If input needed → opencode_respond → Send response to task
4. Task completes → Status: completed/failed
working → input_required → working → completed
↓ ↓
(respond) (or failed)
- working: Task is actively executing
- input_required: Task paused, waiting for input via
opencode_respond - completed: Task finished successfully
- failed: Task encountered an error
Delegate a task to OpenCode for autonomous execution. Returns immediately with a taskId while the task runs in background.
| Parameter | Type | Required | Description |
|---|---|---|---|
task |
string | Yes | The task/prompt to send to OpenCode |
agent |
string | No | Agent mode: explore, plan, or build |
model |
string | No | Override default model (e.g., google/gemini-2.5-pro) |
outputGuidance |
string | No | Instructions for output formatting |
sessionTitle |
string | No | Human-readable name for tracking |
Returns: { taskId, sessionId, status: "working" }
Agent Modes:
explore- Investigation and researchplan- Structured analysis and planningbuild- Immediate execution and implementation
List and monitor OpenCode tasks. Essential for tracking async task progress.
| Parameter | Type | Required | Description |
|---|---|---|---|
status |
string | No | active (running only) or all (includes completed). Default: active |
limit |
number | No | Maximum sessions to return. Default: 10 |
Returns: { sessions: [...], total: number }
Each session contains: taskId, sessionId, title, status, model, agent, createdAt, lastEventAt
Send a response to an OpenCode task waiting for input. Resumes task execution.
| Parameter | Type | Required | Description |
|---|---|---|---|
taskId |
string | Yes | The task ID to respond to |
response |
string | Yes | The response text to send |
Returns: { taskId, status: "working", message: "..." }
Prerequisites:
- Task must be in
input_requiredstate - Task must have a valid sessionId
ping: Echo test - returns the provided messageHelp: Shows OpenCode CLI help information
"use opencode to analyze @src/main.js"
→ Returns taskId immediately
→ Monitor with opencode_sessions
"check my opencode tasks"
→ Lists all active tasks with status
When a task shows input_required:
"respond to task abc123 with 'yes, proceed with the refactoring'"
- Start: "use opencode to refactor @utils.ts for better error handling"
- Check: "what's the status of my opencode tasks?"
- Respond: (if input needed) "respond with 'use try-catch blocks'"
- Complete: Task finishes with results
use opencode to analyze @src/main.js and explain what it doesuse opencode to summarize @. the current directoryanalyze @package.json using opencode
ask opencode to search for the latest tech newsuse opencode to explain div centeringask opencode about best practices for React development
- Explore:
use opencode in explore mode to investigate the authentication system - Plan:
use opencode in plan mode to design a caching strategy - Build:
use opencode in build mode to implement the login feature
Contributions are welcome! Please open an issue or submit a pull request at github.com/ajhcs/Better-OpenCodeMCP.
This project is licensed under the MIT License. See the LICENSE file for details.
Based on opencode-mcp-tool by frap129.
Disclaimer: This is an unofficial, third-party tool and is not affiliated with, endorsed, or sponsored by Google or Anthropic.