Skip to main content
Glama
OpenCode Remote Bridge

OpenCode Remote Bridge

by sandro9800

🌉 OpenCode Remote Bridge

Control your local OpenCode from anywhere, through any MCP client.

An authenticated Model Context Protocol server that exposes OpenCode sessions, files, terminal and Git over Streamable HTTP, published on a persistent zrok public name.

CI License: MIT Node MCP

WARNING

This bridge gives whoever holds the bearer tokenread/write/delete access to files and command execution on the host machine. It is not a hardened sandbox. Only connect clients you trust, keep the token secret, and review your OpenCode permissions.


Table of contents

Related MCP server: opencode-mcp

Features

  • 🔐 Bearer-token auth with timing-safe comparison

  • 🌐 MCP Streamable HTTP transport, works with Cursor, VS Code, Claude Code and more

  • 💬 OpenCode sessions: create, prompt (sync or async), inspect, abort, delete

  • 📁 Filesystem tools: read, write, list, search, delete

  • 💻 Terminal: run commands through an OpenCode session and its permissions

  • 🌿 Git: status and diff

  • 🤖 Autonomous Goal Runner: orchestrator, worker and reviewer loop until the goal is verified

  • 🚀 One-command manager for OpenCode, the bridge and a persistent zrok share

  • 🧩 Preserves your other MCP servers (e.g. Composio) when updating the OpenCode config

How it works

flowchart LR
    A[MCP client<br/>Cursor / VS Code / Claude Code] -- HTTPS + Bearer token --> B[zrok public name]
    B --> C[Bridge :8787<br/>/mcp]
    C --> D[OpenCode API :4096]
    D --> E[(Your project<br/>files, shell, Git)]

Both OpenCode and the bridge bind to 127.0.0.1. Only zrok exposes the bridge publicly.

Requirements

Requirement

Notes

Debian / Ubuntu

Debian in Termux/PRoot is supported

Node.js 20+ and npm

Node 22 recommended

OpenCode CLI

available as opencode

zrok v2 CLI

available as zrok2, with an enabled account

Python 3, OpenSSL, curl, Git

used by the installer and manager

Free local ports

4096 (OpenCode) and 8787 (bridge)

Run as root, or prefix with sudo.

# Basics
apt-get update
apt-get install -y ca-certificates curl git openssl python3

# Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs

# OpenCode CLI
curl -fsSL https://opencode.ai/v2/install | bash
export PATH="$HOME/.opencode/bin:$PATH"   # add to ~/.bashrc if needed

# zrok v2
curl -sSf https://get.openziti.io/install.bash | bash -s zrok2

References: OpenCode docs · zrok reserved names

Quick start

1. Set up zrok (one time)

zrok2 enable YOUR_ZROK_ENABLE_TOKEN
zrok2 create name -n public YOUR_UNIQUE_NAME
zrok2 list names

Your endpoint will be https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp. Every installation needs its own reserved name. Never publish your enable token.

2. Install the bridge

git clone https://github.com/sandro9800/opencode-remote-bridge-clean.git
cd opencode-remote-bridge-clean
chmod +x mcp scripts/install.sh
./scripts/install.sh

The installer installs dependencies and creates a private .bridge-token (git-ignored, restricted permissions).

3. Set your zrok name

Open the mcp script and set, near the top:

ZROK_RESERVED_NAME="public:YOUR_UNIQUE_NAME"

4. Start

./mcp start     # OpenCode API + bridge + zrok share
./mcp client    # open OpenCode with the bridge configured

Keep ./mcp start running while an external assistant is connected. Read your token locally with cat .bridge-token.

Connect an AI client

Any client that supports remote HTTP MCP with custom headers works.

  • URL: https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp

  • Header: Authorization: Bearer YOUR_BRIDGE_TOKEN

{
  "mcpServers": {
    "opencode-remote-bridge": {
      "url": "https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp",
      "headers": { "Authorization": "Bearer YOUR_BRIDGE_TOKEN" }
    }
  }
}
{
  "inputs": [
    {
      "type": "promptString",
      "id": "bridge-token",
      "description": "OpenCode Remote Bridge token",
      "password": true
    }
  ],
  "servers": {
    "opencode-remote-bridge": {
      "type": "http",
      "url": "https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp",
      "headers": { "Authorization": "Bearer ${input:bridge-token}" }
    }
  }
}
claude mcp add --transport http opencode-remote-bridge \
  https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp \
  --header "Authorization: Bearer YOUR_BRIDGE_TOKEN"

Command-line arguments can end up in shell history. Prefer a safer credential method where available.

{
  "mcpServers": {
    "opencode-remote-bridge": {
      "command": "npx",
      "args": [
        "-y", "mcp-remote",
        "https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp",
        "--header", "Authorization: Bearer YOUR_BRIDGE_TOKEN"
      ]
    }
  }
}
NOTE

MCP connects an assistant to OpenCode's tools. It doesnot copy skills or agents between products. OpenCode skills, agents and AGENTS.md must live in the environment running this bridge.

Autonomous Goal Runner

Submit one high-level goal and three OpenCode sessions work on it:

Role

Job

Orchestrator

Breaks the goal into tasks and decides what remains

Worker

Performs each task with your configured tools, skills and agents

Reviewer

Independently inspects the project and checks the original goal is really done

The loop runs in the background until the reviewer verifies completion, you cancel it, an error occurs, or the iteration limit is hit (default 20, configurable 1 to 100). State is saved in .goal-runner/goals.json with restrictive permissions.

Goal tools: list_goal_models · start_goal · get_goal_status · list_goals · control_goal (pause / resume / cancel)

Example prompt for your MCP client:

Start a goal: make this project production-ready. Use auto model selection,
work in the current project, and run tests. Keep working until an independent
review verifies every acceptance criterion.

Models: set any role to auto, or use an exact providerID/modelID from list_goal_models. The runner uses OpenCode's live provider catalog (cloud, local and custom providers, including NVIDIA NIM once configured in OpenCode). See OpenCode providers and the NVIDIA API Catalog.

Limits:

  • The worker inherits your OpenCode instance's permissions.

  • The reviewer is a separate session, not a formal proof. Check important changes yourself.

  • In-flight goals are not auto-resumed after a restart. Use list_goals, then resume.

  • Automatic cross-provider fallback is not yet enabled.

  • Avoid running several goals in the same working directory.

MCP tools (17)

Category

Tools

Sessions

opencode_health, list_sessions, get_session_messages, create_session, send_prompt, send_prompt_async, get_session_status, abort_session, delete_session*

Filesystem

read_file, write_file, list_files, search_files, delete_file*

Terminal

run_command (via an OpenCode session and its permissions)

Git

git_status, git_diff

* Destructive: requires confirm: "DELETE".

Goal Runner tools are listed above.

Commands

Command

Action

./mcp start

Start all services

./mcp stop

Stop managed services

./mcp restart

Restart all services

./mcp status

Show service state and zrok URL

./mcp logs

Show recent logs

./mcp client

Open isolated OpenCode client

Logs and PIDs: ~/.local/state/opencode-remote-bridge/ · Client profile: ~/.config/opencode-remote-bridge/

Configuration

The ./mcp manager uses the default ports (4096 and 8787), so keep them when using it. When running the server directly with npm start, these environment variables apply (see .env.example):

Variable

Default

Meaning

BRIDGE_HOST

127.0.0.1

MCP bind interface

BRIDGE_PORT

8787

MCP port

OPENCODE_URL

http://127.0.0.1:4096

Local OpenCode API

BRIDGE_TOKEN_FILE

.bridge-token

Private token file

Keep the bridge bound to localhost when using zrok.

Termux + Debian (PRoot)

pkg update && pkg upgrade
pkg install proot-distro git
proot-distro install debian
proot-distro login debian --shared-tmp

Then follow the Debian steps above inside the shell. Android battery management can kill background processes, so exclude Termux from battery optimization.

Security

  • Use a unique, unpredictable bearer token per installation.

  • Never commit or share .bridge-token, client configs or credentials.

  • OpenCode and the bridge bind to localhost; zrok provides the public ingress.

  • Anyone with the token can invoke every exposed tool.

  • There is no per-tool authorization or sandboxing. Run it on a machine and in a project you are comfortable exposing.

Troubleshooting

Problem

Fix

Port in use

Stop the conflicting service on 4096 / 8787

zrok share won't start

Check zrok2 status, zrok2 list names, ./mcp logs

401 Unauthorized

Verify the Authorization header and token (unauthenticated requests return 401 by design)

OpenCode unavailable

Check the opencode CLI and ./mcp logs

Termux stops services

Keep Termux alive; disable battery optimization

Development

npm install
npm run check
npm start

CI runs JavaScript and shell syntax checks on pushes and pull requests.

src/
  config.js
  server.js
  lib/          # OpenCode API, output, path helpers
  middleware/   # Bearer authentication
  tools/        # OpenCode, filesystem, terminal, Git tools
scripts/
  install.sh
mcp             # service manager
.github/workflows/ci.yml

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Exposes local OpenCode instances as remote MCP servers for Claude and ChatGPT, enabling terminal access, session management, and interactive human-in-the-loop workflows. It simplifies deployment for local machines using Cloudflare Tunnels to provide secure public connectivity and OAuth support.
      -
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables 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.
      21,687 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables cloud AI agents to access local STDIO MCP servers and their tools through a single authenticated Streamable HTTP endpoint, optionally tunneled via ngrok.
      18 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Exposes an authenticated Streamable HTTP or stdio MCP endpoint that lets models list connected devices and route authorized operations to them over outbound WebSockets, including running commands, reading and writing files, taking screenshots, and sending mouse, keyboard, and scroll input. It works for machines behind NAT or containers without inbound ports, with per-device tokens and capability checks limiting what each caller can do.
      18
      MIT