@mastra/mcp-docs-server 1.1.41 → 1.1.42-alpha.10

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.
Files changed (180) hide show
  1. package/.docs/docs/agent-builder/access-control.md +97 -0
  2. package/.docs/docs/agent-builder/browser.md +61 -0
  3. package/.docs/docs/agent-builder/channels.md +76 -0
  4. package/.docs/docs/agent-builder/configuration.md +147 -0
  5. package/.docs/docs/agent-builder/deploying.md +121 -0
  6. package/.docs/docs/agent-builder/memory.md +65 -0
  7. package/.docs/docs/agent-builder/model-policy.md +48 -0
  8. package/.docs/docs/agent-builder/overview.md +97 -0
  9. package/.docs/docs/agent-builder/skill-registries.md +31 -0
  10. package/.docs/docs/agent-builder/workspace.md +60 -0
  11. package/.docs/docs/agents/a2a.md +1 -1
  12. package/.docs/docs/agents/acp.md +4 -4
  13. package/.docs/docs/agents/adding-voice.md +37 -6
  14. package/.docs/docs/agents/agent-approval.md +15 -1
  15. package/.docs/docs/agents/background-tasks.md +2 -2
  16. package/.docs/docs/agents/channels.md +3 -1
  17. package/.docs/docs/agents/code-mode.md +163 -0
  18. package/.docs/docs/agents/guardrails.md +2 -2
  19. package/.docs/docs/agents/networks.md +1 -1
  20. package/.docs/docs/agents/overview.md +1 -1
  21. package/.docs/docs/agents/processors.md +3 -3
  22. package/.docs/docs/agents/response-caching.md +1 -1
  23. package/.docs/docs/agents/sdk-agents.md +261 -0
  24. package/.docs/docs/agents/signals.md +150 -73
  25. package/.docs/docs/agents/structured-output.md +5 -5
  26. package/.docs/docs/agents/supervisor-agents.md +2 -2
  27. package/.docs/docs/agents/using-tools.md +5 -5
  28. package/.docs/docs/browser/agent-browser.md +1 -1
  29. package/.docs/docs/browser/browser-viewer.md +1 -1
  30. package/.docs/docs/browser/overview.md +1 -1
  31. package/.docs/docs/browser/stagehand.md +5 -5
  32. package/.docs/docs/editor/overview.md +70 -8
  33. package/.docs/docs/evals/custom-scorers.md +1 -1
  34. package/.docs/docs/evals/datasets/running-experiments.md +1 -1
  35. package/.docs/docs/evals/overview.md +2 -2
  36. package/.docs/docs/getting-started/manual-install.md +1 -1
  37. package/.docs/docs/mcp/mcp-apps.md +3 -3
  38. package/.docs/docs/mcp/overview.md +1 -1
  39. package/.docs/docs/memory/memory-processors.md +6 -6
  40. package/.docs/docs/memory/multi-user-threads.md +1 -1
  41. package/.docs/docs/memory/observational-memory.md +19 -0
  42. package/.docs/docs/memory/semantic-recall.md +2 -2
  43. package/.docs/docs/memory/storage.md +2 -1
  44. package/.docs/docs/memory/working-memory.md +1 -1
  45. package/.docs/docs/observability/metrics/overview.md +1 -0
  46. package/.docs/docs/observability/metrics/querying.md +292 -0
  47. package/.docs/docs/observability/tracing/exporters/langfuse.md +1 -1
  48. package/.docs/docs/observability/tracing/exporters/langsmith.md +2 -2
  49. package/.docs/docs/rag/graph-rag.md +2 -2
  50. package/.docs/docs/rag/retrieval.md +12 -12
  51. package/.docs/docs/server/auth/fga.md +4 -0
  52. package/.docs/docs/server/mastra-client.md +1 -1
  53. package/.docs/docs/server/request-context.md +3 -3
  54. package/.docs/docs/streaming/overview.md +1 -1
  55. package/.docs/docs/streaming/tool-streaming.md +1 -1
  56. package/.docs/docs/voice/overview.md +86 -24
  57. package/.docs/docs/voice/speech-to-speech.md +55 -4
  58. package/.docs/docs/voice/speech-to-text.md +1 -1
  59. package/.docs/docs/voice/text-to-speech.md +1 -1
  60. package/.docs/docs/workspace/filesystem.md +2 -2
  61. package/.docs/docs/workspace/overview.md +1 -1
  62. package/.docs/docs/workspace/sandbox.md +5 -3
  63. package/.docs/guides/build-your-ui/ai-sdk-ui.md +1 -1
  64. package/.docs/guides/deployment/inngest.md +69 -0
  65. package/.docs/guides/guide/ai-recruiter.md +1 -1
  66. package/.docs/guides/guide/chef-michel.md +1 -1
  67. package/.docs/guides/guide/code-review-bot.md +1 -1
  68. package/.docs/guides/guide/dev-assistant.md +1 -1
  69. package/.docs/guides/guide/docs-manager.md +1 -1
  70. package/.docs/guides/guide/firecrawl.md +6 -6
  71. package/.docs/guides/guide/github-actions-pr-description.md +1 -1
  72. package/.docs/guides/guide/research-assistant.md +1 -1
  73. package/.docs/guides/guide/research-coordinator.md +2 -2
  74. package/.docs/guides/guide/slack-assistant.md +1 -1
  75. package/.docs/guides/guide/stock-agent.md +2 -2
  76. package/.docs/guides/guide/whatsapp-chat-bot.md +2 -2
  77. package/.docs/guides/migrations/agentnetwork.md +4 -4
  78. package/.docs/guides/migrations/upgrade-to-v1/agent.md +1 -1
  79. package/.docs/guides/migrations/vnext-to-standard-apis.md +2 -2
  80. package/.docs/models/embeddings.md +2 -2
  81. package/.docs/reference/agents/agent.md +60 -21
  82. package/.docs/reference/agents/channels.md +48 -6
  83. package/.docs/reference/agents/generateLegacy.md +1 -1
  84. package/.docs/reference/agents/getLLM.md +2 -2
  85. package/.docs/reference/agents/getMetadata.md +2 -2
  86. package/.docs/reference/agents/network.md +1 -1
  87. package/.docs/reference/browser/agent-browser.md +1 -1
  88. package/.docs/reference/browser/browser-viewer.md +1 -1
  89. package/.docs/reference/browser/mastra-browser.md +1 -1
  90. package/.docs/reference/browser/stagehand-browser.md +5 -5
  91. package/.docs/reference/client-js/agent-builder.md +161 -0
  92. package/.docs/reference/client-js/agents.md +19 -2
  93. package/.docs/reference/client-js/mastra-client.md +4 -0
  94. package/.docs/reference/configuration.md +1 -1
  95. package/.docs/reference/editor/agent-builder/agent-builder-options.md +74 -0
  96. package/.docs/reference/editor/agent-builder/builder-agent-defaults.md +77 -0
  97. package/.docs/reference/editor/agent-builder/builder-models.md +64 -0
  98. package/.docs/reference/editor/blob-store-provider.md +59 -0
  99. package/.docs/reference/editor/browser-provider.md +75 -0
  100. package/.docs/reference/editor/filesystem-provider.md +62 -0
  101. package/.docs/reference/editor/mastra-editor.md +61 -1
  102. package/.docs/reference/editor/processor-provider.md +64 -0
  103. package/.docs/reference/editor/sandbox-provider.md +61 -0
  104. package/.docs/reference/editor/storage-browser-ref.md +80 -0
  105. package/.docs/reference/editor/storage-workspace-ref.md +93 -0
  106. package/.docs/reference/evals/answer-relevancy.md +1 -1
  107. package/.docs/reference/evals/answer-similarity.md +1 -1
  108. package/.docs/reference/evals/bias.md +1 -1
  109. package/.docs/reference/evals/context-precision.md +3 -3
  110. package/.docs/reference/evals/context-relevance.md +11 -11
  111. package/.docs/reference/evals/create-scorer.md +2 -0
  112. package/.docs/reference/evals/faithfulness.md +1 -1
  113. package/.docs/reference/evals/hallucination.md +5 -5
  114. package/.docs/reference/evals/noise-sensitivity.md +11 -11
  115. package/.docs/reference/evals/prompt-alignment.md +15 -15
  116. package/.docs/reference/evals/tool-call-accuracy.md +3 -3
  117. package/.docs/reference/evals/toxicity.md +1 -1
  118. package/.docs/reference/index.md +15 -0
  119. package/.docs/reference/memory/memory-class.md +3 -3
  120. package/.docs/reference/memory/observational-memory.md +6 -4
  121. package/.docs/reference/memory/serialized-memory-config.md +72 -0
  122. package/.docs/reference/observability/metrics/automatic-metrics.md +7 -1
  123. package/.docs/reference/observability/tracing/exporters/langfuse.md +1 -1
  124. package/.docs/reference/processors/batch-parts-processor.md +1 -1
  125. package/.docs/reference/processors/cost-guard-processor.md +1 -1
  126. package/.docs/reference/processors/language-detector.md +1 -1
  127. package/.docs/reference/processors/message-history-processor.md +1 -1
  128. package/.docs/reference/processors/moderation-processor.md +2 -2
  129. package/.docs/reference/processors/pii-detector.md +2 -2
  130. package/.docs/reference/processors/prefill-error-handler.md +2 -2
  131. package/.docs/reference/processors/processor-interface.md +2 -2
  132. package/.docs/reference/processors/prompt-injection-detector.md +1 -1
  133. package/.docs/reference/processors/regex-filter-processor.md +1 -1
  134. package/.docs/reference/processors/semantic-recall-processor.md +1 -1
  135. package/.docs/reference/processors/skill-search-processor.md +1 -1
  136. package/.docs/reference/processors/system-prompt-scrubber.md +1 -1
  137. package/.docs/reference/processors/token-limiter-processor.md +3 -3
  138. package/.docs/reference/processors/tool-call-filter.md +2 -2
  139. package/.docs/reference/processors/tool-search-processor.md +33 -2
  140. package/.docs/reference/processors/unicode-normalizer.md +1 -1
  141. package/.docs/reference/processors/working-memory-processor.md +1 -1
  142. package/.docs/reference/rag/rerank.md +1 -1
  143. package/.docs/reference/server/nestjs-adapter.md +1 -1
  144. package/.docs/reference/server/routes.md +108 -9
  145. package/.docs/reference/storage/dsql.md +1 -1
  146. package/.docs/reference/storage/mongodb.md +1 -1
  147. package/.docs/reference/storage/postgresql.md +1 -1
  148. package/.docs/reference/storage/redis.md +1 -1
  149. package/.docs/reference/storage/spanner.md +5 -0
  150. package/.docs/reference/storage/upstash.md +1 -1
  151. package/.docs/reference/streaming/agents/stream.md +1 -1
  152. package/.docs/reference/templates/overview.md +3 -3
  153. package/.docs/reference/tools/mcp-client.md +53 -2
  154. package/.docs/reference/tools/mcp-server.md +33 -1
  155. package/.docs/reference/tools/vector-query-tool.md +1 -1
  156. package/.docs/reference/vectors/libsql.md +1 -1
  157. package/.docs/reference/vectors/mongodb.md +1 -1
  158. package/.docs/reference/vectors/pg.md +3 -1
  159. package/.docs/reference/vectors/upstash.md +1 -1
  160. package/.docs/reference/voice/google-gemini-live.md +15 -2
  161. package/.docs/reference/voice/inworld-realtime.md +353 -0
  162. package/.docs/reference/voice/inworld.md +2 -0
  163. package/.docs/reference/voice/voice.addInstructions.md +1 -1
  164. package/.docs/reference/workspace/agentcore-runtime-sandbox.md +202 -0
  165. package/.docs/reference/workspace/agentfs-filesystem.md +1 -1
  166. package/.docs/reference/workspace/azure-blob-filesystem.md +1 -1
  167. package/.docs/reference/workspace/blaxel-sandbox.md +3 -0
  168. package/.docs/reference/workspace/docker-sandbox.md +4 -2
  169. package/.docs/reference/workspace/e2b-sandbox.md +9 -5
  170. package/.docs/reference/workspace/files-sdk-filesystem.md +1 -1
  171. package/.docs/reference/workspace/gcs-filesystem.md +1 -1
  172. package/.docs/reference/workspace/google-drive-filesystem.md +1 -1
  173. package/.docs/reference/workspace/local-filesystem.md +1 -1
  174. package/.docs/reference/workspace/local-sandbox.md +1 -1
  175. package/.docs/reference/workspace/modal-sandbox.md +1 -1
  176. package/.docs/reference/workspace/s3-filesystem.md +1 -1
  177. package/.docs/reference/workspace/vercel-microvm-sandbox.md +199 -0
  178. package/.docs/reference/workspace/vercel.md +2 -0
  179. package/CHANGELOG.md +65 -0
  180. package/package.json +8 -6
@@ -0,0 +1,292 @@
1
+ # Querying metrics
2
+
3
+ Mastra exposes the same five OLAP queries (`getMetricAggregate`, `getMetricBreakdown`, `getMetricTimeSeries`, `getMetricPercentiles`, and discovery helpers) through three surfaces: an in-process store accessor, the runtime HTTP API, and the `mastra api metric` CLI. All three accept the same Zod-validated input shapes, so you can move from a one-off CLI investigation to a programmatic dashboard tool without re-learning the API.
4
+
5
+ ## When to use this
6
+
7
+ - Build a custom dashboard or KPI tile alongside Studio.
8
+ - Power a scheduled alert that fires when token cost or latency crosses a threshold.
9
+ - Give an agent a tool that reads its own performance metrics and explains them in chat.
10
+ - Run one-off investigations from a terminal with `mastra api metric ...`.
11
+
12
+ For setup of the observability store itself, see the [Metrics overview](https://mastra.ai/docs/observability/metrics/overview). For the list of metric names you can query, see the [Automatic metrics reference](https://mastra.ai/reference/observability/metrics/automatic-metrics).
13
+
14
+ > **Note:** Metric queries are served by the observability domain, which requires an OLAP-capable store (DuckDB locally, ClickHouse in production). See [Metrics overview](https://mastra.ai/docs/observability/metrics/overview) for setup. If the observability store is not configured, `getStore('observability')` returns `null`.
15
+
16
+ ## Surfaces
17
+
18
+ ### In-process
19
+
20
+ Inside a tool, server route, or workflow step, get the observability store from the Mastra storage:
21
+
22
+ ```typescript
23
+ import { createTool } from '@mastra/core/tools'
24
+ import { z } from 'zod'
25
+
26
+ export const agentLatencyTool = createTool({
27
+ id: 'agentLatency',
28
+ description: 'Average agent latency over the last hour.',
29
+ inputSchema: z.object({}),
30
+ execute: async (_input, context) => {
31
+ const observability = await context.mastra!.getStorage()!.getStore('observability')
32
+ if (!observability) {
33
+ throw new Error('Observability domain is not configured (requires DuckDB or ClickHouse)')
34
+ }
35
+
36
+ const result = await observability.getMetricAggregate({
37
+ name: ['mastra_agent_duration_ms'],
38
+ aggregation: 'avg',
39
+ filters: {
40
+ timestamp: { start: new Date(Date.now() - 60 * 60 * 1000) },
41
+ },
42
+ })
43
+
44
+ return { averageMs: result.value }
45
+ },
46
+ })
47
+ ```
48
+
49
+ `getStore('observability')` returns `null` when the configured backend does not support OLAP queries.
50
+
51
+ ### HTTP
52
+
53
+ The `mastra dev` server (and any deployed Mastra runtime) exposes the same queries under `/api/observability/metrics/*`. Aggregate, breakdown, time series, and percentile endpoints take a JSON body with `POST`. Discovery endpoints use `GET` with query parameters.
54
+
55
+ ```bash
56
+ curl -sS -X POST http://localhost:4111/api/observability/metrics/aggregate \
57
+ -H "content-type: application/json" \
58
+ -d '{"name":["mastra_agent_duration_ms"],"aggregation":"avg"}'
59
+ ```
60
+
61
+ Available routes:
62
+
63
+ - `POST /api/observability/metrics/aggregate`
64
+ - `POST /api/observability/metrics/breakdown`
65
+ - `POST /api/observability/metrics/timeseries`
66
+ - `POST /api/observability/metrics/percentiles`
67
+ - `GET /api/observability/metrics` (raw rows, paginated)
68
+ - `GET /api/observability/discovery/metric-names`
69
+ - `GET /api/observability/discovery/metric-label-keys`
70
+ - `GET /api/observability/discovery/metric-label-values`
71
+
72
+ The `@mastra/client-js` SDK wraps the same routes as `mastraClient.getMetricAggregate(...)`, `getMetricBreakdown(...)`, and so on.
73
+
74
+ ### CLI
75
+
76
+ `mastra api metric ...` calls the same endpoints with a single JSON argument, so an agent or shell script can fetch metrics without writing any code:
77
+
78
+ ```bash
79
+ mastra api metric aggregate \
80
+ '{"name":["mastra_agent_duration_ms"],"aggregation":"avg"}' \
81
+ --url http://localhost:4111 --pretty
82
+ ```
83
+
84
+ By default the CLI targets hosted Mastra observability (`https://observability.mastra.ai`). Pass `--url http://localhost:4111` to query a local `mastra dev` server. See [`mastra api metric aggregate`](https://mastra.ai/reference/cli/mastra) and the surrounding entries for the full command list.
85
+
86
+ ## Queries
87
+
88
+ ### `getMetricAggregate`
89
+
90
+ Returns a single scalar — the building block for KPI cards.
91
+
92
+ Inputs:
93
+
94
+ - `name`: Array of one or more metric names.
95
+ - `aggregation`: One of `'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'`.
96
+ - `filters`: Optional [filter object](#filtering).
97
+ - `comparePeriod`: Optional `'previous_period' | 'previous_day' | 'previous_week'` for period-over-period comparison.
98
+
99
+ Response:
100
+
101
+ - `value`, `previousValue`, `changePercent`.
102
+ - `estimatedCost`, `costUnit`, `previousEstimatedCost`, `costChangePercent` for token metrics.
103
+
104
+ ```typescript
105
+ const observability = await mastra.getStorage()!.getStore('observability')
106
+
107
+ const cost = await observability!.getMetricAggregate({
108
+ name: ['mastra_model_total_input_tokens', 'mastra_model_total_output_tokens'],
109
+ aggregation: 'sum',
110
+ comparePeriod: 'previous_day',
111
+ })
112
+
113
+ console.log(cost.value, cost.estimatedCost, cost.costUnit, cost.changePercent)
114
+ ```
115
+
116
+ ### `getMetricBreakdown`
117
+
118
+ Groups rows by one or more dimensions and aggregates each group — the building block for top-N tables (e.g. "tokens by agent").
119
+
120
+ Inputs:
121
+
122
+ - `name`: Array of metric names.
123
+ - `groupBy`: Array of fields to group by (for example `['entityName']`).
124
+ - `aggregation`: Same enum as above.
125
+ - `limit`: Server-side top-K cap. Required for high-cardinality `groupBy`.
126
+ - `orderDirection`: `'ASC' | 'DESC'` (defaults to `DESC`).
127
+ - `filters`: Optional.
128
+
129
+ Response: `groups[]`, each with `dimensions` (record of group keys to values), `value`, and `estimatedCost`.
130
+
131
+ ```typescript
132
+ const byAgent = await observability!.getMetricBreakdown({
133
+ name: ['mastra_model_total_input_tokens'],
134
+ groupBy: ['entityName'],
135
+ aggregation: 'sum',
136
+ limit: 10,
137
+ orderDirection: 'DESC',
138
+ })
139
+ ```
140
+
141
+ ### `getMetricTimeSeries`
142
+
143
+ Buckets values by a fixed interval — the building block for line and bar charts.
144
+
145
+ Inputs:
146
+
147
+ - `name`: Array of metric names.
148
+ - `interval`: One of `'1m' | '5m' | '15m' | '1h' | '1d'`.
149
+ - `aggregation`: Same enum.
150
+ - `groupBy`: Optional. When omitted, multiple metric names are summed into one series; use one call per metric to keep them separate.
151
+ - `filters`: Optional.
152
+
153
+ Response: `series[]`, each with `name`, `costUnit`, and `points[]` of `{ timestamp, value, estimatedCost }`.
154
+
155
+ ```typescript
156
+ const inputTokens = await observability!.getMetricTimeSeries({
157
+ name: ['mastra_model_total_input_tokens'],
158
+ aggregation: 'sum',
159
+ interval: '1h',
160
+ filters: {
161
+ timestamp: { start: new Date(Date.now() - 24 * 60 * 60 * 1000) },
162
+ },
163
+ })
164
+ ```
165
+
166
+ ### `getMetricPercentiles`
167
+
168
+ Returns percentile values bucketed by time — the building block for latency charts.
169
+
170
+ Inputs:
171
+
172
+ - `name`: Single metric name (string, not array).
173
+ - `percentiles`: Array of numbers between `0` and `1`, for example `[0.5, 0.95, 0.99]`.
174
+ - `interval`: Same enum as `getMetricTimeSeries`.
175
+ - `filters`: Optional.
176
+
177
+ Response: `series[]`, each with `percentile` and `points[]` of `{ timestamp, value }`.
178
+
179
+ ```typescript
180
+ const latency = await observability!.getMetricPercentiles({
181
+ name: 'mastra_agent_duration_ms',
182
+ percentiles: [0.5, 0.95],
183
+ interval: '1h',
184
+ })
185
+ ```
186
+
187
+ ### Discovery
188
+
189
+ Use these endpoints to populate dropdowns or to give an agent the menu of values it can filter by. All discovery routes are `GET` and live under `/api/observability/discovery/`.
190
+
191
+ **Metric-specific** (also exposed as `mastra api metric` subcommands):
192
+
193
+ | Method | Args | Path suffix | CLI |
194
+ | ---------------------- | ------------------------------------------- | --------------------- | -------------------------------- |
195
+ | `getMetricNames` | `{ prefix?, limit? }` | `metric-names` | `mastra api metric names` |
196
+ | `getMetricLabelKeys` | `{ metricName }` | `metric-label-keys` | `mastra api metric label-keys` |
197
+ | `getMetricLabelValues` | `{ metricName, labelKey, prefix?, limit? }` | `metric-label-values` | `mastra api metric label-values` |
198
+
199
+ **Shared with traces and logs** (HTTP-only, no dedicated CLI subcommand):
200
+
201
+ | Method | Args | Path suffix |
202
+ | ----------------- | ----------------- | --------------- |
203
+ | `getEntityTypes` | `{}` | `entity-types` |
204
+ | `getEntityNames` | `{ entityType? }` | `entity-names` |
205
+ | `getServiceNames` | `{}` | `service-names` |
206
+ | `getEnvironments` | `{}` | `environments` |
207
+ | `getTags` | `{ entityType? }` | `tags` |
208
+
209
+ ## Filtering
210
+
211
+ Every query accepts the same `filters` object. The most useful fields:
212
+
213
+ - `name`: Restrict to specific metric names. (Top-level `name` already does this for aggregate/breakdown/timeseries; use `filters.name` when you want to mix multiple metrics under a single query.)
214
+ - `timestamp`: `{ start, end, startExclusive, endExclusive }`. Both bounds are optional; omit `end` for "until now".
215
+ - `provider`, `model`, `costUnit`: For token and cost metrics.
216
+ - `labels`: Exact key-value match on metric labels, for example `{ status: 'error' }` for duration metrics.
217
+ - Correlation fields: `entityType`, `entityName`, `parentEntityName`, `rootEntityName`, `userId`, `organizationId`, `resourceId`, `runId`, `sessionId`, `threadId`, `requestId`, `executionSource`, `environment`, `serviceName`, `experimentId`, `tags`.
218
+
219
+ The same `filters` shape works across all three surfaces:
220
+
221
+ ```typescript
222
+ // In-process
223
+ await observability!.getMetricAggregate({
224
+ name: ['mastra_tool_duration_ms'],
225
+ aggregation: 'avg',
226
+ filters: { entityName: 'weatherTool', labels: { status: 'error' } },
227
+ })
228
+ ```
229
+
230
+ ```bash
231
+ # CLI
232
+ mastra api metric aggregate \
233
+ '{"name":["mastra_tool_duration_ms"],"aggregation":"avg","filters":{"entityName":"weatherTool","labels":{"status":"error"}}}' \
234
+ --url http://localhost:4111
235
+ ```
236
+
237
+ ```bash
238
+ # HTTP
239
+ curl -sS -X POST http://localhost:4111/api/observability/metrics/aggregate \
240
+ -H "content-type: application/json" \
241
+ -d '{"name":["mastra_tool_duration_ms"],"aggregation":"avg","filters":{"entityName":"weatherTool","labels":{"status":"error"}}}'
242
+ ```
243
+
244
+ ## Example: build a custom KPI tile
245
+
246
+ The following tool returns input-token volume and estimated cost for the last hour. An agent or a dashboard can call it as `structuredContent` without re-implementing the query.
247
+
248
+ ```typescript
249
+ import { createTool } from '@mastra/core/tools'
250
+ import { z } from 'zod'
251
+
252
+ export const tokenKpiTool = createTool({
253
+ id: 'tokenKpi',
254
+ description: 'Returns input-token volume and estimated cost for the last hour.',
255
+ inputSchema: z.object({}),
256
+ outputSchema: z.object({
257
+ inputTokens: z.number().nullable(),
258
+ estimatedCost: z.number().nullable(),
259
+ costUnit: z.string().nullable(),
260
+ changePercent: z.number().nullable(),
261
+ }),
262
+ execute: async (_input, context) => {
263
+ const observability = await context.mastra!.getStorage()!.getStore('observability')
264
+ if (!observability) {
265
+ throw new Error('Observability domain is not configured (requires DuckDB or ClickHouse)')
266
+ }
267
+
268
+ const result = await observability.getMetricAggregate({
269
+ name: ['mastra_model_total_input_tokens'],
270
+ aggregation: 'sum',
271
+ filters: {
272
+ timestamp: { start: new Date(Date.now() - 60 * 60 * 1000) },
273
+ },
274
+ comparePeriod: 'previous_period',
275
+ })
276
+
277
+ return {
278
+ inputTokens: result.value,
279
+ estimatedCost: result.estimatedCost ?? null,
280
+ costUnit: result.costUnit ?? null,
281
+ changePercent: result.changePercent ?? null,
282
+ }
283
+ },
284
+ })
285
+ ```
286
+
287
+ ## Related
288
+
289
+ - [Metrics overview](https://mastra.ai/docs/observability/metrics/overview)
290
+ - [Automatic metrics reference](https://mastra.ai/reference/observability/metrics/automatic-metrics)
291
+ - [CLI: `mastra api metric ...`](https://mastra.ai/reference/cli/mastra)
292
+ - [Studio observability](https://mastra.ai/docs/studio/observability)
@@ -214,7 +214,7 @@ const prompt = await exporter.client.prompt.get('customer-support', { type: 'tex
214
214
  export const supportAgent = new Agent({
215
215
  name: 'support-agent',
216
216
  instructions: prompt.compile(), // Use the prompt text from Langfuse
217
- model: 'openai/gpt-5.4',
217
+ model: 'openai/gpt-5.5',
218
218
  defaultGenerateOptions: {
219
219
  tracingOptions: buildTracingOptions(
220
220
  withLangfusePrompt({ name: prompt.name, version: prompt.version }),
@@ -143,7 +143,7 @@ export const supportAgent = new Agent({
143
143
  id: 'support-agent',
144
144
  name: 'support-agent',
145
145
  instructions: 'You are a helpful support agent.',
146
- model: 'openai/gpt-5.4',
146
+ model: 'openai/gpt-5.5',
147
147
  defaultOptions: {
148
148
  tracingOptions: buildTracingOptions(withLangsmithMetadata({ projectName: 'customer-support' })),
149
149
  },
@@ -163,7 +163,7 @@ export const supportAgent = new Agent({
163
163
  id: 'support-agent',
164
164
  name: 'support-agent',
165
165
  instructions: 'You are a helpful support agent.',
166
- model: 'openai/gpt-5.4',
166
+ model: 'openai/gpt-5.5',
167
167
  defaultOptions: ({ requestContext }) => {
168
168
  const userTier = requestContext?.get('user-tier') as string
169
169
  const userId = requestContext?.get('user-id') as string
@@ -75,7 +75,7 @@ const ragAgent = new Agent({
75
75
  instructions: `You are a helpful assistant that answers questions based on the provided context.
76
76
  When answering questions, use the graph query tool to find relevant information and relationships.
77
77
  Base your answers on the context provided by the tool, and clearly state if the context doesn't contain enough information.`,
78
- model: 'openai/gpt-5.4',
78
+ model: 'openai/gpt-5.5',
79
79
  tools: {
80
80
  graphQueryTool,
81
81
  },
@@ -197,7 +197,7 @@ const agent = new Agent({
197
197
  name: 'RAG Agent',
198
198
  instructions: `Use vector search for simple fact-finding queries.
199
199
  Use graph search when you need to understand relationships or find connected information.`,
200
- model: 'openai/gpt-5.4',
200
+ model: 'openai/gpt-5.5',
201
201
  tools: {
202
202
  vectorQueryTool,
203
203
  graphQueryTool,
@@ -272,7 +272,7 @@ import { PGVECTOR_PROMPT } from '@mastra/pg'
272
272
  export const ragAgent = new Agent({
273
273
  id: 'rag-agent',
274
274
  name: 'RAG Agent',
275
- model: 'openai/gpt-5.4',
275
+ model: 'openai/gpt-5.5',
276
276
  instructions: `
277
277
  Process queries using the provided context. Structure responses to be concise and relevant.
278
278
  ${PGVECTOR_PROMPT}
@@ -289,7 +289,7 @@ import { PINECONE_PROMPT } from '@mastra/pinecone'
289
289
  export const ragAgent = new Agent({
290
290
  id: 'rag-agent',
291
291
  name: 'RAG Agent',
292
- model: 'openai/gpt-5.4',
292
+ model: 'openai/gpt-5.5',
293
293
  instructions: `
294
294
  Process queries using the provided context. Structure responses to be concise and relevant.
295
295
  ${PINECONE_PROMPT}
@@ -306,7 +306,7 @@ import { QDRANT_PROMPT } from '@mastra/qdrant'
306
306
  export const ragAgent = new Agent({
307
307
  id: 'rag-agent',
308
308
  name: 'RAG Agent',
309
- model: 'openai/gpt-5.4',
309
+ model: 'openai/gpt-5.5',
310
310
  instructions: `
311
311
  Process queries using the provided context. Structure responses to be concise and relevant.
312
312
  ${QDRANT_PROMPT}
@@ -323,7 +323,7 @@ import { CHROMA_PROMPT } from '@mastra/chroma'
323
323
  export const ragAgent = new Agent({
324
324
  id: 'rag-agent',
325
325
  name: 'RAG Agent',
326
- model: 'openai/gpt-5.4',
326
+ model: 'openai/gpt-5.5',
327
327
  instructions: `
328
328
  Process queries using the provided context. Structure responses to be concise and relevant.
329
329
  ${CHROMA_PROMPT}
@@ -340,7 +340,7 @@ import { ASTRA_PROMPT } from '@mastra/astra'
340
340
  export const ragAgent = new Agent({
341
341
  id: 'rag-agent',
342
342
  name: 'RAG Agent',
343
- model: 'openai/gpt-5.4',
343
+ model: 'openai/gpt-5.5',
344
344
  instructions: `
345
345
  Process queries using the provided context. Structure responses to be concise and relevant.
346
346
  ${ASTRA_PROMPT}
@@ -357,7 +357,7 @@ import { LIBSQL_PROMPT } from '@mastra/libsql'
357
357
  export const ragAgent = new Agent({
358
358
  id: 'rag-agent',
359
359
  name: 'RAG Agent',
360
- model: 'openai/gpt-5.4',
360
+ model: 'openai/gpt-5.5',
361
361
  instructions: `
362
362
  Process queries using the provided context. Structure responses to be concise and relevant.
363
363
  ${LIBSQL_PROMPT}
@@ -374,7 +374,7 @@ import { UPSTASH_PROMPT } from '@mastra/upstash'
374
374
  export const ragAgent = new Agent({
375
375
  id: 'rag-agent',
376
376
  name: 'RAG Agent',
377
- model: 'openai/gpt-5.4',
377
+ model: 'openai/gpt-5.5',
378
378
  instructions: `
379
379
  Process queries using the provided context. Structure responses to be concise and relevant.
380
380
  ${UPSTASH_PROMPT}
@@ -391,7 +391,7 @@ import { VECTORIZE_PROMPT } from '@mastra/vectorize'
391
391
  export const ragAgent = new Agent({
392
392
  id: 'rag-agent',
393
393
  name: 'RAG Agent',
394
- model: 'openai/gpt-5.4',
394
+ model: 'openai/gpt-5.5',
395
395
  instructions: `
396
396
  Process queries using the provided context. Structure responses to be concise and relevant.
397
397
  ${VECTORIZE_PROMPT}
@@ -408,7 +408,7 @@ import { MONGODB_PROMPT } from '@mastra/mongodb'
408
408
  export const ragAgent = new Agent({
409
409
  id: 'rag-agent',
410
410
  name: 'RAG Agent',
411
- model: 'openai/gpt-5.4',
411
+ model: 'openai/gpt-5.5',
412
412
  instructions: `
413
413
  Process queries using the provided context. Structure responses to be concise and relevant.
414
414
  ${MONGODB_PROMPT}
@@ -425,7 +425,7 @@ import { OPENSEARCH_PROMPT } from '@mastra/opensearch'
425
425
  export const ragAgent = new Agent({
426
426
  id: 'rag-agent',
427
427
  name: 'RAG Agent',
428
- model: 'openai/gpt-5.4',
428
+ model: 'openai/gpt-5.5',
429
429
  instructions: `
430
430
  Process queries using the provided context. Structure responses to be concise and relevant.
431
431
  ${OPENSEARCH_PROMPT}
@@ -442,7 +442,7 @@ import { S3VECTORS_PROMPT } from '@mastra/s3vectors'
442
442
  export const ragAgent = new Agent({
443
443
  id: 'rag-agent',
444
444
  name: 'RAG Agent',
445
- model: 'openai/gpt-5.4',
445
+ model: 'openai/gpt-5.5',
446
446
  instructions: `
447
447
  Process queries using the provided context. Structure responses to be concise and relevant.
448
448
  ${S3VECTORS_PROMPT}
@@ -474,7 +474,7 @@ const initialResults = await pgVector.query({
474
474
  // Create a relevance scorer
475
475
  const relevanceProvider = new MastraAgentRelevanceScorer(
476
476
  'relevance-scorer',
477
- 'openai/gpt-5.4',
477
+ 'openai/gpt-5.5',
478
478
  )
479
479
 
480
480
  // Re-rank the results
@@ -1,5 +1,7 @@
1
1
  # Fine-Grained Authorization (FGA)
2
2
 
3
+ > **Note:** Fine-Grained Authorization is part of the Mastra Enterprise Edition. Production deployments require a valid EE license. [Contact sales](https://mastra.ai/contact) for more information.
4
+
3
5
  Fine-Grained Authorization (FGA) adds resource-level permission checks to your Mastra application. While RBAC answers "can this role do this action?", FGA answers **"can this user do this action on this specific resource?"**
4
6
 
5
7
  ## When to use FGA
@@ -211,6 +213,8 @@ When an FGA provider is configured, Mastra automatically checks authorization at
211
213
  | Stored resource routes | Stored resource permission for the route action | Stored resource type | Route record ID, or the stored-resource scope for collection routes |
212
214
  | HTTP resource routes | Configured per route | Configured per route | Configured per route |
213
215
 
216
+ For OAuth-protected MCP servers, HTTP MCP transports pass authenticated data as `extra.authInfo`. If an `MCPServer` is registered on an FGA-enabled Mastra instance, configure `mapAuthInfoToUser` so Mastra can set `requestContext.get('user')` before checking `tools/list` and `tools/call`. See [MCPServer authentication context](https://mastra.ai/reference/tools/mcp-server).
217
+
214
218
  Direct SDK calls to `createRun().start()`, `resume()`, or `restart()` are not independently checked by core FGA in this release. Make those calls from a protected route or guard them in application code. Pass a `requestContext` with an authenticated user when invoking protected entry points directly.
215
219
 
216
220
  Core agent, internal workflow, tool, and memory checks also pass `requestContext` and action metadata to the FGA provider. Route checks pass `requestContext`. Thread checks pass the owning `resourceId` when available.
@@ -235,7 +235,7 @@ export const colorAgent = new Agent({
235
235
  instructions: `You are a helpful CSS assistant.
236
236
  You can change the background color of web pages.
237
237
  Respond with a hex reference for the color requested by the user`,
238
- model: 'openai/gpt-5.4',
238
+ model: 'openai/gpt-5.5',
239
239
  })
240
240
  ```
241
241
 
@@ -155,7 +155,7 @@ export const dynamicAgent = new Agent({
155
155
 
156
156
  return `${basePrompt} ${localeInstructions}`.trim()
157
157
  },
158
- model: 'openai/gpt-5.4',
158
+ model: 'openai/gpt-5.5',
159
159
  })
160
160
  ```
161
161
 
@@ -182,7 +182,7 @@ export const registryAgent = new Agent({
182
182
 
183
183
  return prompt.content
184
184
  },
185
- model: 'openai/gpt-5.4',
185
+ model: 'openai/gpt-5.5',
186
186
  })
187
187
  ```
188
188
 
@@ -336,7 +336,7 @@ export const validatedAgent = new Agent({
336
336
 
337
337
  return `You are helping user ${userId}`
338
338
  },
339
- model: 'openai/gpt-5.4',
339
+ model: 'openai/gpt-5.5',
340
340
  })
341
341
  ```
342
342
 
@@ -120,7 +120,7 @@ The event structure includes `runId` and `from` at the top level, making it easi
120
120
  }
121
121
  ```
122
122
 
123
- ## Workflow stream properties
123
+ ### Workflow stream properties
124
124
 
125
125
  A workflow stream provides access to various response properties:
126
126
 
@@ -21,7 +21,7 @@ export const testAgent = new Agent({
21
21
  id: 'test-agent',
22
22
  name: 'Test Agent',
23
23
  instructions: 'You are a weather agent.',
24
- model: 'openai/gpt-5.4',
24
+ model: 'openai/gpt-5.5',
25
25
  tools: { testTool },
26
26
  })
27
27
  ```