opencode-mcp-bridge
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-mcp-bridgeStart an agent session to fix the failing unit tests in src/"
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-mcp-bridge
opencode の HTTP サーバー (opencode serve) を MCP (Model Context Protocol) サーバーとして公開するブリッジです。
MCP しか接続できない AI チャット(tool calling API を直接使えないクライアント)から、opencode のコーディングエージェントとシェルをフル機能で操作するために作りました。
設計上の最重要ポイント: すべての MCP ツールは 必ず 55 秒以内にレスポンスを返します。 60 秒でタイムアウトする MCP クライアントでも「呼び出し失敗」にならないよう、長時間処理は必ず 「開始 → ジョブ ID を返す → ポーリング」の非同期パターンに分解しています。
なぜブリッジが必要か
課題 | 素の opencode | 本ブリッジ |
MCP サーバーとして起動できるか | ❌ opencode は MCP クライアント機能しか持たない | ✅ Streamable HTTP / stdio の MCP サーバー |
エージェント実行の待ち時間 |
| ✅ |
シェルの長時間コマンド | 完了までブロック | ✅ ジョブ化して |
危険コマンド | 設定次第 | ✅ ブリッジ側にも deny/allow のガードを二重化 |
API のバージョン差 | v2 experimental な | ✅ 起動時に能力を検出し、 |
モデル不要のコマンド実行 | 旧 API のシェルは AI エージェント経由のため、モデル未設定だと | ✅ |
Related MCP server: mcp_server_for_claudes_toolbox
アーキテクチャ
MCP クライアント (60 秒制限あり)
│ Streamable HTTP: POST /mcp (または stdio)
▼
opencode-mcp-bridge ── HTTP ──▶ opencode serve (127.0.0.1:4096)
│ │
│ ├── /session, /session/{id}/prompt_async
│ ├── /api/pty(本物の端末・モデル不要)
│ ├── /api/shell(v2)または /session/{id}/shell(legacy)
│ ├── /file/content, /find, /find/file
│ └── /permission, /question
└── 55 秒ハードキャップ + ジョブ管理 + コマンドガードモデル向けツールの MCP 移植(tool calling の代替)
opencode がモデルに渡すツールは GET /experimental/tool/ids で確認できる 14 個で、
実際のスキーマは GET /experimental/tool?provider=&model= が返す。
ただし ツールを実行する HTTP エンドポイントは存在しない(一覧系の 2 本だけ)。
そこでブリッジ側でスキーマを 1:1 で写し取り、実行はブリッジ自身が行う。
これにより tool calling に対応していない MCP クライアント(Notion AI など)が モデルの位置に入り、プロバイダの API キーを一切登録せずに 調査 → 編集 → テスト → diff 確認までを回せる。
MCP ツール | opencode 側の実体 | 実行経路 |
|
| opencode の pty API。実端末で exit code まで取得 |
|
| 行番号付き。既定 2000 行 |
|
| 親ディレクトリを作成して上書き |
|
| 完全一致置換。一意でなければエラー |
|
|
|
|
| 正規表現。ファイル名と行番号を返す |
|
| 認証情報不要 |
|
| セッションのタスク一覧 |
| — | opencode の一覧と本ミラーを突き合わせて差分を報告 |
写していないもの(opencode_model_tools が理由付きで返す):
task… サブエージェント起動。モデルが必要。ここでは MCP クライアント自身が実行するskill… モデルの文脈にプロンプトを差し込むだけ。opencode_skillsで中身を読めば足りるquestion… 操作者への質問。ここでは MCP クライアントが操作者なので自分のユーザーに聞くwebsearch… プロバイダの認証情報が必要apply_patch… 一部プロバイダにしか出さない。editとwriteで代替できるinvalid… 不正なツール呼び出し用のプレースホルダ
opencode が更新されて 14 個の構成が変わったら opencode_model_tools を呼ぶと
not_mirrored と mirrored_but_missing_upstream に差分が出る。
writeとeditはブリッジのプロセスが直接ファイルを書くため、 opencode の permission 機構(OPENCODE_PERMISSION)は通らない。bashは pty 経由なのでブリッジの deny / allow パターンで守られる。
ツール一覧(29 個)
モデル向けツール(opencode が本来モデルに渡すもの)
bash / read / write / edit / glob / grep / webfetch / todowrite / opencode_model_tools
(詳細は上の表を参照)
エージェント
ツール | 説明 |
| プロンプトを投げてセッションを開始(即座に |
| 指定秒数だけ完了を待つ。未完なら |
| セッションのメッセージ履歴を取得(ページング対応) |
| 実行中のセッションを中断 |
| セッション一覧 |
シェル
ツール | 説明 |
| コマンドを PTY ジョブとして開始し、 |
|
|
| ジョブの状態・終了コード |
| 実行中/完了済みジョブ一覧 |
| タイムアウト延長(PTY / v2 API のみ。legacy は開始時に固定) |
| ジョブを強制終了 |
シェルの実行経路(重要)
opencode_shell 系は、接続先 opencode の能力に応じて次の順に経路を選びます。ツール名・引数・cursor の意味は経路が変わっても同じです。
優先 | 経路 | 中身 | モデル(API キー) |
1 |
| opencode が本物の擬似端末を起動し、出力を WebSocket で配信。終了コードもそのまま取得 | 不要 |
2 |
| experimental なシェル API | 不要 |
3 |
| AI エージェントにコマンドを実行させる旧経路 | 必要 |
OPENCODE_MCP_SHELL_BACKEND で経路を固定できます(auto / pty / v2 / legacy)。PTY 経路では TERM=dumb を渡し、色や制御文字を除去した素のテキストを返します。
能力検出は起動時に一度走りますが、opencode 本体の起動が遅れていると /api/pty を取り逃すことがあります。その一度きりの失敗で以降ずっとモデル依存の旧 API に落ちないよう、auto / pty では「pty なし」と判定してから 15 秒以上経っていればシェル実行時に再判定します。pty の起動そのものを拒否したビルドでは、この再判定は行いません。
ファイル・検索
ツール | 説明 |
| ファイル読み取り(オフセット/行数指定可) |
| 内容検索 |
| ファイル名検索 |
| 作業ツリーの差分 |
承認(permission / question)
ツール | 説明 |
| 承認待ちの一覧 |
|
|
| エージェントからの質問一覧 |
| 質問への回答 |
診断
ツール | 説明 |
| 接続確認と API 能力検出( |
すべてのツールは JSON テキストを返し、ok と next_action(次に呼ぶべきツールのヒント)を含みます。
これにより、tool calling に不慣れなチャット AI でも「次に何をすればよいか」を迷いません。
セットアップ
git clone https://github.com/nmt3325/opencode-mcp-bridge.git
cd opencode-mcp-bridge
npm install
npm run build
# 1) opencode をサーバーモードで起動
opencode serve --port 4096 --hostname 127.0.0.1
# 2) ブリッジを起動(HTTP モード)
OPENCODE_BASE_URL=http://127.0.0.1:4096 \
OPENCODE_MCP_TOKEN=$(openssl rand -hex 24) \
node dist/index.js --http --port 8787stdio で使う場合は node dist/index.js --stdio。
MCP クライアント設定例
Streamable HTTP:
{
"mcpServers": {
"opencode": {
"type": "http",
"url": "http://127.0.0.1:8787/mcp",
"headers": { "Authorization": "Bearer <OPENCODE_MCP_TOKEN>" }
}
}
}stdio:
{
"mcpServers": {
"opencode": {
"command": "node",
"args": ["/path/to/opencode-mcp-bridge/dist/index.js", "--stdio"],
"env": { "OPENCODE_BASE_URL": "http://127.0.0.1:4096" }
}
}
}環境変数
変数 | 既定値 | 説明 |
|
| opencode サーバーの URL |
| – | opencode 側 Basic 認証 |
| – | Bearer で送る場合 |
|
| ブリッジの待受 |
| – | 設定すると |
|
| 1 回のツール呼び出しで待つ最大秒数(上限 50) |
|
| シェル経路の固定( |
|
| PTY 経路でコマンドを渡すシェル |
|
| PTY 1 本あたりに保持する出力量(文字) |
|
| ポーリング間隔 |
|
| opencode への 1 リクエストのタイムアウト |
|
| 1 レスポンスの最大文字数(超過分は切り詰め、続きは cursor で取得) |
|
| シェルジョブの既定タイムアウト |
| 下記 | 追加の拒否パターン( |
| – | 設定するとホワイトリスト運用になる |
| – | 既定の作業ディレクトリ / エージェント / モデル |
既定の拒否パターン: rm -rf /, rm -rf /*, rm -rf ~, mkfs*, dd if=* of=/dev/*, shutdown*, reboot*, halt*, chmod -R 777 /*, フォークボム など。
セキュリティ
必ず
127.0.0.1にバインドしてください。opencode のサーバーモードは認証が無く、シェル実行 API を含みます(過去に/find経由のコマンドインジェクション事例あり)。外部公開する場合は Tailscale / SSH トンネル +OPENCODE_MCP_TOKENを併用してください。ブリッジのガードは二重防御の 1 枚目です。opencode 側の
permission設定(examples/opencode.json)も必ず設定してください。可能なら専用コンテナ / VM 内で動かし、ホストの鍵や本番環境の認証情報を置かないこと。
テスト
npm test # test/e2e.shtest/mock-opencode.mjs(依存ゼロのモック opencode)を起動し、curl だけで MCP over HTTP を叩いて 49 項目を検証します。
v2 API 構成: initialize / tools/list / 各ツール / permission 承認フロー / セッション無し時 400 応答
--legacy構成:/api/shellとprompt_asyncを 404 にして、旧 API への自動フォールバックを検証--html-spa/--spa-post構成:/api/shellが Web UI の HTML を 200 で返すビルドでも誤検出しないことを検証(下記の実機バグの回帰テスト)
===================================
passed: 49 failed: 0
===================================実物の opencode に対する疎通確認は bash test/smoke-real.sh(opencode serve が起動している必要あり)。
実機検証で見つかったバグと修正
モックだけでなく実際の opencode serve に繋いだところ、次の不具合を検出して修正しました。
現象: 一部のビルドは未定義のパスに対して Web UI の HTML を HTTP 200 で返す。そのため
GET /api/shellが 200 になり、ブリッジが「v2 シェル API あり」と誤検知 → シェル実行がshell id missing in responseで失敗した。修正: 能力検出をステータスコードだけでなく ボディが本当に JSON か(
isJsonPayload)で判定するように変更。さらにPOST /api/shellが JSON でない応答を返した場合も実行時に legacy ルートへ自動ダウングレードするようにした。回帰テスト: モックに
--html-spa/--spa-postモードを追加し、両ケースを e2e に組み込み。
修正後の実機実行結果(bash test/smoke-real.sh):
{ "ok": true, "capabilities": { "reachable": true, "shellApi": "legacy", "promptAsync": true, "sessionStatusEndpoint": true, "vcsBase": "/api/vcs" } }
{ "ok": true, "shell_id": "local-90c75649", "api": "legacy", "status": "completed", "exit_code": 0, "output": "real-opencode-ok\nLinux\n" }ライセンス
MIT
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
- Alicense-qualityDmaintenanceIntegrates the OpenCode AI coding agent into MCP-compatible clients, allowing users to execute terminal-based coding tasks and manage sessions programmatically. It provides tools for running commands, listing AI models, and continuing existing coding sessions via the OpenCode CLI.15MIT
- Flicense-qualityDmaintenanceExposes a set of CLI tools (test generation, documentation generation, linting, test running, code search) to AI assistants via MCP, allowing them to perform these tasks through natural language.3
- Alicense-qualityCmaintenanceEnables MCP clients to spawn and control Codex CLI and Claude Code sessions on the host machine, with session management and filesystem access.4MIT
- AlicenseAqualityDmaintenanceMCP server providing 13 tools to control opencode, Gemini CLI, and Qwen Code AI coding agents with session continuity and auth checking.13MIT
Related MCP Connectors
OCR, transcription, file extraction, and image generation for AI agents via MCP.
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
MCP server exposing the Backtest360 engine API as tools for AI agents.
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/nmt3325/opencode-mcp-bridge'
If you have feedback or need assistance with the MCP directory API, please join our Discord server