7 min read

Server-Sent Events

Consuming Real-Time Events via SSE

Mission Control exposes a Server-Sent Events (SSE) endpoint that streams agent activity in real time. This is the same mechanism the dashboard uses internally, and it’s available for any client that can consume SSE.

The SSE Endpoint

GET /api/events
Authorization: Bearer <your-token>
Accept: text/event-stream

The connection stays open indefinitely. The server pushes events as they occur, with no polling required.

Event Format

Each event follows the standard SSE format:

id: 42
event: activity
data: {"taskId":"abc123","agentId":"agent-1","type":"progress","message":"Reading src/auth/middleware.ts","timestamp":"2025-01-15T10:30:00Z"}

The id field increments with each event and can be used for reconnection (see below).

Event Types

Mission Control emits several event types over SSE:

Event TypeWhen It Fires
activityAgent emits a progress update
status_changeA task’s status changes
dispatchA task is dispatched to an agent
completeAn agent reports task completion
errorAn agent reports a failure

Reconnection with Last-Event-ID

If your SSE connection drops, reconnect and include the Last-Event-ID header set to the last event ID you received:

GET /api/events
Last-Event-ID: 42

Mission Control buffers recent events and will replay any events you missed since that ID, ensuring no events are lost during brief disconnections.

Filtering the Stream

By default, the SSE endpoint streams events for all tasks and agents. You can filter to a specific task or agent:

GET /api/events?taskId=abc123
GET /api/events?agentId=agent-1

Using SSE in Code

Any HTTP client that supports streaming can consume SSE. In Node.js:

const EventSource = require('eventsource');
const es = new EventSource('http://localhost:4000/api/events', {
  headers: { Authorization: 'Bearer <token>' }
});
es.addEventListener('activity', (e) => console.log(JSON.parse(e.data)));