OpenCode MCP Server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
OpenCode MCP Server
A production-ready Model Context Protocol (MCP) server that integrates AI-powered IDEs with OpenCode agents. Supports multi-agent delegation, dynamic model selection, rate-limit mitigation, and resilient connection management.
Built with Bun, @modelcontextprotocol/sdk, and the official @opencode-ai/sdk v2. Validated at 100% line coverage.
Key Capabilities
Automatic Server Provisioning — Detects and spawns
opencode servevia the official SDK when no running instance is found. No manual setup required.Resilient Connection Management — Automatic retries with exponential backoff for
ECONNREFUSED,ENOTFOUND,ETIMEDOUT, HTTP429, and5xxresponses.Optimized Health Monitoring — Server availability is validated with a configurable TTL-based cache (default: 30 seconds), minimizing redundant network overhead.
Graceful Lifecycle Management —
SIGINTandSIGTERMsignals trigger orderly termination of any managed OpenCode processes.Diagnostic Error Reporting — Connection failures include specific remediation instructions and contextual details.
Input Validation — All tool arguments are validated before dispatching to the OpenCode API, preventing malformed requests.
Related MCP server: opencode-mcp
Features
Feature | Description |
Asynchronous Task Delegation | Submits tasks to OpenCode's |
Synchronous Execution | Executes tasks with internal status polling, returning the final result upon completion. |
Multi-Agent Delegation | Route tasks to any OpenCode-native agent (e.g., |
Dynamic Model Selection | Switch the active LLM model at runtime via |
Rate-Limit Mitigation | Integrates |
Remote Shell Execution | Executes shell commands within OpenCode session workspaces via |
Native Command Access | Directly execute OpenCode native commands like |
Skill Management | Discover and install community skills from the OpenCode registry via |
Resilient Core | Native support for model rotation, automatic retries, and high-accuracy task verification loops. |
Comprehensive Test Coverage | Ships with unit tests and end-to-end tests at 100% line coverage. |
Prerequisites
Installation
bun installCompiled Binary
For optimized startup performance in production environments:
bun run build
./opencode-mcpQuick Start
The server automatically provisions an OpenCode instance on first use:
bun run startTo connect to an externally managed OpenCode instance:
# Terminal 1: Start OpenCode separately
opencode serve --port 4096
# Terminal 2: Start the MCP server with auto-start disabled
OPENCODE_AUTO_START=false bun run startConfiguration
The server communicates with clients via JSON-RPC over stdio and with the OpenCode API via HTTP. All configuration is managed through environment variables.
Variable | Default | Description |
|
| Base URL of the OpenCode REST API server. |
|
| HTTP Basic Authentication username (applied when a password is configured). |
| (empty) | HTTP Basic Authentication password. Leave empty to disable authentication. |
|
| Maximum number of retry attempts for failed requests (applies to |
|
| When |
|
| Port number for the automatically provisioned OpenCode server. |
Automatic Server Provisioning
When OPENCODE_AUTO_START=true (default):
At startup — Performs a non-blocking health check. If the server is unreachable, logs a diagnostic message and continues initialization.
On first tool invocation — If the server remains unreachable, spawns
opencode servevia@opencode-ai/sdkand waits for it to report healthy status.On shutdown — Terminates any managed OpenCode process via registered signal handlers.
Set OPENCODE_AUTO_START=false when OpenCode is managed externally (e.g., via systemd, Docker, or Kubernetes).
Available Tools
This server exposes 32 tools to connected MCP clients:
Tool | Parameters | Description |
|
| Submit a task and block until the agent completes execution. |
|
| Submit a task for background execution. Returns a session ID immediately. |
|
| Retrieve session details, status, and recent messages. |
|
| Execute a shell command within an OpenCode session workspace. |
| (none) | List all available agent profiles. |
| (none) | List all configured LLM providers and models. |
| (none) | Retrieve the current global configuration. |
|
| Update global configuration parameters (e.g., switch the active model). |
| (none) | Query the server health endpoint (bypassing cache). |
|
| Abort a running or unresponsive session. |
|
| Permanently delete a session. |
Multi-Agent & OMO | ||
|
| High-accuracy Plan -> Execute -> Verify loop using Hephaestus and Momus. |
|
| Run the Implementation persona with specific mode ( |
| (none) | Reload dynamic agent personas from local config. |
Native Commands | ||
| (none) | List available native OpenCode commands (built-in + plugins). |
|
| Execute a native command with arguments in a session. |
|
| Manage OpenCode skills (find, add, rm, update, ls). |
Advanced Tools | ||
| (none) | List all MCP servers configured within OpenCode. |
|
| Dynamically add a new MCP server to OpenCode. |
|
| Remove a configured MCP server by name. |
|
| Create a persistent PTY (pseudo-terminal) session. |
| (none) | List all active PTY sessions. |
|
| Get a file-system diff for a session state. |
|
| Create a new session forked from a specific point in history. |
|
| Revert a session's workspace to a specific message ID. |
Usage Examples
Delegating a Task to a Specific Agent
{
"name": "opencode_ask_async",
"arguments": {
"task": "Refactor the authentication module to use JWT tokens",
"agent": "hephaestus"
}
}Synchronous Task Execution
{
"name": "opencode_ask_sync",
"arguments": {
"task": "Analyze the architecture of the src/auth module and provide recommendations",
"agent": "oracle"
}
}Remote Shell Execution
{
"name": "opencode_run_shell",
"arguments": {
"command": "bun test --coverage",
"agent": "hephaestus"
}
}Dynamic Model Configuration
{
"name": "opencode_set_config",
"arguments": {
"config": {
"model": "claude-sonnet-4-20250514",
"agent": "hephaestus"
}
}
}Session Status Monitoring
{
"name": "opencode_get_session",
"arguments": {
"sessionId": "abc-123-xyz",
"limit": 20
}
}
### Forking a Session (Revision Control)
```json
{
"name": "opencode_session_fork",
"arguments": {
"sessionId": "original-session-id",
"messageId": "msg-456"
}
}Managing PTY Terminals
{
"name": "opencode_pty_create",
"arguments": {
"cols": 120,
"rows": 40,
"cwd": "/home/user/project"
}
}Dynamic MCP Chaining
{
"name": "opencode_mcp_add",
"arguments": {
"name": "mysql-mcp",
"config": {
"command": "npx",
"args": ["@modelcontextprotocol/server-mysql", "mysql://..."]
}
}
}IDE Integration
You can configure this server locally or run it directly from GitHub without installation.
Zero-Install (Direct from GitHub)
For the best experience, use bunx to run the server directly from the source:
{
"mcpServers": {
"opencode": {
"command": "bunx",
"args": ["--bun", "github:jinto-ag/opencode-mcp"]
}
}
}Alternatively, with npx:
{
"mcpServers": {
"opencode": {
"command": "npx",
"args": ["-y", "github:jinto-ag/opencode-mcp"]
}
}
}Local Configuration
Provide the absolute path to src/index.ts or the compiled binary.
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"opencode": {
"command": "bun",
"args": ["run", "/absolute/path/to/opencode-mcp/src/index.ts"],
"env": {
"OPENCODE_SERVER_URL": "http://127.0.0.1:4096"
}
}
}
}Gemini Code Assist / Antigravity
Add to your workspace or global MCP configuration:
{
"mcpServers": {
"opencode": {
"command": "bun",
"args": ["run", "/absolute/path/to/opencode-mcp/src/index.ts"]
}
}
}Cursor
Navigate to Settings → Features → MCP Servers.
Add a new server:
Type:
stdioName:
opencodeCommand:
bun run /absolute/path/to/opencode-mcp/src/index.ts
Windsurf
Add to mcp_config.json:
{
"mcpServers": {
"opencode": {
"command": "bun",
"args": ["run", "/absolute/path/to/opencode-mcp/src/index.ts"]
}
}
}Using the Compiled Binary
For any IDE, the pre-compiled binary may be used in place of bun run:
{
"mcpServers": {
"opencode": {
"command": "/absolute/path/to/opencode-mcp/opencode-mcp"
}
}
}Architecture
┌─────────────┐ stdio ┌──────────────────────┐ HTTP ┌─────────────────┐
│ AI IDE │ ◄──────────► │ OpenCode MCP │ ◄─────────► │ OpenCode API │
│ (Claude, │ JSON-RPC │ Server │ REST API │ (opencode │
│ Cursor, │ │ │ /session │ serve) │
│ etc.) │ │ • Auto-provisioning │ /agent │ │
└─────────────┘ │ • Health cache │ /config └─────────────────┘
│ • Retry with backoff │ /provider ▲
│ • Lifecycle mgmt │ │
└──────────────────────┘ Auto-provisioned
when unavailableTesting
# Run unit tests with coverage reporting
bun test --coverage
# Run static type analysis
bun run typecheck
# Run end-to-end tests (requires Podman or a running OpenCode instance)
OPENCODE_SERVER_URL=http://127.0.0.1:4096 bun testTroubleshooting
ECONNREFUSED on Port 4096
Cause: The OpenCode HTTP API server is not running on the expected port.
Resolution: Enable automatic server provisioning (default behavior) or start OpenCode manually:
opencode serve --port 4096Automatic Provisioning Failure
Cause: The opencode CLI is not installed or not available in the system PATH.
Resolution: Verify the OpenCode installation:
which opencode # Should return a valid path
opencode --version # Should return version 1.2 or laterHealth Check Timeout
Cause: The OpenCode server is experiencing high load or network connectivity issues.
Resolution: Increase the retry limit:
OPENCODE_MAX_RETRIES=5 bun run startLicense
MIT © Jinto AG
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
The OpenRouter MCP server plugs OpenRouter into the AI tools you already use. Once connected, your assistant can pull live OpenRouter data (models, prices, your credits, rankings, and docs) and send quick test messages, all without leaving your editor.
Your org's AI agents, tasks, runs, search, and brain files as MCP tools and resources.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Build and run AI workflows, agents, data tables and 1000+ API integrations from any MCP client.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceConnects MCP clients such as Claude, Cursor, and VS Code to OpenCode's headless API, enabling users to delegate coding work, ask questions, implement features, monitor background jobs, and review changes across projects. It also supports resolving permission and input requests during agentic coding workflows.22,181 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables MCP clients such as Claude, Cursor, and VS Code to delegate coding tasks to an OpenCode server, including asking questions, running background jobs, monitoring progress, responding to input/permissions, and reviewing changes across projects.22,181 npmMIT
- AlicenseNot gradedqualityAmaintenanceConnects MCP clients such as Claude, Cursor, and VS Code to OpenCode's headless API, enabling users to ask questions, implement features, run and monitor background coding jobs, handle prompts and permissions, and review changes across projects.22,181 npmMIT
- AlicenseNot gradedqualityAmaintenanceConnects MCP clients such as Claude, Cursor, and VS Code to OpenCode's headless API so users can delegate coding tasks, ask questions, run work in the background, and resolve permission or input requests across projects. It also supports monitoring job progress, reviewing resulting changes, and inspecting conversation history.22,181 npmMIT