Skip to content

Real-time Events

Klaxon provides two real-time transports:

TransportEndpointAudienceProtocol
SSEGET /mcp/sseMCP agentsServer-Sent Events (MCP spec)
WebSocketGET /api/wsWeb/mobile clientsWebSocket (JSON messages)

Both are powered by Postgres LISTEN/NOTIFY on the klaxon_events channel, so events propagate across server replicas.

WebSocket (Clients)

Connect with a bearer token:

javascript
const ws = new WebSocket("ws://localhost:3000/api/ws");
ws.onmessage = msg => {
  const event = JSON.parse(msg.data);
  console.log(event.kind, event.id);
};

Event Kinds

KindDescription
item.createdNew item created
item.updatedItem fields changed
item.answeredForm response submitted
item.dismissedItem dismissed
item.archivedItem archived
bulk.updatedMultiple items changed
item.viewedItem marked as viewed

Event Payload

json
{
  "org_id": "...",
  "kind": "item.created",
  "id": "item-uuid"
}

Events are filtered by org_id — you only receive events for your organization.

SSE (MCP Agents)

Per the MCP spec, agents subscribe via SSE:

bash
curl -N http://localhost:3000/mcp/sse \
  -H "Authorization: Bearer API_KEY"

Events are sent as event: notifications/klaxon with JSON data.

How It Works

  1. A mutation (create, update, dismiss, etc.) calls pg_notify('klaxon_events', payload)
  2. All server replicas receive the notification via their PgListener
  3. SSE and WebSocket handlers filter by org_id and forward to connected clients