loading…
Search for a command to run...
loading…
Exposes local OpenCode instances as remote MCP servers for Claude and ChatGPT, enabling terminal access, session management, and interactive human-in-the-loop w
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.
[!WARNING] This project exposes remote shell execution, PTY control, session steering, and agent-driven code execution on the machine where it runs. Treat it like a personal-use remote code execution service. If this gateway is compromised, an attacker may be able to read files, execute commands, access credentials, damage data, or pivot deeper into your environment. Do not expose it to untrusted users. Use strong secrets. Keep the origin machine locked down.
This repository is the Cloudflare desktop deployment variant of opencode-mcp-gateway.
It is designed for:
Repository:
https://github.com/gjabdelnoor/opencode-mcp-gateway-cloudflare-desktopClaude / ChatGPT
|
v
https://mcp.example.com/mcp
|
v
Cloudflare Edge
|
v
cloudflared tunnel
|
v
http://127.0.0.1:3001
|
v
http://127.0.0.1:9999
|
v
OpenCode
You need OpenCode installed and working before this gateway can do anything useful.
OpenCode docs:
https://opencode.ai/docs/https://opencode.ai/docs/providers/https://opencode.ai/docs/server/Detailed docs in this repo:
docs/ubuntu-cloudflare-desktop-setup.mddocs/session-change-map.mdThere are two practical install paths documented here.
This is the recommended path.
Use this when you want a stable hostname like:
https://mcp.example.com/mcpWhy this is better:
mcp1, mcp2, mcp3trycloudflare TunnelThis is the free, no-personal-domain path.
Use this when you want to experiment without buying or wiring a domain.
Why this is worse:
sudo apt update
sudo apt install -y curl git python3 python3-pip python3-venv
curl -fsSL https://opencode.ai/install | bash
Then configure a provider and start OpenCode locally:
opencode serve --hostname 127.0.0.1 --port 9999
git clone https://github.com/gjabdelnoor/opencode-mcp-gateway-cloudflare-desktop.git
cd opencode-mcp-gateway-cloudflare-desktop
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
.envcp .env.example .env
Example:
MCP_AUTH_TOKEN=replace-with-a-long-random-secret
MCP_CLIENT_ID=opencode-mcp-gateway
MCP_ALLOWED_CLIENT_IDS=opencode-mcp-gateway
PUBLIC_BASE_URL=https://mcp.example.com
DEFAULT_WORKSPACE_DIR="/home/YOUR_USER/AI Projects"
OPENCODE_HOST=127.0.0.1
OPENCODE_PORT=9999
GATEWAY_PORT=3001
ENABLE_RAW_BASH=true
DEFAULT_PLANNING_MODEL=opencode/minimax-m2.5-free
DEFAULT_BUILDING_MODEL=openai/gpt-5.4-mini
Install cloudflared:
curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared.deb
rm cloudflared.deb
Authenticate and create the tunnel:
cloudflared tunnel login
cloudflared tunnel create opencode-mcp-gateway
cloudflared tunnel route dns opencode-mcp-gateway mcp.example.com
Create ~/.cloudflared/config.yml:
tunnel: YOUR_TUNNEL_ID
credentials-file: /home/YOUR_USER/.cloudflared/YOUR_TUNNEL_ID.json
ingress:
- hostname: mcp.example.com
service: http://127.0.0.1:3001
originRequest:
httpHostHeader: mcp.example.com
- service: http_status:404
Set:
PUBLIC_BASE_URL=https://mcp.example.comRun the tunnel:
cloudflared tunnel run opencode-mcp-gateway
trycloudflare pathInstall cloudflared the same way, then run:
cloudflared tunnel --url http://127.0.0.1:3001
That gives you a temporary https://...trycloudflare.com URL.
Use that URL as:
PUBLIC_BASE_URL=https://YOUR-TEMP-HOST.trycloudflare.comImportant caveat:
source .venv/bin/activate
python main.py
Check:
curl https://mcp.example.com/.well-known/oauth-authorization-server
curl https://mcp.example.com/.well-known/oauth-authorization-server/mcp
curl https://mcp.example.com/.well-known/oauth-protected-resource
curl -D - -o /dev/null https://mcp.example.com/mcp
You want:
https://mcp.example.comhttps://mcp.example.com/oauth/tokenhttps://mcp.example.com/mcp/mcp returns 401 with WWW-Authenticate and resource_metadataMCP server URL:
https://mcp.example.com/mcp
OAuth discovery URLs:
https://mcp.example.com/.well-known/oauth-authorization-serverhttps://mcp.example.com/.well-known/oauth-authorization-server/mcpManual OAuth values when needed:
opencode-mcp-gatewayMCP_AUTH_TOKENclient_secret_postmcpIf you want multiple chatbot-controlled agents at once, run multiple gateway processes.
Recommended layout:
mcp1.example.com -> localhost:3001mcp2.example.com -> localhost:3002mcp3.example.com -> localhost:3003mcp4.example.com -> localhost:3004mcp5.example.com -> localhost:3005mcp6.example.com -> localhost:3006Each instance should have its own:
PUBLIC_BASE_URLGATEWAY_PORTMCP_AUTH_TOKENMCP_CLIENT_ID| Variable | Description |
|---|---|
MCP_AUTH_TOKEN |
Bearer secret for OAuth token exchange and MCP access |
MCP_CLIENT_ID |
Main OAuth client ID accepted by the gateway |
MCP_ALLOWED_CLIENT_IDS |
Optional comma-separated allowlist of additional client IDs |
PUBLIC_BASE_URL |
External HTTPS base URL advertised in OAuth metadata |
DEFAULT_WORKSPACE_DIR |
Default project root for new sessions and PTYs |
OPENCODE_HOST |
OpenCode origin host |
OPENCODE_PORT |
OpenCode origin port |
GATEWAY_PORT |
Gateway listen port |
ENABLE_RAW_BASH |
Enables direct bash and bash_exec tools |
DEFAULT_PLANNING_MODEL |
Optional fallback model for planning-mode sessions |
DEFAULT_BUILDING_MODEL |
Optional fallback model for building-mode sessions |
BLOCKED_SESSION_MODELS |
Optional comma-separated models to reject even if OpenCode advertises them |
Use the full MCP URL:
https://mcp.example.com/mcp
Check:
PUBLIC_BASE_URL is correcthttps://mcp.example.com/mcpGET /mcp without auth returns 401 with WWW-AuthenticateMCP_AUTH_TOKENsession_create or send_message looks stalledCheck:
curl http://127.0.0.1:9999/session/status
If OpenCode is retrying an unsupported model, set or adjust:
DEFAULT_PLANNING_MODEL=opencode/minimax-m2.5-free
DEFAULT_BUILDING_MODEL=openai/gpt-5.4-mini
switch_model rejects a model you thought should workThe gateway now validates against OpenCode’s live model catalog.
It will reject:
minimax-coding-plan/MiniMax-M2.5-highspeedminimax-coding-plan/MiniMax-M2.7-highspeedSet:
DEFAULT_WORKSPACE_DIR="/home/YOUR_USER/AI Projects"
This repo now defaults new sessions and PTYs to that workspace if you do not pass an explicit directory.
Use separate gateway instances on separate hostnames and ports.
docs/ubuntu-cloudflare-desktop-setup.mddocs/session-change-map.mdIf you have questions, comments, setup issues, or serious security concerns, contact @isnotgabe on Discord.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"opencode-mcp-gateway": {
"command": "npx",
"args": []
}
}
}