Quickstart
This walkthrough takes you from an empty ontology to a working slice of the illustrative ice cream maker: shops and the refrigerated runs that serve them, linked through their stops, with an action that adds tubs to a run that has not left. You write the ontology folder, load the source tables, build the backing datasets, then query the objects and apply the action from the mso command, Python and TypeScript. Plan on about an hour
top-up-delivery, with conditions and writebackmso command, typed Python and typed TypeScriptIn the platform today
- Everything on this page runs in the platform service, and the outputs shown are what it returns, trimmed to the fields that matter where an ellipsis shows
- An ontology is a folder:
ontology.yamlfor object, link and action types, people and watched folders,pipelines.yamlfor the backing datasets,functions.pyfor functions andsystems.yamlfor writeback targets, as described in Object types, Pipelines and Writeback - The service reads the folder when it starts and again on
POST /api/v2/ontology:reload - This quickstart edits the folder of a test service directly
- On a shared implementation the same definitions go in through a change set on the Model changes screen, which is checked, previewed and reviewed before it merges, as described in Branches and proposals
- A test service of your implementation, at
https://ontology.example.comon this page, and write access to the folder it loads its ontology from. The quickstart replaces that ontology, so use a service nobody else relies on - An access token from your identity provider, for the person you list as an administrator in the first step
- The Python client package,
mso-client, on Python 3.11 or later. It also installs themsocommand - For the TypeScript step, Node.js 22.18 or later and the TypeScript client,
@marklandstreet/ontology-client
What you will build
By the end you will have the slice of ontology below, backed by tables loaded from the point of sale and the dispatch system, and a short script that finds the runs still at the creamery that stop at an open shop and adds tubs to one of them. The action writes the new load back to the dispatch system, and the next refresh reads it back as source data
Before you start
Every command on this page reads the service address and your token from the environment. Check that the service answers
export MSO_API_URL=https://ontology.example.com
export MSO_TOKEN="<access token from your identity provider>"
mso health
status ok …The CSV files below stand in for exports from a point of sale and a dispatch system. A connectors: entry in ontology.yaml reads the same tables from the systems themselves, such as a PostgreSQL reporting replica, on a schedule. See Connectors
Start the ontology
Start ontology.yaml with a name, an access label, the people who use the ontology and three watched folders, one for each table you will load. List yourself in admins: administrators reload the ontology and run every pipeline. Each folder lands its files in one raw table and upserts rows by key, so a corrected file updates rows instead of adding them
# ontology.yaml
name: Creamery operations
description: Scoop shops and the reefer runs that serve them
timezone: America/Halifax
accessLabels:
- { id: INTERNAL, name: Internal }
users: # ids as your identity provider signs people in
- { id: ops.lead, name: Operations lead, groups: [admins, operations],
accessLabels: [INTERNAL] }
- { id: dispatch.desk, name: Dispatch desk, groups: [dispatch], accessLabels: [INTERNAL] }
ingest:
folders:
pos-locations:
{ table: raw.pos_locations, key: [store_code], pattern: ["*.csv"],
allowedGroups: [operations] }
tms-runs:
{ table: raw.tms_runs, key: [run_id], pattern: ["*.csv"],
allowedGroups: [operations] }
tms-stops:
{ table: raw.tms_stops, key: [run_id, stop_seq], pattern: ["*.csv"],
allowedGroups: [operations] }
Save the file in the service's ontology folder and reload. The answer is the folder's new revision
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
{"revision":"da969c912368"}Load the source tables
Save the three exports below as locations.csv, runs.csv and stops.csv, and upload each one to its folder. A file loads once, by its content, so uploading the same file again is skipped
store_code,store_name,town,province,season_type,location_status
SHP-CHT,Queen Street,Charlottetown,PE,YEAR_ROUND,OPEN
SHP-CAV,Cavendish Boardwalk,Cavendish,PE,SEASONAL,CLOSED_FOR_SEASON
SHP-SUM,Water Street,Summerside,PE,YEAR_ROUND,OPEN
SHP-HFX,Halifax Waterfront,Halifax,NS,YEAR_ROUND,OPEN
run_id,run_name,departure,eta,tubs,pallets,trailer_pallets,run_status
DLV-5521,Island east run,2026-10-30T07:00:00-03:00,2026-10-30T11:30:00-03:00,160,4,8,IN_TRANSIT
DLV-5523,Summerside and Halifax,2026-10-30T13:00:00-03:00,2026-10-30T19:30:00-03:00,200,5,8,LOADING
DLV-5524,Charlottetown top-up,2026-10-31T08:00:00-03:00,2026-10-31T09:00:00-03:00,64,2,6,SCHEDULED
run_id,stop_seq,stop_code,stop_kind,planned_arrival,stop_status
DLV-5521,1,SHP-CHT,SHOP,2026-10-30T08:00:00-03:00,DONE
DLV-5521,2,SHP-CAV,SHOP,2026-10-30T09:15:00-03:00,DROPPED
DLV-5523,1,SHP-SUM,SHOP,2026-10-30T14:30:00-03:00,PLANNED
DLV-5523,2,SHP-HFX,SHOP,2026-10-30T19:30:00-03:00,PLANNED
DLV-5524,1,SHP-CHT,SHOP,2026-10-31T09:00:00-03:00,PLANNED
DLV-5524,2,WHL-0412,CUSTOMER,2026-10-31T10:30:00-03:00,PLANNED
curl -X POST \
"$MSO_API_URL/api/v2/ingest/folders/pos-locations/files?name=locations.csv" \
-H "Authorization: Bearer $MSO_TOKEN" --data-binary @locations.csv
curl -X POST \
"$MSO_API_URL/api/v2/ingest/folders/tms-runs/files?name=runs.csv" \
-H "Authorization: Bearer $MSO_TOKEN" --data-binary @runs.csv
curl -X POST \
"$MSO_API_URL/api/v2/ingest/folders/tms-stops/files?name=stops.csv" \
-H "Authorization: Bearer $MSO_TOKEN" --data-binary @stops.csv
{…,"folder":"pos-locations","table":"raw.pos_locations","status":"succeeded","rows":4,…}{…,"folder":"tms-runs","table":"raw.tms_runs","status":"succeeded","rows":3,…}{…,"folder":"tms-stops","table":"raw.tms_stops","status":"succeeded","rows":6,…}Read a raw table back with SQL. Each row also records the file it came from
mso sql "select run_id, stop_seq, stop_code, stop_kind, stop_status, _source_file
from raw.tms_stops"
run_id stop_seq stop_code stop_kind stop_status _source_file
-------- -------- --------- --------- ----------- ------------
DLV-5521 1 SHP-CHT SHOP DONE stops.csv
DLV-5521 2 SHP-CAV SHOP DROPPED stops.csv
DLV-5523 1 SHP-SUM SHOP PLANNED stops.csv
DLV-5523 2 SHP-HFX SHOP PLANNED stops.csv
DLV-5524 1 SHP-CHT SHOP PLANNED stops.csv
DLV-5524 2 WHL-0412 CUSTOMER PLANNED stops.csv
6 rows
Build the backing datasets
Raw tables mirror the source. Object types need one row per object, with clean names, typed columns and a stable key. A pipeline does that shaping: each step is one SQL query over its inputs, merged into its output by key, with checks that warn about, drop or fail on rows that break them. A build publishes every output or none of them. Name each column after the property it fills
# pipelines.yaml
pipelines:
- id: shops-and-runs
name: Shops and reefer runs
owner: Dispatch
steps:
- output: gold.shops
key: shopId
inputs: [raw.pos_locations]
sql: |
select store_code as shopId, store_name as name, town, province,
case season_type when 'SEASONAL' then 'Seasonal'
else 'Year-round' end as season,
case when location_status like 'CLOSED%' then 'Closed'
else 'Normal' end as status
from raw.pos_locations
checks:
- { primaryKey: [shopId] }
- { values: { season: [Year-round, Seasonal] } }
- output: gold.deliveries
key: deliveryId
inputs: [raw.tms_runs]
sql: |
select run_id as deliveryId, run_name as name,
cast(departure as timestamptz) as departs, cast(eta as timestamptz) as eta,
tubs, pallets, trailer_pallets as capacityPallets,
case upper(run_status) when 'LOADING' then 'Loading'
when 'IN_TRANSIT' then 'In transit' when 'DELIVERED' then 'Delivered'
when 'DELAYED' then 'Delayed' else 'Scheduled' end as status
from raw.tms_runs
checks:
- { primaryKey: [deliveryId] }
expectations:
- { name: Load fits the trailer, row: "pallets <= capacityPallets", onFail: warn }
- output: gold.delivery_stops
key: stopId
inputs: [raw.tms_stops]
sql: |
select concat(run_id, '/', stop_seq) as stopId, run_id as deliveryId,
stop_seq as sequence,
stop_code as shopId, cast(planned_arrival as timestamptz) as plannedArrival
from raw.tms_stops
where stop_kind = 'SHOP' and upper(stop_status) <> 'DROPPED'
checks:
- { primaryKey: [stopId] }
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
curl -X POST "$MSO_API_URL/api/v2/pipelines/shops-and-runs:run" \
-H "Authorization: Bearer $MSO_TOKEN"
{"build":{…,"pipeline_id":"shops-and-runs","status":"succeeded","steps":3,"rows_out":11,"rows_dropped":0,"warnings":0,…},…}The stop table has six rows and the dataset four: the stop dispatch dropped at the closed Cavendish shop and the stop at a wholesale customer are left out by the step's where
Model the object types
Now add the object types to ontology.yaml. A type's ID is its key under objectTypes and a property's ID its key under properties. backing names the dataset whose rows become its objects, values lists what a string may hold, and required means no action or sync may leave the property empty. conflictPolicy: preferEdit lets an action's edit stand over the source value until the source agrees
# ontology.yaml, continued
objectTypes:
shop:
name: Scoop shop
plural: Scoop shops
description: Scoop shops, from the point of sale's store list
key: shopId
title: "{name}"
backing: gold.shops
accessLabel: INTERNAL
properties:
shopId: { type: string, name: Shop }
name: { type: string, required: true }
town: { type: string }
province: { type: string, values: [PE, NS] }
season: { type: string, values: [Year-round, Seasonal] }
status: { type: string, name: Weekend status, values: [Normal, Watch, At risk, Closed] }
delivery:
name: Reefer delivery
plural: Reefer deliveries
description: Refrigerated truck runs from the creamery to the shops
key: deliveryId
title: "{name}"
backing: gold.deliveries
accessLabel: INTERNAL
conflictPolicy: preferEdit
properties:
deliveryId: { type: string, name: Delivery }
name: { type: string }
departs: { type: timestamp }
eta: { type: timestamp, name: ETA }
tubs: { type: integer }
pallets: { type: integer }
capacityPallets: { type: integer, unit: pallets, name: Trailer capacity }
status: { type: string, values: [Scheduled, Loading, In transit, Delayed, Delivered] }
delivery-stop:
name: Delivery stop
plural: Delivery stops
description: A shop on a reefer run
key: stopId
title: "{stopId}"
backing: gold.delivery_stops
accessLabel: INTERNAL
properties:
stopId: { type: string }
deliveryId: { type: string, required: true }
sequence: { type: integer }
shopId: { type: string, required: true }
plannedArrival: { type: timestamp }
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
curl -X POST "$MSO_API_URL/api/v2/refresh" \
-H "Authorization: Bearer $MSO_TOKEN"
{"builds":[{…,"pipeline_id":"shops-and-runs","status":"succeeded","steps_skipped":3,…}],"syncs":[{…,"object_type":"shop","status":"succeeded","rows_upserted":4,"rows_rejected":0,…}{…,"object_type":"delivery","status":"succeeded","rows_upserted":3,"rows_rejected":0,…}{…,"object_type":"delivery-stop","status":"succeeded","rows_upserted":4,"rows_rejected":0,…}]}A refresh builds every pipeline, skipping steps whose inputs and logic are unchanged, then syncs every object type from its dataset. A row with an empty key, a duplicate key or an empty required property is rejected and counted, and its object keeps its last good version. The objects are there to query
mso query delivery --select deliveryId,status,tubs,pallets,capacityPallets
_key _title deliveryId status tubs pallets capacityPallets
-------- ---------------------- ---------- ---------- ---- ------- ---------------
DLV-5521 Island east run DLV-5521 In transit 160 4 8
DLV-5523 Summerside and Halifax DLV-5523 Loading 200 5 8
DLV-5524 Charlottetown top-up DLV-5524 Scheduled 64 2 6
3 of 3 delivery
Link the types and add an action
A run stops at several shops and a shop receives several runs, so each stop is its own object, and two link types join it to its run and to its shop. A link runs from the type that holds the foreign key, named in via, to the type it points at. Name each end the way people talk about it from that end
# ontology.yaml, continued
linkTypes:
delivery-stop-delivery:
{ from: delivery-stop, to: delivery, via: deliveryId, name: Stop on, reverse: Stops }
delivery-stop-shop:
{ from: delivery-stop, to: shop, via: shopId, name: Delivers to shop, reverse: Deliveries }
Now the action. top-up-delivery adds tubs to a run that has not left and writes the new load to the dispatch system. Its conditions stop anyone adding tubs to a run that has already left, or going over the trailer's pallets. The pallets come from one function in functions.py, so the condition, the edit and the writeback count them the same way. Operands such as add and { parameter, property } read the run as it was before the action
# ontology.yaml, continued
actionTypes:
top-up-delivery:
name: Add tubs to delivery
objectType: delivery
description: Load extra tubs onto a run that has not left
allowedGroups: [dispatch, operations]
parameters:
delivery: { type: object, objectType: delivery, required: true }
tubs: { type: integer, required: true, min: 1, name: Extra tubs }
conditions:
- name: notLeft
message: "{{delivery.name}} has already left"
all:
- left: { parameter: delivery, property: status }
op: notIn
right: [In transit, Delivered]
- name: trailerRoom
message: "That would go over the {{delivery.capacityPallets}} pallets on the trailer"
all:
- left:
add:
- { parameter: delivery, property: pallets }
- { function: pallets_for, args: { tubs: { parameter: tubs } } }
op: lessThanOrEqual
right: { parameter: delivery, property: capacityPallets }
rules:
- modify:
object: { parameter: delivery }
set:
tubs: { add: [ { parameter: delivery, property: tubs }, { parameter: tubs } ] }
pallets:
add:
- { parameter: delivery, property: pallets }
- { function: pallets_for, args: { tubs: { parameter: tubs } } }
writeback:
- system: dispatch
operation: set-run-load
payload:
runId: { parameter: delivery }
tubs: { add: [ { parameter: delivery, property: tubs }, { parameter: tubs } ] }
pallets:
add:
- { parameter: delivery, property: pallets }
- { function: pallets_for, args: { tubs: { parameter: tubs } } }
notify:
- { group: dispatch, message: "{{tubs}} more tubs on {{delivery.name}}" }
# functions.py
import math
from mso.registry import function
@function(description='Pallets needed for a number of tubs, 40 tubs to a pallet',
inputs={'tubs': 'integer'}, output='integer')
def pallets_for(ctx, tubs):
return math.ceil(int(tubs) / 40)
The writeback names an operation in systems.yaml. This one updates the run in the dispatch system's run table, the raw table you loaded, which stands in for the system. An operation with kind: http calls a system's own API instead, as described in Writeback
# systems.yaml
systems:
dispatch:
name: Dispatch
operations:
set-run-load:
table: raw.tms_runs
key: { run_id: runId }
set: { tubs: tubs, pallets: pallets }
Reload, then follow the links: from the open shops, through their stops, to the runs that serve them
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
mso query shop --where '{"status": {"$ne": "Closed"}}' \
--follow delivery-stop-shop --follow delivery-stop-delivery \
--select name,status,pallets,capacityPallets
_key _title name status pallets capacityPallets
-------- ---------------------- ---------------------- ---------- ------- ---------------
DLV-5521 Island east run Island east run In transit 4 8
DLV-5523 Summerside and Halifax Summerside and Halifax Loading 5 8
DLV-5524 Charlottetown top-up Charlottetown top-up Scheduled 2 6
3 of 3 delivery
Check the action before you run it. A check evaluates the parameters and conditions against current data, as you, and commits nothing; a dry run also computes the edits. A failed check exits with code 5
mso actions check top-up-delivery delivery=DLV-5521 tubs:=12
mso actions check top-up-delivery delivery=DLV-5523 tubs:=160
mso actions run top-up-delivery delivery=DLV-5523 tubs:=12 --dry-run
top-up-delivery: INVALID
condition notLeft: Island east run has already left
top-up-delivery: INVALID
condition trailerRoom: That would go over the 8 pallets on the trailer
top-up-delivery: VALID (dry run, nothing committed)
modify delivery DLV-5523 tubs = 212, pallets = 6
Call the action from code
Generate typed code from the running service. Each generator writes only the types you can see and records the ontology revision it read, so regenerate when the ontology changes. Run the TypeScript one from the TypeScript client's folder
mso generate --out generated/creamery_ontology
npm run generate -- "$MSO_API_URL" --token "$MSO_TOKEN" > ontology-types.ts
Then find the runs still at the creamery that stop at an open shop, check the action on the first to leave and run it. Run one of the two scripts below; each applies the action once. In Python, with mso_client
# topup.py
import os
from mso_client import Client
from generated.creamery_ontology import Shop, Delivery, TOP_UP_DELIVERY
mso = Client(os.environ["MSO_API_URL"], token=os.environ["MSO_TOKEN"])
# Runs still at the creamery that stop at an open shop, first to leave first
runs = (mso.objects(Shop)
.where({"status": {"$ne": "Closed"}})
.follow("delivery-stop-shop")
.follow("delivery-stop-delivery", Delivery)
.where({"status": {"$in": ["Scheduled", "Loading"]}})
.order_by("departs")
.all())
target = runs[0]
print(target.deliveryId, target.name, target.pallets, "of", target.capacityPallets, "pallets")
# Check first: commits nothing
check = mso.actions(TOP_UP_DELIVERY).check({"delivery": target.deliveryId, "tubs": 12})
if check["result"] != "VALID":
raise SystemExit([c["message"] for c in check["conditions"] if c["result"] == "INVALID"])
result = mso.actions(TOP_UP_DELIVERY).run({"delivery": target.deliveryId, "tubs": 12},
include_edits=True)
print(result["logId"], result["writeback"], result["changes"][0]["changes"])
DLV-5523 Summerside and Halifax 5 of 8 pallets
alog_01M62AQGG7TZD7HCPK75J5YSKT [{'system': 'dispatch', 'status': 'delivered'}] {'tubs': {'before': 200, 'after': 212}, 'pallets': {'before': 5, 'after': 6}}
The same in TypeScript, with @marklandstreet/ontology-client. An object from a query can be passed as an object parameter
import { Client } from "@marklandstreet/ontology-client";
import { Shop, topUpDelivery, type Ontology } from "./ontology-types.ts";
const mso = new Client<Ontology>(process.env.MSO_API_URL!, { token: process.env.MSO_TOKEN });
// Runs still at the creamery that stop at an open shop, first to leave first
const runs = await mso.objects(Shop)
.where({ status: { $ne: "Closed" } })
.follow("delivery-stop-shop")
.follow("delivery-stop-delivery")
.where({ status: { $in: ["Scheduled", "Loading"] } })
.orderBy("departs")
.all();
const target = runs[0];
// Check first: commits nothing
const check = await mso.actions(topUpDelivery).check({ delivery: target, tubs: 12 });
if (check.result !== "VALID") {
const failed = check.conditions.filter((c) => c.result === "INVALID").map((c) => c.message);
throw new Error(failed.join("; "));
}
const applied = await mso.actions(topUpDelivery).run(
{ delivery: target, tubs: 12 },
{ includeEdits: true }
);
console.log(applied.logId, applied.writeback, applied.changes);
Or over HTTP, with the same access token
{
"parameters": { "delivery": "DLV-5523", "tubs": 12 },
"options": { "includeEdits": true }
}
The answer carries the action log ID, the writeback status for each system and, with includeEdits, each changed property before and after
Check the result
Every applied action leaves a record. Look at it on the object, in the action log, at the writeback target and in the dispatch group's inbox
mso get delivery DLV-5523
mso log --type delivery --limit 5
_key DLV-5523
_type delivery
_version 2
_updatedAt 2026-10-28T22:40:11.271428Z
_edited ["pallets", "tubs"]
_title Summerside and Halifax
deliveryId DLV-5523
name Summerside and Halifax
departs 2026-10-30T16:00:00Z
eta 2026-10-30T22:30:00Z
tubs 212
pallets 6
capacityPallets 8
status Loading
log when action object by reverts
------------------------------- --------------------------- --------------- ----------------- -------- -------
alog_01M62AQGG7TZD7HCPK75J5YSKT 2026-10-28T22:40:11.300659Z top-up-delivery delivery DLV-5523 ops.lead
_edited lists the properties an action changed on top of the source values. The writeback has already updated the run in the dispatch system's table
mso sql "select run_id, tubs, pallets from raw.tms_runs order by run_id"
run_id tubs pallets
-------- ---- -------
DLV-5521 160 4
DLV-5523 212 6
DLV-5524 64 2
3 rows
People in dispatch find the notification in their inbox with mso inbox; the person who ran the action is not notified of it
id when kind read message
------------------------------ --------------------------- ------ ----- --------------------------------------
ntf_01M62AQGHRB91HH6K42ENPRK4C 2026-10-28T22:40:11.320246Z action false 12 more tubs on Summerside and Halifax
1 unread
The next refresh reads the run back from the dispatch system with the same values, and the edit markers clear
curl -X POST "$MSO_API_URL/api/v2/refresh" \
-H "Authorization: Bearer $MSO_TOKEN"
mso get delivery DLV-5523
{…,"syncs":[…,{…,"object_type":"delivery","status":"succeeded","rows_upserted":1,"edits_cleared":2,…},…]}_edited []To take the action back, mso undo reverts the edits and undoes the writeback through the same outbox. Try it with --dry-run first
mso undo 5 --dry-run
mso undo 5 --reason "Quickstart clean-up"
alog_01M62AQGG7TZD7HCPK75J5YSKT: can be undone (dry run, nothing changed)
modify delivery DLV-5523 tubs = 200, pallets = 5
alog_01M62AQGG7TZD7HCPK75J5YSKT: REVERTED log alog_01M62AQKHYG5SGPMM7DMCJ1Z8H
Limitations
- The quickstart covers three uploaded files, three object types and one action. It sets no row policies or hidden properties, so everyone who holds
INTERNALsees every shop and run - It edits the ontology folder of a test service and reloads it. On a shared implementation, make the same changes through a change set, so they are checked, previewed and reviewed before they merge
- The writeback updates a raw table that stands in for the dispatch system. It is not transactional across the two: the edit commits first, and a write the system refuses becomes a dead letter for a person to resolve while the edit stays
- The uploaded files are a snapshot. Nothing changes until you upload a new file or a connector reads the source
- Generated code describes the ontology revision it was generated from. Types added later do not appear in it until you regenerate
Next steps
mso command
WritebackThe outbox, calls to real systems and undo