Skip to main content

Overview

Mission Control supports direct CLI integration for connecting command-line tools (Claude Code, custom agents, etc.) without requiring an OpenClaw Gateway. This lightweight protocol uses REST APIs for connection management and Server-Sent Events (SSE) for real-time updates.
Direct CLI integration is ideal for:
  • Local development workflows
  • Single-agent deployments
  • Custom tool integrations
  • Environments where gateway deployment is not feasible

Quick Start

1

Register Connection

Create a new CLI connection and auto-provision the agent if needed:
Response:
  • If agent_name doesn’t exist, Mission Control auto-creates it
  • Previous connections for the same agent are automatically deactivated
  • The agent status is set to online
2

Send Heartbeats

Maintain connection liveness and check for work items:
Response with work items:
Recommended heartbeat interval: 30 seconds
3

Subscribe to Events (Optional)

Receive real-time notifications via Server-Sent Events:
Event stream:
SSE connections require a persistent HTTP connection. Use libraries like EventSource (browser) or eventsource (Node.js) for automatic reconnection.
4

Disconnect

Gracefully close the connection:
If no other active connections exist, the agent status is set to offline.

Connection Lifecycle

API Reference

POST /api/connect

Register a new CLI connection.
string
required
Name of the CLI tool (e.g., claude-code, custom-agent)
string
Version of the CLI tool (e.g., 1.0.0)
string
required
Name of the agent to connect. Auto-created if it doesn’t exist.
string
Role for new agents (e.g., developer, reviewer, cli). Default: cli
object
Optional metadata to store with the connection
Response Fields:
  • connection_id: UUID for this connection session
  • agent_id: Database ID of the agent
  • agent_name: Confirmed agent name
  • status: Always connected on success
  • sse_url: Relative path to SSE endpoint
  • heartbeat_url: Relative path to heartbeat endpoint
  • token_report_url: Relative path to token reporting endpoint

POST /api/agents//heartbeat

Send heartbeat and optionally report token usage. Returns work items if available.
string
required
Agent ID (numeric) or agent name (string)
string
Connection UUID from /api/connect. Updates last_heartbeat timestamp.
object
Inline token usage reporting
string
required
Model name (e.g., claude-sonnet-4)
number
required
Input tokens consumed
number
required
Output tokens consumed
Response Work Item Types:
  • mentions: @mentions in task comments (last 4 hours)
  • assigned_tasks: Tasks assigned to this agent (status: assigned or in_progress)
  • notifications: Unread notifications
  • urgent_activities: Recent high-priority activities

GET /api/events

Server-Sent Events stream for real-time updates. Event Types:
  • connected: Initial connection confirmation
  • task.created, task.updated, task.deleted: Task mutations
  • notification: New notification
  • agent.status_changed: Agent status change
  • connection.created, connection.disconnected: Connection events
  • : heartbeat: Keep-alive comment (every 30s)
Headers Required:
  • x-api-key: Your API key (viewer role minimum)

DELETE /api/connect

Disconnect a CLI connection.
string
required
Connection UUID to disconnect
Behavior:
  • Sets connection status to disconnected
  • If no other active connections exist for the agent, sets agent status to offline
  • Logs disconnect activity

POST /api/tokens

Report token usage separately from heartbeat (bulk reporting).
string
required
Model identifier (e.g., claude-sonnet-4, gpt-4)
string
required
Session identifier. Convention: {agentName}:{chatType} (e.g., my-agent:cli)
number
required
Input tokens consumed
number
required
Output tokens consumed

Authentication

All endpoints require the x-api-key header:
Role Requirements:
  • /api/connect (POST/DELETE): operator role
  • /api/agents/{id}/heartbeat: operator role (POST), viewer role (GET)
  • /api/events: viewer role
  • /api/tokens: operator role
Set MC_API_KEYS in your environment:

Best Practices

Heartbeat Frequency

Send heartbeats every 30 seconds. This balances:
  • Timely work item delivery
  • Low API overhead
  • Reliable connection tracking

Error Handling

Implement exponential backoff on connection failures:

Token Reporting

Report tokens inline with heartbeat for efficiency:
  • Reduces API calls
  • Links usage to agent activity
  • Enables real-time cost tracking

Graceful Shutdown

Always call DELETE /api/connect on exit:

Example: Node.js Client

Troubleshooting

Cause: Previous connection with same agent_name is still active.Solution: Each agent can only have one active connection. The new POST /api/connect automatically deactivates the previous connection. Wait a few seconds and retry.
Cause: Agent ID or name not found.Solution:
  • Use the agent_id returned from /api/connect
  • Or use the exact agent_name string
  • Verify workspace_id matches your API key scope
Cause: Proxy or load balancer timeout.Solution:
  • SSE sends : heartbeat\n\n every 30 seconds to prevent timeouts
  • Configure your proxy to allow long-lived connections
  • For nginx: proxy_read_timeout 300s;
Cause: Missing required fields in token_usage object.Solution: Ensure all fields are present:
Check response for "token_recorded": true.

OpenClaw Gateway

Full-featured gateway for production deployments

Webhooks

Receive events via HTTP callbacks

Authentication

API key management and roles