Skip to content

Metric programs: define, query, watch

The Metric Verbs define, query, watch as MCP do programs, with inputs, result, refusals and an example.

Reference for Metric, one group of Metric programs.

Metric.define

Define compiles a Metric’s query against the Startup’s Events and Entries and lists every Event it reads. Verb page.

Text
do: return await $.Metric.define(input)

Emits Metric.defined.

Inputs

InputTypeRequiredDescription
namestringrequiredThe Metric’s name.
querytextrequiredThe query, over Events and Entries.
unitstringrequiredWhat one unit of it is.

Returns

OutputTypeRequiredDescription
metricMetricrequiredThe defined Metric.

Refuses when

CheckErrorFixThen call
The key is valid, but its scopes do not allow this operation.forbiddenUse a key whose scopes cover the operation, or ask an owner of the namespace to grant them.None.

Example

JSON
{
  "name": "do",
  "arguments": {
    "code": "return await $.Metric.define({ name: 'Leaseline', query: 'Example query', unit: 'Example unit' })"
  }
}

Metric.query

Query reads Metrics or Events as a trend, funnel, retention curve, path or lifecycle, broken down by any property. Verb page.

Text
do: return await $.Metric.query(input)

Emits Metric.queried.

Inputs

InputTypeRequiredDescription
metricMetricThe Metric to read; omitted, the query names Events directly.
shapestringrequiredThe analysis to run.
breakdownstringThe property to split by, such as an Organization or a Motion.
windowstringThe time range, such as 30d.

Returns

OutputTypeRequiredDescription
rowsjsonrequiredThe result rows, each number with its readability.
metricMetricrequiredThe Metric read.

Refuses when

CheckErrorFixThen call
The key is valid, but its scopes do not allow this operation.forbiddenUse a key whose scopes cover the operation, or ask an owner of the namespace to grant them.None.

Example

JSON
{
  "name": "do",
  "arguments": {
    "code": "return await $.Metric.query({ shape: 'trend' })"
  }
}

Metric.watch

Watch alerts the owner of a Metric when it crosses a threshold, by a Task or a Message. Verb page.

Text
do: return await $.Metric.watch(input)

Emits Metric.watched.

Inputs

InputTypeRequiredDescription
metricMetricrequiredThe Metric to watch.
thresholdnumberrequiredThe value that trips it.
directionstringrequiredTrip when the Metric goes above or below the threshold.

Returns

OutputTypeRequiredDescription
watchWatchrequiredThe Watch that checks it.
metricMetricrequiredThe Metric now watched.

Refuses when

CheckErrorFixThen call
The key is valid, but its scopes do not allow this operation.forbiddenUse a key whose scopes cover the operation, or ask an owner of the namespace to grant them.None.

Example

JSON
{
  "name": "do",
  "arguments": {
    "code": "return await $.Metric.watch({ metric: 'metric_GXFHAlK100', threshold: 1, direction: 'above' })"
  }
}