Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

schema

commandschema
KindOffline discovery
NeedsNothing: no configuration, identity, network or stdin
Statusesok, error
Schemasschemas/schema.input.json, schemas/schema.output.json

Describes the machine interface of this binary: every command, whether it supports JSON, its input schema, its output schema and the configuration it reads.

Invocation

mostro-cli --output json schema
mostro-cli schema                  # human mode: the same DiscoveryData, pretty-printed, without envelope

Input

None. Any option is invalid_arguments.

Behavior

Pure and deterministic for a given binary. It never reads environment values (so it never prints secrets or relay URLs), never opens the database and never connects. Call it once at wrapper start-up and cache it keyed by executable_version.

Success data: DiscoveryData

FieldTypeMeaning
schema_versionstringContract version, "1"
executable_versionstringPackage version of the binary, e.g. "0.16.3"
schema_dialectstring"https://json-schema.org/draft/2020-12/schema"
commandsarray of CommandDescriptorSorted by name; JSON-capable and human-only commands alike

CommandDescriptor

FieldTypeMeaning
namestringCanonical dotted name, as in the command field of outcomes
cli_patharray of stringTokens to type today, e.g. ["order", "take-sell"], ["getdmuser"]
output_modesarray of "human" | "json"["human", "json"] for migrated commands, ["human"] for legacy ones
input_schemaobject or nullJSON Schema of the options; null for human-only commands
output_schemaobject or nullJSON Schema of the whole envelope; null for human-only commands
required_configurationarray of string or nullEnvironment variables read (["MOSTRO_PUBKEY", "RELAYS"]); [] for schema; null when not modeled (legacy)

Example descriptor (trimmed):

{
  "name": "order.cancel",
  "cli_path": ["order", "cancel"],
  "output_modes": ["human", "json"],
  "input_schema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "order": { "type": "string", "description": "Id of the order" },
      "yes": { "type": "string", "enum": ["true", "false"], "description": "Send the request without asking (required with --output json)" }
    },
    "required": ["order"]
  },
  "output_schema": { "title": "...", "oneOf": ["..."], "$defs": {"...": "..."} },
  "required_configuration": ["MOSTRO_PUBKEY", "RELAYS"]
}

Input schemas use one extension keyword: "x-case-insensitive": true on enums that accept any letter case (side, status of order list).

Outcomes

CasestatuscodeStages
Describedoknot_applicable ×3
An option was givenerrorinvalid_arguments (exit 2)not_applicable ×3
Could not serializeerrorinternal_errornot_applicable ×3

Using it in a wrapper

# names of JSON commands and the codes each can fail with
mostro-cli --output json schema | jq -r '
  .data.commands[] | select(.output_schema != null) |
  "\(.name): \([.output_schema.oneOf[] | .properties.error.properties.code.enum? // empty] | add | unique | join(", "))"'

Check at start-up that every command your wrapper uses is present with "json" in output_modes; refuse to run against an older binary instead of failing mid-trade.

Examples

The full discovery document (all commands, inputs, outputs)

schema/discovery · status ok · exit 0 · captured

mostro-cli --output json schema

The document is about 110 KB; see schemas/discovery.json.

schema takes no options

schema/invalid_arguments · status error · invalid_arguments · exit 2 · captured

mostro-cli --output json schema --bogus
{
  "schema_version": "1",
  "command": "schema",
  "status": "error",
  "data": null,
  "error": {
    "code": "invalid_arguments",
    "message": "The command arguments are invalid."
  },
  "warnings": [],
  "meta": {
    "publication": "not_applicable",
    "daemon_acceptance": "not_applicable",
    "persistence": "not_applicable",
    "snapshot": null
  }
}

Next

Command index · order list