Reference implementation
The canonical reference Adapter is
pack-hello-world/adapter.py
in the platform repo: the smallest
possible complete Adapter, Python stdlib only,
used by the platform’s smoke tests. Read it top to bottom: it is about 200 lines
and exercises every part of the contract:
- Handshake:
hellowithmpp = 2, the Pack ID, amanifest_hashcomputed at startup by shelling out tomobrule pack print-hash(never hand-pinned), and abridge_tokenthat authenticates the connection. The Adapter readsMOBRULE_ADAPTER_TOKENfrom its environment and sends that value as the hello frame’sbridge_token; the bridge hashes it against the Adapter-token hash it minted and rejects a mismatch. - Credit priming: one
pullper declared queue afterhello_ack. - Per-queue dispatch table:
invocation.queueselects a handler, so a multi-queue Pack adds an entry instead of restructuring the loop. - Lifecycle replies:
ack→applied(with aresult) →done, then a freshpullon the same queue;failedwith areasonfor unknown events. - Pack state: a running counter published via
state_writeafter each applied Event, feeding the overlay’s counter widget. - Heartbeat thread: a
heartbeatframe every 15 s.
Environment
Section titled “Environment”The reference Adapter reads its connection parameters from the environment:
| Variable | Default | Meaning |
|---|---|---|
BRIDGE_HOST | 127.0.0.1 | Bridge MPP host. |
BRIDGE_PORT | 7777 | Bridge MPP port. |
MOBRULE_ADAPTER_TOKEN | (required) | Adapter auth token, sent as the hello bridge_token. |
There is one token. When the bridge launches the Adapter itself
(adapter.launch), it injects the token into the child process as
MOBRULE_ADAPTER_TOKEN, and the Adapter reads exactly that variable. A
hand-launched dev Adapter must set MOBRULE_ADAPTER_TOKEN itself. The Adapter
reads it with no fallback: if the variable is absent the process exits with a
KeyError before connecting.
Porting to another language
Section titled “Porting to another language”There is no SDK to link: MPP is newline-delimited JSON over a TCP socket, so the reference Adapter ports almost mechanically to any language. Keep these invariants:
- One JSON object per line; read line-by-line, never by fixed buffer.
hellomust be your first frame; wait forhello_ack.okbefore anything else, and applyhello_ack.persisted[]before your firststate_write.- Never assume push without credit: no
pull, no Invocations. - Treat
configframes as latched values and apply them idempotently. - On
protocol_error, log the message and exit non-zero; it is always a bug on your side or a stale manifest, never a transient condition.
See also
Section titled “See also”- Python tutorial: the guided walkthrough.
- MPP protocol: the authoritative wire spec.