@mastra/mcp-docs-server 1.2.19-alpha.15 → 1.2.19-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/channels.md +27 -1
- package/.docs/docs/mastra-platform/api.md +54 -0
- package/.docs/docs/mastra-platform/observability.md +3 -1
- package/.docs/docs/memory/semantic-recall.md +19 -0
- package/.docs/docs/observability/feedback.md +14 -0
- package/.docs/docs/observability/metrics/overview.md +31 -44
- package/.docs/docs/server/middleware.md +26 -0
- package/.docs/docs/server/server-adapters.md +97 -26
- package/.docs/docs/subagents.md +6 -6
- package/.docs/integrations/channels/github.md +56 -9
- package/.docs/integrations/sandboxes/daytona.md +18 -0
- package/.docs/integrations/sandboxes/e2b.md +4 -0
- package/.docs/integrations/sandboxes/vercel.md +2 -2
- package/.docs/models/environment-variables.md +5 -0
- package/.docs/models/gateways/netlify.md +1 -1
- package/.docs/models/gateways/openrouter.md +2 -2
- package/.docs/models/gateways/vercel.md +5 -2
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/agnes.md +75 -0
- package/.docs/models/providers/cline-pass.md +4 -2
- package/.docs/models/providers/deepseek.md +4 -6
- package/.docs/models/providers/digitalocean.md +3 -3
- package/.docs/models/providers/edenai.md +5 -4
- package/.docs/models/providers/evroc.md +3 -2
- package/.docs/models/providers/hyper.md +3 -3
- package/.docs/models/providers/inceptron.md +1 -1
- package/.docs/models/providers/iteracompute.md +73 -0
- package/.docs/models/providers/kilo.md +13 -13
- package/.docs/models/providers/llmgateway-providers.md +4 -3
- package/.docs/models/providers/nano-gpt.md +11 -9
- package/.docs/models/providers/neosmith.md +104 -0
- package/.docs/models/providers/openai.md +2 -2
- package/.docs/models/providers/opencode-go.md +2 -2
- package/.docs/models/providers/pendra.md +78 -0
- package/.docs/models/providers/standardcompute.md +73 -0
- package/.docs/models/providers/vivgrid.md +2 -1
- package/.docs/models/providers/wandb.md +2 -1
- package/.docs/models/providers/zai.md +2 -1
- package/.docs/models/providers.md +5 -0
- package/.docs/reference/cli/mastra.md +10 -4
- package/.docs/reference/client-js/observability.md +1 -1
- package/.docs/reference/index.md +2 -0
- package/.docs/reference/observability/feedback.md +4 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +1 -1
- package/.docs/reference/observability/metrics/queries.md +462 -0
- package/.docs/reference/server/elysia-adapter.md +184 -0
- package/.docs/reference/workspace/local-sandbox.md +2 -0
- package/.docs/reference/workspace/platform-sandbox.md +3 -1
- package/.docs/reference/workspace/sandbox.md +70 -2
- package/CHANGELOG.md +14 -0
- package/package.json +5 -5
- package/.docs/docs/observability/metrics/querying.md +0 -314
|
@@ -15,6 +15,7 @@ Direct access to individual AI model providers. Each provider offers unique mode
|
|
|
15
15
|
- [Abacus](https://mastra.ai/models/providers/abacus)
|
|
16
16
|
- [abliteration.ai](https://mastra.ai/models/providers/abliteration-ai)
|
|
17
17
|
- [AgentRouter](https://mastra.ai/models/providers/agentrouter)
|
|
18
|
+
- [Agnes AI](https://mastra.ai/models/providers/agnes)
|
|
18
19
|
- [AI-ROUTER](https://mastra.ai/models/providers/ai-router)
|
|
19
20
|
- [ai&](https://mastra.ai/models/providers/aiand)
|
|
20
21
|
- [AKI.IO](https://mastra.ai/models/providers/aki-io)
|
|
@@ -78,6 +79,7 @@ Direct access to individual AI model providers. Each provider offers unique mode
|
|
|
78
79
|
- [InferX](https://mastra.ai/models/providers/inferx)
|
|
79
80
|
- [Infomaniak](https://mastra.ai/models/providers/infomaniak)
|
|
80
81
|
- [IO.NET](https://mastra.ai/models/providers/io-net)
|
|
82
|
+
- [IteraCompute](https://mastra.ai/models/providers/iteracompute)
|
|
81
83
|
- [Jalapeno Cloud](https://mastra.ai/models/providers/jalapeno)
|
|
82
84
|
- [Jiekou.AI](https://mastra.ai/models/providers/jiekou)
|
|
83
85
|
- [Kenari](https://mastra.ai/models/providers/kenari)
|
|
@@ -111,6 +113,7 @@ Direct access to individual AI model providers. Each provider offers unique mode
|
|
|
111
113
|
- [NanoGPT](https://mastra.ai/models/providers/nano-gpt)
|
|
112
114
|
- [NEAR AI Cloud](https://mastra.ai/models/providers/nearai)
|
|
113
115
|
- [Nebius Token Factory](https://mastra.ai/models/providers/nebius)
|
|
116
|
+
- [NeoSmith](https://mastra.ai/models/providers/neosmith)
|
|
114
117
|
- [Neuralwatt](https://mastra.ai/models/providers/neuralwatt)
|
|
115
118
|
- [Nova](https://mastra.ai/models/providers/nova)
|
|
116
119
|
- [NovitaAI](https://mastra.ai/models/providers/novita-ai)
|
|
@@ -122,6 +125,7 @@ Direct access to individual AI model providers. Each provider offers unique mode
|
|
|
122
125
|
- [Opper](https://mastra.ai/models/providers/opper)
|
|
123
126
|
- [OrcaRouter](https://mastra.ai/models/providers/orcarouter)
|
|
124
127
|
- [OVHcloud AI Endpoints](https://mastra.ai/models/providers/ovhcloud)
|
|
128
|
+
- [Pendra](https://mastra.ai/models/providers/pendra)
|
|
125
129
|
- [Perplexity](https://mastra.ai/models/providers/perplexity)
|
|
126
130
|
- [Perplexity Agent](https://mastra.ai/models/providers/perplexity-agent)
|
|
127
131
|
- [Pioneer](https://mastra.ai/models/providers/pioneer)
|
|
@@ -143,6 +147,7 @@ Direct access to individual AI model providers. Each provider offers unique mode
|
|
|
143
147
|
- [SiliconFlow (China)](https://mastra.ai/models/providers/siliconflow-cn)
|
|
144
148
|
- [Snowflake Cortex](https://mastra.ai/models/providers/snowflake-cortex)
|
|
145
149
|
- [STACKIT](https://mastra.ai/models/providers/stackit)
|
|
150
|
+
- [Standard Compute](https://mastra.ai/models/providers/standardcompute)
|
|
146
151
|
- [StepFun (China)](https://mastra.ai/models/providers/stepfun)
|
|
147
152
|
- [StepFun (Global)](https://mastra.ai/models/providers/stepfun-ai)
|
|
148
153
|
- [StepFun Step Plan (China)](https://mastra.ai/models/providers/stepfun-step-plan)
|
|
@@ -1100,9 +1100,9 @@ For runtime commands, the command resolves the target server in this order:
|
|
|
1100
1100
|
2. `http://localhost:4111` for a local `mastra dev` server.
|
|
1101
1101
|
3. `.mastra-project.json` for a Mastra platform project.
|
|
1102
1102
|
|
|
1103
|
-
Automatic
|
|
1103
|
+
Automatic Platform authentication is used when the CLI resolves a project from `.mastra-project.json` or recognizes an explicit Mastra-hosted Studio, Factory, or observability URL. Localhost and arbitrary explicit `--url` targets don't receive automatic credentials. Headers passed with `--header` are sent to any target, including localhost.
|
|
1104
1104
|
|
|
1105
|
-
For observability commands (`trace`, `log`, `score`, and `metric`), the CLI targets `https://observability.mastra.ai` by default instead of a project deployment URL. Trace Intelligence commands (`learning`) work the same way but target `https://output.signals.mastra.ai`.
|
|
1105
|
+
For observability commands (`trace`, `log`, `score`, and `metric`), the CLI targets the United States endpoint at `https://observability.mastra.ai` by default instead of a project deployment URL. Trace Intelligence commands (`learning`) work the same way but target `https://output.signals.mastra.ai`. When the CLI selects either hosted target automatically, it resolves credentials in this order:
|
|
1106
1106
|
|
|
1107
1107
|
1. Explicit `Authorization` and `X-Mastra-Project-Id` headers passed with `--header`.
|
|
1108
1108
|
2. `MASTRA_PLATFORM_ACCESS_TOKEN` and `MASTRA_PROJECT_ID` from your environment.
|
|
@@ -1111,7 +1111,13 @@ For observability commands (`trace`, `log`, `score`, and `metric`), the CLI targ
|
|
|
1111
1111
|
|
|
1112
1112
|
Learning commands also send `X-Mastra-Organization-Id`, resolved from an explicit `--header`, `MASTRA_ORGANIZATION_ID` in your environment, or `.mastra-project.json`, in that order.
|
|
1113
1113
|
|
|
1114
|
-
|
|
1114
|
+
European Union observability data is stored at `https://observability.eu.mastra.ai`. Pass that trusted host with `--url`; it uses the same Platform credential resolution as the default United States endpoint:
|
|
1115
|
+
|
|
1116
|
+
```bash
|
|
1117
|
+
mastra api --url https://observability.eu.mastra.ai trace list
|
|
1118
|
+
```
|
|
1119
|
+
|
|
1120
|
+
Use `--url` and `--header` when you need to override another target or its credentials.
|
|
1115
1121
|
|
|
1116
1122
|
### Flags
|
|
1117
1123
|
|
|
@@ -1527,7 +1533,7 @@ mastra api metric label-values '{"metricName":"latency_ms","labelKey":"model","p
|
|
|
1527
1533
|
|
|
1528
1534
|
#### Observability with `curl`
|
|
1529
1535
|
|
|
1530
|
-
You can call the hosted observability API directly with your platform access token and project ID:
|
|
1536
|
+
You can call the hosted observability API directly with your platform access token and project ID. The examples below use the United States host. Substitute `https://observability.eu.mastra.ai` for a European Union environment. The [hosted feedback query API](https://mastra.ai/docs/mastra-platform/api) documents feedback endpoints that don't have CLI commands:
|
|
1531
1537
|
|
|
1532
1538
|
```bash
|
|
1533
1539
|
curl -sS "https://observability.mastra.ai/api/observability/traces?page=0&perPage=20" \
|
|
@@ -92,7 +92,7 @@ const scores = await mastraClient.listScoresBySpan({
|
|
|
92
92
|
|
|
93
93
|
## Feedback
|
|
94
94
|
|
|
95
|
-
Feedback methods create, list, and query human-in-the-loop signals such as ratings, thumbs, comments, and corrections. See the [feedback guide](https://mastra.ai/docs/observability/feedback) for examples and the [feedback reference](https://mastra.ai/reference/observability/feedback) for full schemas.
|
|
95
|
+
Feedback methods create, list, and query human-in-the-loop signals such as ratings, thumbs, comments, and corrections through the target Mastra runtime and its configured observability storage. They don't call the hosted Mastra Platform feedback query API. See the [feedback guide](https://mastra.ai/docs/observability/feedback) for examples and the [feedback reference](https://mastra.ai/reference/observability/feedback) for full schemas.
|
|
96
96
|
|
|
97
97
|
### Creating feedback
|
|
98
98
|
|
package/.docs/reference/index.md
CHANGED
|
@@ -245,6 +245,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
245
245
|
- [Feedback](https://mastra.ai/reference/observability/feedback)
|
|
246
246
|
- [PinoLogger](https://mastra.ai/reference/logging/pino-logger)
|
|
247
247
|
- [Automatic Metrics](https://mastra.ai/reference/observability/metrics/automatic-metrics)
|
|
248
|
+
- [Metric queries](https://mastra.ai/reference/observability/metrics/queries)
|
|
248
249
|
- [Configuration](https://mastra.ai/reference/observability/tracing/configuration)
|
|
249
250
|
- [Instances](https://mastra.ai/reference/observability/tracing/instances)
|
|
250
251
|
- [Interfaces](https://mastra.ai/reference/observability/tracing/interfaces)
|
|
@@ -295,6 +296,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
295
296
|
- [.chunk()](https://mastra.ai/reference/rag/chunk)
|
|
296
297
|
- [Overview](https://mastra.ai/reference/schedules/overview)
|
|
297
298
|
- [createRoute()](https://mastra.ai/reference/server/create-route)
|
|
299
|
+
- [Elysia Adapter](https://mastra.ai/reference/server/elysia-adapter)
|
|
298
300
|
- [Express Adapter](https://mastra.ai/reference/server/express-adapter)
|
|
299
301
|
- [Fastify Adapter](https://mastra.ai/reference/server/fastify-adapter)
|
|
300
302
|
- [Hono Adapter](https://mastra.ai/reference/server/hono-adapter)
|
|
@@ -54,6 +54,8 @@ await mastra.observability.addFeedback?.({
|
|
|
54
54
|
|
|
55
55
|
**feedback** (`FeedbackInput`): Feedback payload to add.
|
|
56
56
|
|
|
57
|
+
Without `correlationContext`, the method looks up `traceId` in configured observability storage. If the trace or requested span isn't found, Mastra logs a warning and drops the feedback event. Configure `MastraStorageExporter` when adding feedback by ID after execution, including when `MastraPlatformExporter` handles remote export.
|
|
58
|
+
|
|
57
59
|
### `createFeedback(args)`
|
|
58
60
|
|
|
59
61
|
Creates one feedback record through the observability storage domain. Storage-level calls write directly to the store, so include `timestamp`.
|
|
@@ -375,6 +377,8 @@ Use `FeedbackFilter` in `listFeedback()` and OLAP query `filters`.
|
|
|
375
377
|
|
|
376
378
|
## HTTP routes
|
|
377
379
|
|
|
380
|
+
These routes belong to a Mastra runtime and use its configured observability storage. They're separate from the [unversioned Mastra Platform feedback query API](https://mastra.ai/docs/mastra-platform/api), which doesn't provide a feedback creation route.
|
|
381
|
+
|
|
378
382
|
| Method | Path | Purpose | Permission |
|
|
379
383
|
| ------ | ----------------------------------------- | ---------------------------- | -------------------- |
|
|
380
384
|
| `GET` | `/api/observability/feedback` | List feedback records | None derived |
|
|
@@ -136,5 +136,5 @@ When you spot a spike in latency or token usage on the Metrics dashboard, correl
|
|
|
136
136
|
## Related
|
|
137
137
|
|
|
138
138
|
- [Metrics overview](https://mastra.ai/docs/observability/metrics/overview)
|
|
139
|
-
- [
|
|
139
|
+
- [Metric queries](https://mastra.ai/reference/observability/metrics/queries)
|
|
140
140
|
- [Studio observability](https://mastra.ai/docs/studio/observability)
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Metric queries
|
|
4
|
+
|
|
5
|
+
Metric queries read raw and aggregated metric data from the observability storage domain. For exporter and storage setup, see the [Metrics overview](https://mastra.ai/docs/observability/metrics/overview). For automatic metric names and labels, see the [Automatic metrics reference](https://mastra.ai/reference/observability/metrics/automatic-metrics).
|
|
6
|
+
|
|
7
|
+
## Access
|
|
8
|
+
|
|
9
|
+
### Observability store
|
|
10
|
+
|
|
11
|
+
Use the storage domain for in-process queries:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const observability = await mastra.getStorage()?.getStore('observability')
|
|
15
|
+
|
|
16
|
+
if (!observability) {
|
|
17
|
+
throw new Error('Observability storage is not configured')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result = await observability.getMetricAggregate({
|
|
21
|
+
name: ['mastra_agent_duration_ms'],
|
|
22
|
+
aggregation: 'avg',
|
|
23
|
+
filters: {
|
|
24
|
+
timestamp: { start: new Date(Date.now() - 60 * 60 * 1000) },
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`getStore('observability')` returns `undefined` when the storage configuration doesn't provide the observability domain.
|
|
30
|
+
|
|
31
|
+
### Client SDK
|
|
32
|
+
|
|
33
|
+
`@mastra/client-js` exposes the analytics and metric discovery methods on `MastraClient`:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { MastraClient } from '@mastra/client-js'
|
|
37
|
+
|
|
38
|
+
const client = new MastraClient({
|
|
39
|
+
baseUrl: 'http://localhost:4111',
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const result = await client.getMetricAggregate({
|
|
43
|
+
name: ['mastra_agent_duration_ms'],
|
|
44
|
+
aggregation: 'avg',
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The client doesn't expose a raw `listMetrics()` method. Use the observability store or the `GET /api/observability/metrics` route to list raw metric records.
|
|
49
|
+
|
|
50
|
+
## Shared values
|
|
51
|
+
|
|
52
|
+
### Aggregations
|
|
53
|
+
|
|
54
|
+
The aggregate, breakdown, and time-series methods accept these `aggregation` values:
|
|
55
|
+
|
|
56
|
+
| Value | Result |
|
|
57
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------- |
|
|
58
|
+
| `sum` | Sum of metric values |
|
|
59
|
+
| `avg` | Average metric value |
|
|
60
|
+
| `min` | Minimum metric value |
|
|
61
|
+
| `max` | Maximum metric value |
|
|
62
|
+
| `count` | Number of matching metric records |
|
|
63
|
+
| `count_distinct` | Approximate or exact number of distinct values in `distinctColumn`, depending on the storage backend |
|
|
64
|
+
| `last` | Most recent matching metric value |
|
|
65
|
+
|
|
66
|
+
When `aggregation` is `count_distinct`, `distinctColumn` is required. Supported columns are:
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
entityType
|
|
70
|
+
entityName
|
|
71
|
+
parentEntityType
|
|
72
|
+
parentEntityName
|
|
73
|
+
rootEntityType
|
|
74
|
+
rootEntityName
|
|
75
|
+
name
|
|
76
|
+
provider
|
|
77
|
+
model
|
|
78
|
+
environment
|
|
79
|
+
executionSource
|
|
80
|
+
serviceName
|
|
81
|
+
threadId
|
|
82
|
+
resourceId
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Intervals
|
|
86
|
+
|
|
87
|
+
Time-series and percentile queries accept `1m`, `5m`, `15m`, `1h`, or `1d`.
|
|
88
|
+
|
|
89
|
+
### Filters
|
|
90
|
+
|
|
91
|
+
All metric operations accept the same optional `filters` object. Raw list requests pass these fields as query parameters. Analytics methods pass them in the JSON request body.
|
|
92
|
+
|
|
93
|
+
| Field | Type | Description |
|
|
94
|
+
| ----------------------- | -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
95
|
+
| `timestamp` | `{ start?: Date; end?: Date; startExclusive?: boolean; endExclusive?: boolean }` | Timestamp range. Boundaries are inclusive unless their corresponding exclusive flag is `true`. HTTP requests use ISO date strings. |
|
|
96
|
+
| `traceId` | `string` | Exact trace ID |
|
|
97
|
+
| `traceIds` | `string[]` | One to 1,000 trace IDs |
|
|
98
|
+
| `spanId` | `string` | Exact span ID |
|
|
99
|
+
| `entityType` | `EntityType` | Entity type |
|
|
100
|
+
| `entityName` | `string` | Entity name |
|
|
101
|
+
| `entityVersionId` | `string` | Entity version ID |
|
|
102
|
+
| `parentEntityType` | `EntityType` | Parent entity type |
|
|
103
|
+
| `parentEntityName` | `string` | Parent entity name |
|
|
104
|
+
| `parentEntityVersionId` | `string` | Parent entity version ID |
|
|
105
|
+
| `rootEntityType` | `EntityType` | Root entity type |
|
|
106
|
+
| `rootEntityName` | `string` | Root entity name |
|
|
107
|
+
| `rootEntityVersionId` | `string` | Root entity version ID |
|
|
108
|
+
| `userId` | `string` | User ID |
|
|
109
|
+
| `organizationId` | `string` | Organization ID |
|
|
110
|
+
| `experimentId` | `string` | Experiment or evaluation run ID |
|
|
111
|
+
| `serviceName` | `string` | Service name |
|
|
112
|
+
| `environment` | `string` | Environment name |
|
|
113
|
+
| `resourceId` | `string` | Resource ID |
|
|
114
|
+
| `runId` | `string` | Run ID |
|
|
115
|
+
| `sessionId` | `string` | Session ID |
|
|
116
|
+
| `threadId` | `string` | Thread ID |
|
|
117
|
+
| `requestId` | `string` | Request ID |
|
|
118
|
+
| `executionSource` | `string` | Execution source |
|
|
119
|
+
| `tags` | `string[]` | Records must contain all specified tags |
|
|
120
|
+
| `name` | `string[]` | One or more metric names |
|
|
121
|
+
| `provider` | `string` | Model provider |
|
|
122
|
+
| `model` | `string` | Model ID |
|
|
123
|
+
| `costUnit` | `string` | Cost unit |
|
|
124
|
+
| `labels` | `Record<string, string>` | Exact matches for all specified metric label key-value pairs |
|
|
125
|
+
| `source` | `string` | Deprecated. Use `executionSource`. |
|
|
126
|
+
|
|
127
|
+
## Analytics methods
|
|
128
|
+
|
|
129
|
+
### `getMetricAggregate(args)`
|
|
130
|
+
|
|
131
|
+
Returns one value across all matching records. The observability store and `MastraClient` expose this method.
|
|
132
|
+
|
|
133
|
+
#### Arguments
|
|
134
|
+
|
|
135
|
+
| Field | Type | Required | Description |
|
|
136
|
+
| ---------------- | -------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------ |
|
|
137
|
+
| `name` | `string[]` | Yes | One or more metric names |
|
|
138
|
+
| `aggregation` | `AggregationType` | Yes | Aggregation to apply |
|
|
139
|
+
| `distinctColumn` | `MetricDistinctColumn` | For `count_distinct` | Column whose distinct values are counted |
|
|
140
|
+
| `filters` | `MetricsFilter` | No | Shared metric filters |
|
|
141
|
+
| `comparePeriod` | `'previous_period' \| 'previous_day' \| 'previous_week'` | No | Adds comparison-period values. `previous_period` uses the duration of `filters.timestamp`. |
|
|
142
|
+
|
|
143
|
+
#### Returns
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
{
|
|
147
|
+
value: number | null
|
|
148
|
+
previousValue?: number | null
|
|
149
|
+
changePercent?: number | null
|
|
150
|
+
estimatedCost?: number | null
|
|
151
|
+
costUnit?: string | null
|
|
152
|
+
previousEstimatedCost?: number | null
|
|
153
|
+
costChangePercent?: number | null
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`costUnit` is `null` when the matching records don't have one shared unit. Cost fields are optional and may be `null` when the records don't include cost context.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const result = await observability.getMetricAggregate({
|
|
161
|
+
name: ['mastra_model_total_input_tokens', 'mastra_model_total_output_tokens'],
|
|
162
|
+
aggregation: 'sum',
|
|
163
|
+
filters: {
|
|
164
|
+
timestamp: {
|
|
165
|
+
start: new Date('2026-08-24T00:00:00Z'),
|
|
166
|
+
end: new Date('2026-08-25T00:00:00Z'),
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
comparePeriod: 'previous_period',
|
|
170
|
+
})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**HTTP:** `POST /api/observability/metrics/aggregate`
|
|
174
|
+
|
|
175
|
+
### `getMetricBreakdown(args)`
|
|
176
|
+
|
|
177
|
+
Groups matching records by one or more dimensions and aggregates each group. The observability store and `MastraClient` expose this method.
|
|
178
|
+
|
|
179
|
+
#### Arguments
|
|
180
|
+
|
|
181
|
+
| Field | Type | Required | Description |
|
|
182
|
+
| ---------------- | ---------------------- | -------------------- | ----------------------------------------------------------------------------------- |
|
|
183
|
+
| `name` | `string[]` | Yes | One or more metric names |
|
|
184
|
+
| `groupBy` | `string[]` | Yes | One or more fields to group by |
|
|
185
|
+
| `aggregation` | `AggregationType` | Yes | Aggregation for each group |
|
|
186
|
+
| `distinctColumn` | `MetricDistinctColumn` | For `count_distinct` | Column whose distinct values are counted |
|
|
187
|
+
| `filters` | `MetricsFilter` | No | Shared metric filters |
|
|
188
|
+
| `limit` | `number` | No | Positive integer up to 1,000. Required for high-cardinality groupings. |
|
|
189
|
+
| `orderDirection` | `'ASC' \| 'DESC'` | No | Sort direction for the aggregated value. Storage implementations default to `DESC`. |
|
|
190
|
+
|
|
191
|
+
#### Returns
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
{
|
|
195
|
+
groups: Array<{
|
|
196
|
+
dimensions: Record<string, string | null>
|
|
197
|
+
value: number
|
|
198
|
+
estimatedCost?: number | null
|
|
199
|
+
costUnit?: string | null
|
|
200
|
+
}>
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const result = await client.getMetricBreakdown({
|
|
206
|
+
name: ['mastra_model_total_input_tokens'],
|
|
207
|
+
groupBy: ['entityName'],
|
|
208
|
+
aggregation: 'sum',
|
|
209
|
+
limit: 10,
|
|
210
|
+
orderDirection: 'DESC',
|
|
211
|
+
})
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**HTTP:** `POST /api/observability/metrics/breakdown`
|
|
215
|
+
|
|
216
|
+
### `getMetricTimeSeries(args)`
|
|
217
|
+
|
|
218
|
+
Buckets matching values by time interval, with optional grouping. The observability store and `MastraClient` expose this method.
|
|
219
|
+
|
|
220
|
+
#### Arguments
|
|
221
|
+
|
|
222
|
+
| Field | Type | Required | Description |
|
|
223
|
+
| ---------------- | ---------------------- | -------------------- | ------------------------------------------- |
|
|
224
|
+
| `name` | `string[]` | Yes | One or more metric names |
|
|
225
|
+
| `interval` | `AggregationInterval` | Yes | Time bucket interval |
|
|
226
|
+
| `aggregation` | `AggregationType` | Yes | Aggregation for each bucket |
|
|
227
|
+
| `distinctColumn` | `MetricDistinctColumn` | For `count_distinct` | Column whose distinct values are counted |
|
|
228
|
+
| `filters` | `MetricsFilter` | No | Shared metric filters |
|
|
229
|
+
| `groupBy` | `string[]` | No | Fields used to split the result into series |
|
|
230
|
+
|
|
231
|
+
#### Returns
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
{
|
|
235
|
+
series: Array<{
|
|
236
|
+
name: string
|
|
237
|
+
costUnit?: string | null
|
|
238
|
+
points: Array<{
|
|
239
|
+
timestamp: Date
|
|
240
|
+
value: number
|
|
241
|
+
estimatedCost?: number | null
|
|
242
|
+
}>
|
|
243
|
+
}>
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
const result = await client.getMetricTimeSeries({
|
|
249
|
+
name: ['mastra_model_total_input_tokens'],
|
|
250
|
+
interval: '1h',
|
|
251
|
+
aggregation: 'sum',
|
|
252
|
+
filters: {
|
|
253
|
+
timestamp: { start: new Date(Date.now() - 24 * 60 * 60 * 1000) },
|
|
254
|
+
},
|
|
255
|
+
})
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**HTTP:** `POST /api/observability/metrics/timeseries`
|
|
259
|
+
|
|
260
|
+
### `getMetricPercentiles(args)`
|
|
261
|
+
|
|
262
|
+
Calculates percentile values in time buckets. The observability store and `MastraClient` expose this method.
|
|
263
|
+
|
|
264
|
+
#### Arguments
|
|
265
|
+
|
|
266
|
+
| Field | Type | Required | Description |
|
|
267
|
+
| ------------- | --------------------- | -------- | --------------------------------------- |
|
|
268
|
+
| `name` | `string` | Yes | One metric name |
|
|
269
|
+
| `percentiles` | `number[]` | Yes | One or more values from `0` through `1` |
|
|
270
|
+
| `interval` | `AggregationInterval` | Yes | Time bucket interval |
|
|
271
|
+
| `filters` | `MetricsFilter` | No | Shared metric filters |
|
|
272
|
+
|
|
273
|
+
#### Returns
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
{
|
|
277
|
+
series: Array<{
|
|
278
|
+
percentile: number
|
|
279
|
+
points: Array<{
|
|
280
|
+
timestamp: Date
|
|
281
|
+
value: number
|
|
282
|
+
}>
|
|
283
|
+
}>
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
const result = await client.getMetricPercentiles({
|
|
289
|
+
name: 'mastra_agent_duration_ms',
|
|
290
|
+
percentiles: [0.5, 0.95, 0.99],
|
|
291
|
+
interval: '1h',
|
|
292
|
+
})
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**HTTP:** `POST /api/observability/metrics/percentiles`
|
|
296
|
+
|
|
297
|
+
## Raw metric records
|
|
298
|
+
|
|
299
|
+
### `listMetrics(args)`
|
|
300
|
+
|
|
301
|
+
Returns stored metric observations without aggregating them. This method is available on the observability store. The HTTP route accepts the same fields as query parameters.
|
|
302
|
+
|
|
303
|
+
#### Arguments
|
|
304
|
+
|
|
305
|
+
Page mode is the default:
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
{
|
|
309
|
+
mode?: 'page'
|
|
310
|
+
filters?: MetricsFilter
|
|
311
|
+
pagination?: {
|
|
312
|
+
page?: number // Default: 0
|
|
313
|
+
perPage?: number // Default: 10; maximum: 100
|
|
314
|
+
}
|
|
315
|
+
orderBy?: {
|
|
316
|
+
field?: 'timestamp' // Default: 'timestamp'
|
|
317
|
+
direction?: 'ASC' | 'DESC' // Default: 'DESC'
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Delta mode supports incremental polling:
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
{
|
|
326
|
+
mode: 'delta'
|
|
327
|
+
filters?: MetricsFilter
|
|
328
|
+
after?: string
|
|
329
|
+
limit?: number // Default: 10; maximum: 100
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
`pagination` and `orderBy` aren't allowed in delta mode. `after` and `limit` aren't allowed in page mode. A backend that doesn't support delta polling returns an unsupported-operation error.
|
|
334
|
+
|
|
335
|
+
#### Returns
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
{
|
|
339
|
+
metrics: MetricRecord[]
|
|
340
|
+
pagination?: {
|
|
341
|
+
total: number
|
|
342
|
+
page: number
|
|
343
|
+
perPage: number | false
|
|
344
|
+
hasMore: boolean
|
|
345
|
+
}
|
|
346
|
+
delta?: {
|
|
347
|
+
limit: number
|
|
348
|
+
hasMore: boolean
|
|
349
|
+
}
|
|
350
|
+
deltaCursor?: string
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
A `MetricRecord` has this shape:
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
{
|
|
358
|
+
metricId?: string | null
|
|
359
|
+
timestamp: Date
|
|
360
|
+
name: string
|
|
361
|
+
value: number
|
|
362
|
+
traceId?: string | null
|
|
363
|
+
spanId?: string | null
|
|
364
|
+
entityType?: EntityType | null
|
|
365
|
+
entityId?: string | null
|
|
366
|
+
entityName?: string | null
|
|
367
|
+
parentEntityType?: EntityType | null
|
|
368
|
+
parentEntityId?: string | null
|
|
369
|
+
parentEntityName?: string | null
|
|
370
|
+
rootEntityType?: EntityType | null
|
|
371
|
+
rootEntityId?: string | null
|
|
372
|
+
rootEntityName?: string | null
|
|
373
|
+
userId?: string | null
|
|
374
|
+
organizationId?: string | null
|
|
375
|
+
resourceId?: string | null
|
|
376
|
+
runId?: string | null
|
|
377
|
+
sessionId?: string | null
|
|
378
|
+
threadId?: string | null
|
|
379
|
+
requestId?: string | null
|
|
380
|
+
environment?: string | null
|
|
381
|
+
serviceName?: string | null
|
|
382
|
+
scope?: Record<string, unknown> | null
|
|
383
|
+
entityVersionId?: string | null
|
|
384
|
+
parentEntityVersionId?: string | null
|
|
385
|
+
rootEntityVersionId?: string | null
|
|
386
|
+
experimentId?: string | null
|
|
387
|
+
executionSource?: string | null
|
|
388
|
+
tags?: string[] | null
|
|
389
|
+
source?: string | null // Deprecated
|
|
390
|
+
provider?: string | null
|
|
391
|
+
model?: string | null
|
|
392
|
+
estimatedCost?: number | null
|
|
393
|
+
costUnit?: string | null
|
|
394
|
+
costMetadata?: Record<string, unknown> | null
|
|
395
|
+
labels: Record<string, string>
|
|
396
|
+
metadata?: Record<string, unknown> | null
|
|
397
|
+
}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
**HTTP:** `GET /api/observability/metrics`
|
|
401
|
+
|
|
402
|
+
## Metric discovery
|
|
403
|
+
|
|
404
|
+
The observability store and `MastraClient` expose the metric discovery methods. HTTP requests pass arguments as query parameters.
|
|
405
|
+
|
|
406
|
+
| Method | Arguments | Returns | HTTP route |
|
|
407
|
+
| ---------------------------- | --------------------------------------------------------------------------- | ---------------------- | ------------------------------------------------------ |
|
|
408
|
+
| `getMetricNames(args?)` | `{ prefix?: string; limit?: number }` | `{ names: string[] }` | `GET /api/observability/discovery/metric-names` |
|
|
409
|
+
| `getMetricLabelKeys(args)` | `{ metricName: string }` | `{ keys: string[] }` | `GET /api/observability/discovery/metric-label-keys` |
|
|
410
|
+
| `getMetricLabelValues(args)` | `{ metricName: string; labelKey: string; prefix?: string; limit?: number }` | `{ values: string[] }` | `GET /api/observability/discovery/metric-label-values` |
|
|
411
|
+
|
|
412
|
+
`limit` must be a positive integer when provided.
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
const { names } = await client.getMetricNames({ prefix: 'mastra_model_' })
|
|
416
|
+
const { keys } = await client.getMetricLabelKeys({ metricName: names[0] })
|
|
417
|
+
const { values } = await client.getMetricLabelValues({
|
|
418
|
+
metricName: names[0],
|
|
419
|
+
labelKey: keys[0],
|
|
420
|
+
limit: 20,
|
|
421
|
+
})
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The observability discovery API also exposes shared dimensions used by traces, logs, and metrics:
|
|
425
|
+
|
|
426
|
+
| Store or client method | Arguments | HTTP route |
|
|
427
|
+
| ----------------------- | ----------------------------------------- | ------------------------------------------------ |
|
|
428
|
+
| `getEntityTypes()` | None in `MastraClient`; `{}` in the store | `GET /api/observability/discovery/entity-types` |
|
|
429
|
+
| `getEntityNames(args?)` | `{ entityType?: EntityType }` | `GET /api/observability/discovery/entity-names` |
|
|
430
|
+
| `getServiceNames()` | None in `MastraClient`; `{}` in the store | `GET /api/observability/discovery/service-names` |
|
|
431
|
+
| `getEnvironments()` | None in `MastraClient`; `{}` in the store | `GET /api/observability/discovery/environments` |
|
|
432
|
+
| `getTags(args?)` | `{ entityType?: EntityType }` | `GET /api/observability/discovery/tags` |
|
|
433
|
+
|
|
434
|
+
## HTTP routes
|
|
435
|
+
|
|
436
|
+
| Method | Route | Input |
|
|
437
|
+
| ------ | -------------------------------------------------- | ---------------- |
|
|
438
|
+
| `GET` | `/api/observability/metrics` | Query parameters |
|
|
439
|
+
| `POST` | `/api/observability/metrics/aggregate` | JSON body |
|
|
440
|
+
| `POST` | `/api/observability/metrics/breakdown` | JSON body |
|
|
441
|
+
| `POST` | `/api/observability/metrics/timeseries` | JSON body |
|
|
442
|
+
| `POST` | `/api/observability/metrics/percentiles` | JSON body |
|
|
443
|
+
| `GET` | `/api/observability/discovery/metric-names` | Query parameters |
|
|
444
|
+
| `GET` | `/api/observability/discovery/metric-label-keys` | Query parameters |
|
|
445
|
+
| `GET` | `/api/observability/discovery/metric-label-values` | Query parameters |
|
|
446
|
+
| `GET` | `/api/observability/discovery/entity-types` | None |
|
|
447
|
+
| `GET` | `/api/observability/discovery/entity-names` | Query parameters |
|
|
448
|
+
| `GET` | `/api/observability/discovery/service-names` | None |
|
|
449
|
+
| `GET` | `/api/observability/discovery/environments` | None |
|
|
450
|
+
| `GET` | `/api/observability/discovery/tags` | Query parameters |
|
|
451
|
+
|
|
452
|
+
All routes require a configured observability domain. The aggregate, breakdown, time-series, and percentile routes require the `observability:read` permission when runtime authorization is enabled.
|
|
453
|
+
|
|
454
|
+
## Unsupported backends
|
|
455
|
+
|
|
456
|
+
The base observability storage implementation throws `*_NOT_IMPLEMENTED` errors for raw listing, analytics, and discovery methods. A configured observability domain can therefore exist while its backend doesn't implement metric queries.
|
|
457
|
+
|
|
458
|
+
DuckDB, ClickHouse, Postgres v-next observability storage, and in-memory observability storage implement metric queries. Google Cloud Spanner implements them only when `disableMetrics` is `false`. Metrics are disabled by default. Other storage adapters may support tracing without supporting metrics.
|
|
459
|
+
|
|
460
|
+
## CLI
|
|
461
|
+
|
|
462
|
+
The `mastra api metric` commands cover aggregate, breakdown, time-series, percentile, metric-name, label-key, and label-value queries. See the [`mastra api metric` CLI reference](https://mastra.ai/reference/cli/mastra) for commands, targeting, authentication, and schema inspection.
|