Overview
Gateways are the bridge between Mission Control and the OpenClaw agent runtime. Each gateway represents a running OpenClaw instance that hosts and manages agent workspaces. Mission Control communicates with gateways through a WebSocket-based RPC protocol to provision agents, sync configuration files, and send messages.Architecture
Data Model
Frombackend/app/models/gateways.py:
Gateway Types
Mission Control supports two deployment patterns:Self-Hosted Gateway
Use Case: Development, testing, or single-organization deployments. Characteristics:- Runs on the same host as Mission Control
- Direct file system access to workspaces
- Typically uses
disable_device_pairing: true - Example URL:
ws://localhost:18789
Remote Gateway
Use Case: Production deployments, multi-tenant scenarios. Characteristics:- Runs on separate infrastructure
- Requires network-accessible WebSocket endpoint
- Uses standard device pairing flow
- Example URL:
wss://gateway.example.com:18789
RPC Communication
Mission Control communicates with gateways using a JSON-RPC style protocol over WebSockets.Connection Flow
- Open WebSocket — Connect to gateway URL (default port: 18789)
- Authenticate — Send control UI authentication (if
disable_device_pairing: true) - Call Methods — Send RPC requests, receive responses
- Handle Errors — Retry with exponential backoff on connection failures
backend/app/services/openclaw/gateway_rpc.py
RPC Methods
Mission Control uses these OpenClaw gateway methods:Agent Management
File Operations
Session Management
Configuration Management
Health Check
Error Handling
The RPC client implements retry logic with exponential backoff:| Error | Meaning | Resolution |
|---|---|---|
Connection refused | Gateway not running | Start OpenClaw gateway |
missing scope: operator.read | Auth disabled | Set dangerouslyDisableDeviceAuth: true |
unknown agent | Agent doesn’t exist | Create agent first |
not found | Session/file missing | Create or sync resources |
Workspace Structure
Each agent gets its own workspace directory:Workspace Path Calculation
Frombackend/app/services/openclaw/provisioning.py:_workspace_path():
workspace_root:/home/ubuntu/workspacesagent_key:mc-e595d5d1-6d85-439c-82e1-8f388a302e6a- Result:
/home/ubuntu/workspaces/workspace-mc-e595d5d1-6d85-439c-82e1-8f388a302e6a
Template Sync
Template sync updates agent workspace files across the gateway.Sync Endpoint
Sync Flow
Implementation:backend/app/services/openclaw/admin_service.py
- Query Agents — Load agents from database for the gateway
- Filter Scope — Apply
board_id,lead_only,include_mainfilters - Read Tokens — Try to read existing
AUTH_TOKENfrom TOOLS.md - Render Templates — Generate files from Jinja2 templates
- Write Files — Call
agents.files.setfor each template - Update Heartbeats — Patch gateway config with new heartbeat settings
- Return Results — Summary of updates, skips, and errors
Sync Response
When to Rotate Tokens
Userotate_tokens=true when:
- First Setup — Initial gateway configuration
- Agent Config Lost — Agents deleted from
openclaw.json - Cannot Read TOOLS.md — Gateway returns “not found” or “unknown agent”
- Security Rotation — Periodic token refresh
Device Pairing
Standard OpenClaw gateways require device pairing for control UI access.Bypassing Device Pairing
For Mission Control integration, setdisable_device_pairing: true in the gateway record and configure:
dangerouslyDisableDeviceAuth on trusted networks or with additional authentication layers.
With Device Pairing
For production deployments:- Set
disable_device_pairing: falsein Mission Control - Complete device pairing flow through OpenClaw UI
- Store the device token in Mission Control’s
tokenfield - Mission Control uses the device token for RPC authentication
Gateway Main Agent
Each gateway has a special “main” agent for organization-level operations.Characteristics
- One per gateway (not board-scoped)
- No
board_id(organization-level) - Session key:
gateway:mc-gateway-<uuid>:main - Agent ID:
mc-gateway-<uuid> - Workspace:
{workspace_root}/workspace-gateway-<uuid>
Creation
The gateway-main agent is automatically created when a gateway is first registered:backend/app/services/openclaw/admin_service.py:create_gateway() for implementation.
Version Compatibility
Mission Control enforces minimum gateway version requirements:backend/app/services/openclaw/gateway_compat.py
If a gateway is running an older version, provisioning and sync operations will fail with a version mismatch error.
Related API Endpoints
Gateway Management
GET /api/v1/gateways— List all gatewaysPOST /api/v1/gateways— Create gateway (provisions main agent)GET /api/v1/gateways/{id}— Get gateway detailsPATCH /api/v1/gateways/{id}— Update gateway configurationDELETE /api/v1/gateways/{id}— Delete gateway
Template Operations
POST /api/v1/gateways/{id}/templates/sync— Sync templates to agents
Runtime Operations
GET /api/v1/gateway/status— Gateway health statusGET /api/v1/gateway/sessions— Active sessionsGET /api/v1/gateway/sessions/{id}— Session detailsGET /api/v1/gateway/sessions/{id}/history— Chat historyPOST /api/v1/gateway/sessions/{id}/message— Send message to session
Troubleshooting
”missing scope: operator.read”
Cause: Gateway doesn’t havedangerouslyDisableDeviceAuth enabled.
Fix:
”unable to read AUTH_TOKEN from TOOLS.md”
Cause: Agent doesn’t exist in gateway config (deleted fromopenclaw.json).
Fix: Run template sync with token rotation:
Connection Refused
Cause: Gateway not running or wrong URL. Fix:- Check gateway is running:
ps aux | grep openclaw - Verify URL in gateway record matches actual endpoint
- Check firewall rules allow WebSocket connections on port 18789
Source Files
- Models:
backend/app/models/gateways.py - Schemas:
backend/app/schemas/gateways.py - RPC Client:
backend/app/services/openclaw/gateway_rpc.py - Admin Service:
backend/app/services/openclaw/admin_service.py - Provisioning:
backend/app/services/openclaw/provisioning.py - API Routes:
backend/app/api/gateways.py,backend/app/api/gateway_api.py
Next Steps
Agents
Learn how agents are provisioned and managed through gateways
Tasks
Understand how agents execute work through task assignments