OpenCode MCP Gateway
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 GatewayShow me all my active OpenCode sessions"
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 Gateway Cloudflare Desktop
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:
an Ubuntu desktop or laptop
a local OpenCode server
a public HTTPS MCP endpoint fronted by Cloudflare Tunnel
Claude and ChatGPT OAuth-compatible remote MCP usage
no VPS
Repository:
https://github.com/gjabdelnoor/opencode-mcp-gateway-cloudflare-desktop
Architecture
Claude / 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
OpenCodeRead This First
You need OpenCode installed and working before this gateway can do anything useful.
OpenCode docs:
Intro:
https://opencode.ai/docs/Providers:
https://opencode.ai/docs/providers/Server mode:
https://opencode.ai/docs/server/
Detailed docs in this repo:
docs/ubuntu-cloudflare-desktop-setup.mddocs/session-change-map.md
Installation Paths
There are two practical install paths documented here.
Path A: Purchased Domain + Cloudflare DNS
This is the recommended path.
Use this when you want a stable hostname like:
https://mcp.example.com/mcp
Why this is better:
stable OAuth issuer URL
stable connector configuration
better long-term reliability
easier to run multiple gateways like
mcp1,mcp2,mcp3
Path B: Free Cloudflare trycloudflare Tunnel
This is the free, no-personal-domain path.
Use this when you want to experiment without buying or wiring a domain.
Why this is worse:
hostname is temporary
hostname can change on reconnect
OAuth clients may break when the issuer URL changes
not ideal for durable Claude or ChatGPT connectors
Quick Start
1. Install Ubuntu packages
sudo apt update
sudo apt install -y curl git python3 python3-pip python3-venv2. Install and configure OpenCode
curl -fsSL https://opencode.ai/install | bashThen configure a provider and start OpenCode locally:
opencode serve --hostname 127.0.0.1 --port 99993. Clone this repo and install dependencies
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.txt4. Create .env
cp .env.example .envExample:
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-mini5. Choose a tunnel path
Purchased domain path
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.debAuthenticate and create the tunnel:
cloudflared tunnel login
cloudflared tunnel create opencode-mcp-gateway
cloudflared tunnel route dns opencode-mcp-gateway mcp.example.comCreate ~/.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:404Set:
PUBLIC_BASE_URL=https://mcp.example.com
Run the tunnel:
cloudflared tunnel run opencode-mcp-gatewayFree trycloudflare path
Install cloudflared the same way, then run:
cloudflared tunnel --url http://127.0.0.1:3001That gives you a temporary https://...trycloudflare.com URL.
Use that URL as:
PUBLIC_BASE_URL=https://YOUR-TEMP-HOST.trycloudflare.com
Important caveat:
this path is still considered experimental here
if the hostname changes, you will usually need to recreate the connector in Claude or ChatGPT
6. Start the gateway
source .venv/bin/activate
python main.pyVerify The Deployment
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/mcpYou want:
OAuth issuer:
https://mcp.example.comtoken endpoint:
https://mcp.example.com/oauth/tokenprotected resource:
https://mcp.example.com/mcpunauthorized
/mcpreturns401withWWW-Authenticateandresource_metadata
Connect ChatGPT Or Claude
MCP server URL:
https://mcp.example.com/mcpOAuth discovery URLs:
Claude:
https://mcp.example.com/.well-known/oauth-authorization-serverChatGPT:
https://mcp.example.com/.well-known/oauth-authorization-server/mcp
Manual OAuth values when needed:
OAuth Client ID:
opencode-mcp-gatewayOAuth Client Secret: your
MCP_AUTH_TOKENToken auth method:
client_secret_postScope:
mcp
Multiple Concurrent Agents
If 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:3006
Each instance should have its own:
PUBLIC_BASE_URLGATEWAY_PORTMCP_AUTH_TOKENMCP_CLIENT_ID
Configuration
Variable | Description |
| Bearer secret for OAuth token exchange and MCP access |
| Main OAuth client ID accepted by the gateway |
| Optional comma-separated allowlist of additional client IDs |
| External HTTPS base URL advertised in OAuth metadata |
| Default project root for new sessions and PTYs |
| OpenCode origin host |
| OpenCode origin port |
| Gateway listen port |
| Enables direct |
| Optional fallback model for planning-mode sessions |
| Optional fallback model for building-mode sessions |
| Optional comma-separated models to reject even if OpenCode advertises them |
Troubleshooting
ChatGPT says the server URL is invalid
Use the full MCP URL:
https://mcp.example.com/mcpClaude reaches login but the connector still fails
Check:
PUBLIC_BASE_URLis correctprotected resource metadata returns
https://mcp.example.com/mcpGET /mcpwithout auth returns401withWWW-Authenticatethe OAuth client secret exactly matches
MCP_AUTH_TOKEN
session_create or send_message looks stalled
Check:
curl http://127.0.0.1:9999/session/statusIf OpenCode is retrying an unsupported model, set or adjust:
DEFAULT_PLANNING_MODEL=opencode/minimax-m2.5-free
DEFAULT_BUILDING_MODEL=openai/gpt-5.4-miniswitch_model rejects a model you thought should work
The gateway now validates against OpenCode’s live model catalog.
It will reject:
anything not currently exposed by OpenCode
I may have hardcoded it to reject the two known-bad models on my minimax plan... oops:
minimax-coding-plan/MiniMax-M2.5-highspeedminimax-coding-plan/MiniMax-M2.7-highspeed
Sessions are starting in the wrong folder
Set:
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.
Several bots interfere with each other
Use separate gateway instances on separate hostnames and ports.
Full Docs
docs/ubuntu-cloudflare-desktop-setup.mddocs/session-change-map.md
Questions Or Security Concerns
If you have questions, comments, setup issues, or serious security concerns, contact @isnotgabe on Discord.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
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/gjabdelnoor/opencode-mcp-gateway-cloudflare-desktop'
If you have feedback or need assistance with the MCP directory API, please join our Discord server