Skip to content

Protocol

cmd-ipc uses a JSON-based message protocol for communication between registries. All messages are sent via channels—either directly (MessagePortChannel) or over HTTP (HTTPChannel).

When using HTTPChannel, two endpoints handle all communication:

Returns all available commands with their schemas. Used for client type generation and service discovery.

GET /cmds.json HTTP/1.1
Host: api.example.com
{
"cmdschema": "1.0.0",
"commands": [
{
"id": "user.create",
"description": "Creates a new user account",
"isLocal": true,
"schema": {
"request": {
"type": "object",
"properties": {
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
},
"required": ["name", "email"]
},
"response": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"email": { "type": "string" }
}
}
}
}
]
}

All protocol messages are sent via POST /cmd. The type field determines how the message is processed.

Default Transport: HTTP Streaming (NDJSON)

By default, HTTPChannel uses NDJSON (Newline-Delimited JSON) streaming for the response. Each message is a complete JSON object on its own line, allowing clients to process responses as they arrive:

{"id":"...","type":"execute.command.response","thid":"...","response":{"ok":true,"result":{...}}}
{"id":"...","type":"event","eventId":"user.updated","payload":{...}}

This streaming approach enables:

  • Real-time event delivery — Events can be pushed to the client as they occur
  • Progressive responses — Large results can be streamed incrementally
  • Efficient long-polling — Single connection for both command responses and events

The protocol defines seven message types grouped into four categories.


Request to execute a command on a remote registry.

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"type": "execute.command.request",
"commandId": "user.create",
"request": {
"name": "John Doe",
"email": "john@example.com"
}
}
FieldTypeDescription
idstringUnique message ID (UUID)
typestring"execute.command.request"
commandIdstringThe command to execute
requestobject?Command arguments (optional)

Response from command execution, indicating success or failure.

Success:

{
"id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"type": "execute.command.response",
"thid": "550e8400-e29b-41d4-a716-446655440000",
"response": {
"ok": true,
"result": {
"id": "usr_123",
"name": "John Doe",
"email": "john@example.com"
}
}
}

Error:

{
"id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"type": "execute.command.response",
"thid": "550e8400-e29b-41d4-a716-446655440000",
"response": {
"ok": false,
"error": {
"code": "COMMAND_NOT_FOUND",
"message": "Command not found: user.unknown"
}
}
}
FieldTypeDescription
idstringUnique message ID (UUID)
typestring"execute.command.response"
thidstringThread ID — matches the request’s id
response.okbooleanWhether execution succeeded
response.resultany?Command result (when ok: true)
response.errorobject?Error details (when ok: false)
response.error.codestringError code (e.g., COMMAND_NOT_FOUND, VALIDATION_ERROR)
response.error.messagestringHuman-readable error message

Used when channels connect to share available commands up the tree.

Registers a command from a remote registry.

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"type": "register.command.request",
"command": {
"id": "calc.factorial",
"description": "Computes factorial of n",
"schema": {
"request": {
"type": "object",
"properties": { "n": { "type": "number" } }
},
"response": {
"type": "object",
"properties": { "result": { "type": "number" } }
}
}
}
}
FieldTypeDescription
idstringUnique message ID (UUID)
typestring"register.command.request"
commandobjectCommand definition
command.idstringCommand ID (must be globally unique)
command.descriptionstring?Optional description
command.schemaobject?Optional JSON Schema for request/response

Acknowledgment of command registration.

Success:

{
"id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"type": "register.command.response",
"thid": "550e8400-e29b-41d4-a716-446655440000",
"response": {
"ok": true
}
}

Error (command already registered):

{
"id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"type": "register.command.response",
"thid": "550e8400-e29b-41d4-a716-446655440000",
"response": {
"ok": false,
"error": "COMMAND_ALREADY_REGISTERED"
}
}
FieldTypeDescription
idstringUnique message ID (UUID)
typestring"register.command.response"
thidstringThread ID — matches request’s id
response.okbooleanWhether registration succeeded
response.errorstring?Error code (when ok: false)

Used to query available commands from a remote registry.

Request a list of available commands.

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"type": "list.commands.request"
}
FieldTypeDescription
idstringUnique message ID (UUID)
typestring"list.commands.request"

Returns available commands from the remote registry.

{
"id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"type": "list.commands.response",
"thid": "550e8400-e29b-41d4-a716-446655440000",
"commands": [
{ "id": "math.add", "description": "Adds two numbers" },
{ "id": "math.multiply", "description": "Multiplies two numbers" }
]
}
FieldTypeDescription
idstringUnique message ID (UUID)
typestring"list.commands.response"
thidstringThread ID — matches request’s id
commandsarrayList of command definitions

Broadcast message to all connected registries. Events are fire-and-forget—they have no response.

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"type": "event",
"eventId": "user.created",
"payload": {
"userId": "usr_123",
"name": "John Doe"
}
}
FieldTypeDescription
idstringUnique message ID (UUID)
typestring"event"
eventIdstringEvent identifier (e.g., user.created)
payloadany?Event data (optional)