Base protocol

The message layer of MCoP: the request, response and push envelopes, the operations, identifiers and limits.

Encoding

All messages are UTF-8 JSON objects. A server and a client MUST accept messages up to max_message_bytes (default 1 MiB) and MUST reject larger ones. Field names are snake_case.

Messages are sent over one of the transports in Transports. The message layer is the same on each.

Envelopes

A message is exactly one of three envelopes.

Request (client to server):

{"id": "1", "op": "subscribe", "body": {"conversation_id": "conv_…"}, "trace": {"traceparent": "…"}}
  • id MUST be unique on the connection while the request is pending.
  • op MUST be one of the operations below.
  • body depends on the operation.
  • trace is OPTIONAL and carries W3C trace context for transports without headers.

Response (server to client, answering a request with the same id):

{"id": "1", "ok": true, "result": {…}}
{"id": "1", "ok": false, "error": {"code": "unknown_conversation", "message": "…"}}

Push (server to client, unsolicited):

{"push": "frames", "body": {…}}

A client MUST NOT answer a push. The server MUST NOT send a response with no request.

Operations

OperationBodyResult
initializeprotocol_versions, conversation_versions, client, capabilitiesprotocol_version, conversation_versions, server, principal, capabilities, agreed, downgrades
commanda command (Commands)a receipt
subscribeconversation_id, optional cursora snapshot, or an acknowledged resume with cursor
read_afterconversation_id, cursor, optional limitframes, cursor, up_to_date, or resnapshot_reason
get_receiptcommand (the same command, to compare its payload)the stored receipt
unsubscribeconversation_idempty

unsubscribe releases a subscription. It never cancels work that the server is doing for the conversation.

A client MUST call initialize once per connection before any other operation. A server MUST reject other operations before initialize with invalid_command.

Pushes

PushBodyMeaning
framesconversation_id, frames, optional up_to_dateOne or more frames of one conversation, in cursor order
resnapshot_requiredconversation_id, reasonThe stream cannot continue; subscribe again from a snapshot

Identifiers

IdentifierScopeFormat
Request idone connectiona string chosen by the client
command_idone sender and one conversationa string chosen by the client; protocol.NewID creates one
Conversation, participant, event IDsglobalprefixed strings such as conv_…, par_…, evt_…
Projection ID and epochone conversationidentify the journal a cursor belongs to

Clients MUST generate command_id values that are unique for their sender and conversation. They MAY reuse a command_id only to retry the same command.

Limits

The server advertises its limits in the initialize result. These are the version 1 defaults:

LimitDefaultMeaning
max_message_bytes1 MiBLargest message on the wire
max_event_bytes64 KiBLargest event
max_parts32Parts in one message
max_mentions32Mentions in one message
max_relations8Relations on one event
page_size50Events per page of a timeline read

A server MUST refuse a command that exceeds a limit with payload_too_large. A client SHOULD read the limits from initialize rather than hard-code them.

Errors

An error has a code, an optional message, and optional retryable and retry_after_ms fields. The codes are listed in Commands and Delivery. A client MUST NOT retry an error that is not retryable with the same request unless the cause has changed.

Next steps