@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
package/.docs/docs/channels.md
CHANGED
|
@@ -82,7 +82,7 @@ For example, a Slack adapter on an agent with the `your-agent` ID uses:
|
|
|
82
82
|
/api/agents/your-agent/channels/slack/webhook
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
Point the platform's webhook, event, or interactions URL to this path. Follow the guide for your platform or the [Chat SDK docs](https://chat-sdk.dev/adapters).
|
|
85
|
+
Point the platform's webhook, event, or interactions URL to this path. Follow the guide for your platform or the [Chat SDK docs](https://chat-sdk.dev/adapters). The webhook acknowledges the request before the agent finishes responding. See [Error handling and delivery](#error-handling-and-delivery) for what happens when verification or a handler fails.
|
|
86
86
|
|
|
87
87
|
During local development, platform webhooks need a public URL to reach your local server. Use a tunnel like [cloudflared](https://github.com/cloudflare/cloudflared) or [ngrok](https://ngrok.com/) to expose your server, `localhost:4111` by default:
|
|
88
88
|
|
|
@@ -215,6 +215,32 @@ Add only JSON-serializable, non-sensitive values. Signal metadata may be stored
|
|
|
215
215
|
|
|
216
216
|
Use `requestContext` for run-scoped configuration, such as credentials for a message that starts a run. Use `signalMetadata` for context that must stay attached to one message, including messages delivered to an active run.
|
|
217
217
|
|
|
218
|
+
## Error handling and delivery
|
|
219
|
+
|
|
220
|
+
A channel webhook acknowledges the platform before the agent finishes, so a `200` response means "received", not "answered". Before that acknowledgment, the adapter rejects bad requests synchronously (`401` for failed verification, `400` for an unparseable body, `503` for transient state failures) and the platform redelivers on non-`2xx` responses per its own policy. After the `200`, the platform never retries and Mastra owns errors. The default handler catches agent-run failures and posts an error message to the thread (customize it with `formatError`, which defaults to `❌ Error: {message}`). A custom handler that throws is only logged by Chat SDK, so nothing is posted or retried. Catch failures in custom handlers yourself:
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
channels: {
|
|
224
|
+
adapters: {
|
|
225
|
+
slack: createSlackAdapter(),
|
|
226
|
+
},
|
|
227
|
+
handlers: {
|
|
228
|
+
onDirectMessage: async (thread, message, defaultHandler, ctx) => {
|
|
229
|
+
try {
|
|
230
|
+
ctx.signalMetadata.ticketId = await lookupTicket(message)
|
|
231
|
+
} catch (error) {
|
|
232
|
+
ctx.mastra?.getLogger().error('Ticket lookup failed', { error })
|
|
233
|
+
await thread.post('Something went wrong looking up your ticket. Try again in a moment.')
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
await defaultHandler(thread, message)
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Platform retries also mean the same event can arrive more than once. Adapters deduplicate redelivered events using channel state, so configure [storage](https://mastra.ai/docs/storage) to keep deduplication reliable across restarts. Deduplication is best effort, so keep side effects in custom handlers idempotent so a duplicate that slips through doesn't repeat work like creating a ticket.
|
|
243
|
+
|
|
218
244
|
## Multimodal content
|
|
219
245
|
|
|
220
246
|
Models like Gemini can process images, video, and audio natively. Combine `inlineMedia` and `inlineLinks` to let users share rich content with your agent across platforms:
|
|
@@ -105,6 +105,60 @@ The root URL for the endpoints below is: `/v1/gateway`
|
|
|
105
105
|
| GET | `/projects/:id/memory/threads/:threadId/observations/history` | Observation history (dashboard) |
|
|
106
106
|
| GET | `/models` | List available models |
|
|
107
107
|
|
|
108
|
+
## Observability feedback query API
|
|
109
|
+
|
|
110
|
+
The hosted feedback query API lists and analyzes feedback exported to Mastra Platform Observability. Because the API is unversioned, backwards compatibility isn't guaranteed. Rate limits, retention, and ingestion-to-query freshness aren't published contracts.
|
|
111
|
+
|
|
112
|
+
Use the root URL for your environment's data-residency region:
|
|
113
|
+
|
|
114
|
+
| Region | Root URL |
|
|
115
|
+
| -------------- | ------------------------------------------------------ |
|
|
116
|
+
| United States | `https://observability.mastra.ai/api/observability` |
|
|
117
|
+
| European Union | `https://observability.eu.mastra.ai/api/observability` |
|
|
118
|
+
|
|
119
|
+
Telemetry stays in its residency region. Querying the other region returns no records for the environment. See [Observability co-location](https://mastra.ai/docs/mastra-platform/regions) for the environment-to-region mapping.
|
|
120
|
+
|
|
121
|
+
### Authentication and project scope
|
|
122
|
+
|
|
123
|
+
Every request requires a platform access token. Create one in [Mastra Platform](https://projects.mastra.ai), or use the token written to `.env` during Platform setup.
|
|
124
|
+
|
|
125
|
+
Include `X-Mastra-Project-Id` to limit results to one project. If you omit it, the query covers feedback in every project available to the token's organization.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
curl -sS "https://observability.mastra.ai/api/observability/feedback?page=0&perPage=20&feedbackType=rating" \
|
|
129
|
+
-H "Authorization: Bearer $MASTRA_PLATFORM_ACCESS_TOKEN" \
|
|
130
|
+
-H "X-Mastra-Project-Id: $MASTRA_PROJECT_ID" | jq
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Use an organization-scoped Platform access token. Gateway inference keys such as `mk_*` keys aren't accepted. Queries remain constrained to the token's organization even when you supply a project ID.
|
|
134
|
+
|
|
135
|
+
### Endpoints
|
|
136
|
+
|
|
137
|
+
| Method | Endpoint | Description |
|
|
138
|
+
| ------ | ----------------------- | ---------------------------- |
|
|
139
|
+
| GET | `/feedback` | List feedback records |
|
|
140
|
+
| POST | `/feedback/aggregate` | Return one aggregate value |
|
|
141
|
+
| POST | `/feedback/breakdown` | Group feedback by dimensions |
|
|
142
|
+
| POST | `/feedback/timeseries` | Bucket feedback by interval |
|
|
143
|
+
| POST | `/feedback/percentiles` | Return percentile series |
|
|
144
|
+
|
|
145
|
+
The list endpoint accepts page-mode parameters such as `page`, `perPage`, `field`, and `direction`, plus feedback filters as query parameters. It also supports delta polling with `mode=delta`, `after`, and `limit`. Responses contain a `feedback` array and page or delta metadata.
|
|
146
|
+
|
|
147
|
+
Analytics endpoints accept the same JSON request shapes and return types as the [feedback reference](https://mastra.ai/reference/observability/feedback). Analytics operate only on numeric feedback values.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
curl -sS "https://observability.mastra.ai/api/observability/feedback/aggregate" \
|
|
151
|
+
-X POST \
|
|
152
|
+
-H "Authorization: Bearer $MASTRA_PLATFORM_ACCESS_TOKEN" \
|
|
153
|
+
-H "X-Mastra-Project-Id: $MASTRA_PROJECT_ID" \
|
|
154
|
+
-H "Content-Type: application/json" \
|
|
155
|
+
--data '{"feedbackType":"rating","feedbackSource":"user","aggregation":"avg"}' | jq
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The API returns `401` for invalid credentials, `403` for organization authorization failures, and `400` for malformed query arguments or JSON bodies.
|
|
159
|
+
|
|
160
|
+
Hosted observability doesn't provide a feedback creation route. Export feedback from the application as described in [Export feedback to Mastra Platform](https://mastra.ai/docs/observability/feedback).
|
|
161
|
+
|
|
108
162
|
## Gateway proxy endpoints
|
|
109
163
|
|
|
110
164
|
Visit the [Gateway documentation](https://gateway.mastra.ai/docs) for more details.
|
|
@@ -130,7 +130,7 @@ See [Mastra storage exporter](https://mastra.ai/docs/observability/integrations/
|
|
|
130
130
|
|
|
131
131
|
## View observability data
|
|
132
132
|
|
|
133
|
-
Open your project in [Mastra Platform](https://projects.mastra.ai) to inspect exported traces, logs, metrics,
|
|
133
|
+
Open your project in [Mastra Platform](https://projects.mastra.ai) to inspect exported traces, logs, metrics, and scores. A Studio or Server deployment isn't required. Query exported feedback through the hosted feedback API described below.
|
|
134
134
|
|
|
135
135
|
Use a consistent `serviceName` to filter data from a specific application or deployment.
|
|
136
136
|
|
|
@@ -164,6 +164,8 @@ bun x mastra api trace list
|
|
|
164
164
|
|
|
165
165
|
The CLI can infer platform credentials from your project environment. See the [`mastra api` CLI reference](https://mastra.ai/reference/cli/mastra) for available commands, filtering, pagination, credential resolution, and `curl` examples.
|
|
166
166
|
|
|
167
|
+
You can query exported feedback over HTTP. See the [observability feedback query API](https://mastra.ai/docs/mastra-platform/api) for its current status, regional endpoints, authentication, and project scoping.
|
|
168
|
+
|
|
167
169
|
## Next steps
|
|
168
170
|
|
|
169
171
|
- 📹 [Mastra observability and Studio workshop](https://www.youtube.com/watch?v=dKO_a3RPra0)
|
|
@@ -350,6 +350,25 @@ const agent = new Agent({
|
|
|
350
350
|
})
|
|
351
351
|
```
|
|
352
352
|
|
|
353
|
+
FastEmbed also exposes the multilingual E5 model for non-English content. E5 is asymmetric, so it's exposed as two models: `multilingualE5LargePassage` for text you index and `multilingualE5LargeQuery` for search text.
|
|
354
|
+
|
|
355
|
+
```ts
|
|
356
|
+
import { Memory } from '@mastra/memory'
|
|
357
|
+
import { Agent } from '@mastra/core/agent'
|
|
358
|
+
import { fastembed } from '@mastra/fastembed'
|
|
359
|
+
|
|
360
|
+
const agent = new Agent({
|
|
361
|
+
id: 'agent',
|
|
362
|
+
memory: new Memory({
|
|
363
|
+
embedder: fastembed.multilingualE5LargePassage,
|
|
364
|
+
}),
|
|
365
|
+
})
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Memory uses a single embedder for both storing and recalling messages, so pick one of the two models and use it consistently. Use the paired `multilingualE5LargeQuery` model only where you control both sides of the pipeline, such as a RAG workflow that indexes with the passage model and searches with the query model.
|
|
369
|
+
|
|
370
|
+
Multilingual E5 produces 1024-dimensional vectors. Your vector index must be created with matching dimensions, and E5 vectors can't be mixed with vectors from another embedder in the same index.
|
|
371
|
+
|
|
353
372
|
## PostgreSQL index optimization
|
|
354
373
|
|
|
355
374
|
When using PostgreSQL as your vector store, you can optimize semantic recall performance by configuring the vector index. This is particularly important for large-scale deployments with thousands of messages.
|
|
@@ -33,6 +33,10 @@ await mastra.observability.addFeedback({
|
|
|
33
33
|
})
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
When you pass only `traceId` and `spanId`, `addFeedback()` rehydrates the target from configured observability storage before emitting the feedback event. Configure [`MastraStorageExporter`](https://mastra.ai/docs/observability/integrations/exporters/mastra-storage) when feedback is added after the traced execution has finished. If the trace isn't available in storage, Mastra logs a warning and drops the feedback event.
|
|
37
|
+
|
|
38
|
+
During a live traced execution, you can pass its `correlationContext` to emit feedback without rehydrating the trace from storage. This path is useful when the active request collects feedback before its tracing context ends.
|
|
39
|
+
|
|
36
40
|
## Find the trace for a message
|
|
37
41
|
|
|
38
42
|
Feedback is usually collected against a message a user has already read, so you need the `traceId` for that message. Assistant messages carry it in `content.metadata`, both in the stream result and when the message is recalled later from memory:
|
|
@@ -143,6 +147,16 @@ const ratingsOverTime = await observability!.getFeedbackTimeSeries({
|
|
|
143
147
|
|
|
144
148
|
See the [feedback reference](https://mastra.ai/reference/observability/feedback) for all fields, filters, return types, and percentile query parameters.
|
|
145
149
|
|
|
150
|
+
The local runtime exposes the list route at `/api/observability/feedback` and analytics under its related paths. See the [HTTP routes table](https://mastra.ai/reference/observability/feedback). Mastra Platform provides a separate, unversioned hosted query API. See the [observability feedback query API](https://mastra.ai/docs/mastra-platform/api) for regional endpoints, authentication, and project scoping.
|
|
151
|
+
|
|
152
|
+
## Export feedback to Mastra Platform
|
|
153
|
+
|
|
154
|
+
[`MastraPlatformExporter`](https://mastra.ai/reference/observability/tracing/exporters/mastra-platform-exporter) forwards emitted feedback events to Mastra Platform automatically because the hosted query API doesn't provide a creation route.
|
|
155
|
+
|
|
156
|
+
If your application adds feedback after an agent or workflow response using only its `traceId`, configure `MastraStorageExporter` alongside `MastraPlatformExporter`. The storage exporter keeps the trace available for `addFeedback()` to rehydrate, and the Platform exporter forwards the resulting feedback event. Exporting a trace to Platform doesn't make it available to the application's local storage.
|
|
157
|
+
|
|
158
|
+
See [Observability on Mastra Platform](https://mastra.ai/docs/mastra-platform/observability) for the combined exporter configuration.
|
|
159
|
+
|
|
146
160
|
## Export feedback to external platforms
|
|
147
161
|
|
|
148
162
|
Feedback flows through the observability event bus, so exporters that support feedback forward it automatically. The [PostHog exporter](https://mastra.ai/reference/observability/tracing/exporters/posthog) sends feedback as native `$ai_feedback` events that appear on the linked trace in PostHog.
|
|
@@ -2,30 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
# Metrics
|
|
4
4
|
|
|
5
|
-
Mastra automatically
|
|
5
|
+
Mastra automatically derives metrics from spans as traced operations complete. No separate metric instrumentation is required.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Mastra emits:
|
|
8
8
|
|
|
9
|
-
- **Duration metrics
|
|
10
|
-
- **Token usage metrics
|
|
11
|
-
- **Cost
|
|
9
|
+
- **Duration metrics** for agent runs, workflows, tools, model calls, and processors
|
|
10
|
+
- **Token usage metrics** for model input and output, including detailed token categories when the provider reports them
|
|
11
|
+
- **Cost estimates** calculated from token usage, provider, model, and an embedded pricing registry
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
>
|
|
15
|
-
> For local development, use [DuckDB](https://duckdb.org/) through `@mastra/duckdb`. For production, use [ClickHouse](https://clickhouse.com/) through `@mastra/clickhouse`. `PostgresStoreVNext` with the observability domain enabled also supports metrics, but always provide a time range to avoid full partition scans.
|
|
16
|
-
>
|
|
17
|
-
> Google Cloud Spanner supports metrics, but it's not recommended for heavy metrics workloads. The Spanner adapter disables metrics by default because metrics are write-heavy and scan-heavy. Set `disableMetrics: false` only for light workloads, or route metrics to an OLAP store.
|
|
13
|
+
Metrics retain trace correlation context, so you can investigate a change in a chart by finding the related span. See the [Automatic metrics reference](https://mastra.ai/reference/observability/metrics/automatic-metrics) for metric names, labels, and cost fields.
|
|
18
14
|
|
|
19
15
|
## When to use metrics
|
|
20
16
|
|
|
21
17
|
- Monitor latency across agents, tools, workflows, and model calls
|
|
22
|
-
- Track token consumption and cost
|
|
23
|
-
-
|
|
24
|
-
-
|
|
18
|
+
- Track token consumption and estimated cost over time
|
|
19
|
+
- Compare success and error rates across agents or tools
|
|
20
|
+
- Measure the effect of prompt, model, or code changes
|
|
25
21
|
|
|
26
|
-
##
|
|
22
|
+
## Storage support
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
Metrics require an analytics-capable observability store:
|
|
25
|
+
|
|
26
|
+
- **DuckDB** through `@mastra/duckdb` is recommended for local development.
|
|
27
|
+
- **ClickHouse** through `@mastra/clickhouse` is recommended for high-volume production workloads.
|
|
28
|
+
- **PostgresStoreVNext** supports metrics when its observability domain is enabled.
|
|
29
|
+
- **In-memory storage** supports metrics, but its data is lost when the process restarts.
|
|
30
|
+
- **Google Cloud Spanner** disables metrics by default. Set `disableMetrics: false` only for light workloads, or route metrics to a dedicated OLAP store.
|
|
31
|
+
|
|
32
|
+
Other storage adapters, including LibSQL, MSSQL, and MongoDB, can store other observability signals but don't implement metric storage and queries.
|
|
33
|
+
|
|
34
|
+
## Set up local metrics
|
|
35
|
+
|
|
36
|
+
Install the observability, application storage, and DuckDB packages:
|
|
29
37
|
|
|
30
38
|
**npm**:
|
|
31
39
|
|
|
@@ -51,7 +59,7 @@ yarn add @mastra/observability @mastra/libsql @mastra/duckdb
|
|
|
51
59
|
bun add @mastra/observability @mastra/libsql @mastra/duckdb
|
|
52
60
|
```
|
|
53
61
|
|
|
54
|
-
|
|
62
|
+
Configure a composite store that routes the observability domain to DuckDB:
|
|
55
63
|
|
|
56
64
|
```ts
|
|
57
65
|
import { Mastra } from '@mastra/core/mastra'
|
|
@@ -83,37 +91,16 @@ export const mastra = new Mastra({
|
|
|
83
91
|
})
|
|
84
92
|
```
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
The Studio metrics dashboard visualizes all automatic metrics with KPI cards, detailed breakdowns, token usage timelines, and configurable time ranges. See [Studio observability](https://mastra.ai/docs/studio/observability) for a full walkthrough.
|
|
89
|
-
|
|
90
|
-
## What Mastra measures
|
|
91
|
-
|
|
92
|
-
Mastra emits three categories of metrics automatically:
|
|
94
|
+
`MastraStorageExporter` persists metrics to the configured observability store and makes them available to Studio. Use `MastraPlatformExporter` instead, or alongside it, to send metrics to Mastra Platform.
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
- **Token usage**: Input and output token counts, broken down by type (text, cache, audio, image, reasoning).
|
|
96
|
-
- **Cost estimation**: Estimated cost per model call, based on an embedded pricing registry.
|
|
96
|
+
## View and query metrics
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
Use the [Studio observability dashboard](https://mastra.ai/docs/studio/observability) to inspect KPI cards, breakdowns, and time-series charts. For custom dashboards and analysis, use the observability store, `@mastra/client-js`, HTTP endpoints, or CLI described in the [Metric queries reference](https://mastra.ai/reference/observability/metrics/queries).
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
In production, always include a timestamp range in metric queries. Time bounds limit the data scanned and allow partitioned backends to skip unrelated partitions or chunks.
|
|
101
101
|
|
|
102
|
-
##
|
|
102
|
+
## Related
|
|
103
103
|
|
|
104
|
-
Mastra auto-instruments agent runs, workflow steps, tool calls, and model generations as spans. When a span ends, the observability layer extracts metrics from it:
|
|
105
|
-
|
|
106
|
-
1. **Duration**: Calculated from the span's start and end timestamps.
|
|
107
|
-
2. **Token usage**: Extracted from the `usage` attribute on model generation spans.
|
|
108
|
-
3. **Cost estimation**: Runs each token metric through an embedded pricing registry that matches by provider and model name.
|
|
109
|
-
|
|
110
|
-
Before storage, all metric labels pass through a cardinality filter that blocks known high-cardinality values (such as trace IDs and UUIDs) to keep storage efficient. Metrics are then batched by an internal event buffer and flushed to storage by the `MastraStorageExporter`.
|
|
111
|
-
|
|
112
|
-
## Next steps
|
|
113
|
-
|
|
114
|
-
- [Automatic metrics reference](https://mastra.ai/reference/observability/metrics/automatic-metrics)
|
|
115
|
-
- [Querying metrics](https://mastra.ai/docs/observability/metrics/querying)
|
|
116
|
-
- [Tracing overview](https://mastra.ai/docs/observability/tracing/overview)
|
|
117
|
-
- [Studio observability](https://mastra.ai/docs/studio/observability)
|
|
118
104
|
- [Observability overview](https://mastra.ai/docs/observability/overview)
|
|
119
|
-
- [
|
|
105
|
+
- [Tracing overview](https://mastra.ai/docs/observability/tracing/overview)
|
|
106
|
+
- [MastraStorageExporter](https://mastra.ai/docs/observability/integrations/exporters/mastra-storage)
|
|
@@ -58,6 +58,32 @@ registerApiRoute('/my-custom-route', {
|
|
|
58
58
|
|
|
59
59
|
## Common examples
|
|
60
60
|
|
|
61
|
+
### Block built-in route groups
|
|
62
|
+
|
|
63
|
+
Mastra doesn't provide a configuration option to remove or allowlist built-in routes. On Hono-based serving paths, you can make selected route groups unavailable by returning a response without calling `next()`:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { Mastra } from '@mastra/core'
|
|
67
|
+
|
|
68
|
+
const notFound = async () => new Response('Not Found', { status: 404 })
|
|
69
|
+
|
|
70
|
+
export const mastra = new Mastra({
|
|
71
|
+
server: {
|
|
72
|
+
middleware: [
|
|
73
|
+
{ path: '/api/memory/*', handler: notFound },
|
|
74
|
+
{ path: '/api/logs/*', handler: notFound },
|
|
75
|
+
{ path: '/api/observability/*', handler: notFound },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Each wildcard pattern blocks both the route group itself and its nested routes. For example, `/api/logs/*` blocks `/api/logs` and `/api/logs/transports`. Other route groups remain available.
|
|
82
|
+
|
|
83
|
+
Generated servers pass `server.apiPrefix` to the Hono adapter's [`prefix` constructor option](https://mastra.ai/reference/server/hono-adapter), which prefixes built-in routes. Middleware paths are registered unchanged, so they must explicitly include the configured prefix. For example, with `apiPrefix: '/api/v2'`, use `/api/v2/memory/*`. Custom API routes must live outside the configured API prefix and aren't blocked by these patterns.
|
|
84
|
+
|
|
85
|
+
This approach can't block routes declared public with `requiresAuth: false`, because Mastra skips user middleware for those routes. With a non-Hono server adapter, register equivalent middleware through the server framework instead.
|
|
86
|
+
|
|
61
87
|
### Using `RequestContext`
|
|
62
88
|
|
|
63
89
|
You can populate `RequestContext` in a runtime server middleware by extracting information from the request. In this example, the `temperature-unit` is set based on the Cloudflare `CF-IPCountry` header to ensure responses match the user's locale.
|
|
@@ -20,6 +20,7 @@ Server adapters let you run Mastra with your own HTTP server instead of the Hono
|
|
|
20
20
|
|
|
21
21
|
Mastra currently provides these official server adapters:
|
|
22
22
|
|
|
23
|
+
- [@mastra/elysia](https://mastra.ai/reference/server/elysia-adapter)
|
|
23
24
|
- [@mastra/express](https://mastra.ai/reference/server/express-adapter)
|
|
24
25
|
- [@mastra/hono](https://mastra.ai/reference/server/hono-adapter)
|
|
25
26
|
- [@mastra/fastify](https://mastra.ai/reference/server/fastify-adapter)
|
|
@@ -32,8 +33,58 @@ You can build your own adapter, read [custom adapters](https://mastra.ai/docs/se
|
|
|
32
33
|
|
|
33
34
|
Install the adapter for the framework of your choice.
|
|
34
35
|
|
|
36
|
+
**Elysia**:
|
|
37
|
+
|
|
38
|
+
**npm**:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @mastra/elysia@latest elysia
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**pnpm**:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm add @mastra/elysia@latest elysia
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Yarn**:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
yarn add @mastra/elysia@latest elysia
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Bun**:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
bun add @mastra/elysia@latest elysia
|
|
60
|
+
```
|
|
61
|
+
|
|
35
62
|
**Express**:
|
|
36
63
|
|
|
64
|
+
```bash
|
|
65
|
+
npm install @mastra/elysia@latest elysia
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Hono**:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm add @mastra/elysia@latest elysia
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Fastify**:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
yarn add @mastra/elysia@latest elysia
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Koa**:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
bun add @mastra/elysia@latest elysia
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**NestJS**:
|
|
87
|
+
|
|
37
88
|
**npm**:
|
|
38
89
|
|
|
39
90
|
```bash
|
|
@@ -58,31 +109,31 @@ yarn add @mastra/express@latest
|
|
|
58
109
|
bun add @mastra/express@latest
|
|
59
110
|
```
|
|
60
111
|
|
|
61
|
-
**
|
|
112
|
+
**Tab 7**:
|
|
62
113
|
|
|
63
114
|
```bash
|
|
64
115
|
npm install @mastra/express@latest
|
|
65
116
|
```
|
|
66
117
|
|
|
67
|
-
**
|
|
118
|
+
**Tab 8**:
|
|
68
119
|
|
|
69
120
|
```bash
|
|
70
121
|
pnpm add @mastra/express@latest
|
|
71
122
|
```
|
|
72
123
|
|
|
73
|
-
**
|
|
124
|
+
**Tab 9**:
|
|
74
125
|
|
|
75
126
|
```bash
|
|
76
127
|
yarn add @mastra/express@latest
|
|
77
128
|
```
|
|
78
129
|
|
|
79
|
-
**
|
|
130
|
+
**Tab 10**:
|
|
80
131
|
|
|
81
132
|
```bash
|
|
82
133
|
bun add @mastra/express@latest
|
|
83
134
|
```
|
|
84
135
|
|
|
85
|
-
**Tab
|
|
136
|
+
**Tab 11**:
|
|
86
137
|
|
|
87
138
|
**npm**:
|
|
88
139
|
|
|
@@ -108,31 +159,31 @@ yarn add @mastra/hono@latest
|
|
|
108
159
|
bun add @mastra/hono@latest
|
|
109
160
|
```
|
|
110
161
|
|
|
111
|
-
**Tab
|
|
162
|
+
**Tab 12**:
|
|
112
163
|
|
|
113
164
|
```bash
|
|
114
165
|
npm install @mastra/hono@latest
|
|
115
166
|
```
|
|
116
167
|
|
|
117
|
-
**Tab
|
|
168
|
+
**Tab 13**:
|
|
118
169
|
|
|
119
170
|
```bash
|
|
120
171
|
pnpm add @mastra/hono@latest
|
|
121
172
|
```
|
|
122
173
|
|
|
123
|
-
**Tab
|
|
174
|
+
**Tab 14**:
|
|
124
175
|
|
|
125
176
|
```bash
|
|
126
177
|
yarn add @mastra/hono@latest
|
|
127
178
|
```
|
|
128
179
|
|
|
129
|
-
**Tab
|
|
180
|
+
**Tab 15**:
|
|
130
181
|
|
|
131
182
|
```bash
|
|
132
183
|
bun add @mastra/hono@latest
|
|
133
184
|
```
|
|
134
185
|
|
|
135
|
-
**Tab
|
|
186
|
+
**Tab 16**:
|
|
136
187
|
|
|
137
188
|
**npm**:
|
|
138
189
|
|
|
@@ -158,31 +209,31 @@ yarn add @mastra/fastify@latest
|
|
|
158
209
|
bun add @mastra/fastify@latest
|
|
159
210
|
```
|
|
160
211
|
|
|
161
|
-
**Tab
|
|
212
|
+
**Tab 17**:
|
|
162
213
|
|
|
163
214
|
```bash
|
|
164
215
|
npm install @mastra/fastify@latest
|
|
165
216
|
```
|
|
166
217
|
|
|
167
|
-
**Tab
|
|
218
|
+
**Tab 18**:
|
|
168
219
|
|
|
169
220
|
```bash
|
|
170
221
|
pnpm add @mastra/fastify@latest
|
|
171
222
|
```
|
|
172
223
|
|
|
173
|
-
**Tab
|
|
224
|
+
**Tab 19**:
|
|
174
225
|
|
|
175
226
|
```bash
|
|
176
227
|
yarn add @mastra/fastify@latest
|
|
177
228
|
```
|
|
178
229
|
|
|
179
|
-
**Tab
|
|
230
|
+
**Tab 20**:
|
|
180
231
|
|
|
181
232
|
```bash
|
|
182
233
|
bun add @mastra/fastify@latest
|
|
183
234
|
```
|
|
184
235
|
|
|
185
|
-
**Tab
|
|
236
|
+
**Tab 21**:
|
|
186
237
|
|
|
187
238
|
**npm**:
|
|
188
239
|
|
|
@@ -208,31 +259,31 @@ yarn add @mastra/koa@latest
|
|
|
208
259
|
bun add @mastra/koa@latest
|
|
209
260
|
```
|
|
210
261
|
|
|
211
|
-
**Tab
|
|
262
|
+
**Tab 22**:
|
|
212
263
|
|
|
213
264
|
```bash
|
|
214
265
|
npm install @mastra/koa@latest
|
|
215
266
|
```
|
|
216
267
|
|
|
217
|
-
**Tab
|
|
268
|
+
**Tab 23**:
|
|
218
269
|
|
|
219
270
|
```bash
|
|
220
271
|
pnpm add @mastra/koa@latest
|
|
221
272
|
```
|
|
222
273
|
|
|
223
|
-
**Tab
|
|
274
|
+
**Tab 24**:
|
|
224
275
|
|
|
225
276
|
```bash
|
|
226
277
|
yarn add @mastra/koa@latest
|
|
227
278
|
```
|
|
228
279
|
|
|
229
|
-
**Tab
|
|
280
|
+
**Tab 25**:
|
|
230
281
|
|
|
231
282
|
```bash
|
|
232
283
|
bun add @mastra/koa@latest
|
|
233
284
|
```
|
|
234
285
|
|
|
235
|
-
**Tab
|
|
286
|
+
**Tab 26**:
|
|
236
287
|
|
|
237
288
|
**npm**:
|
|
238
289
|
|
|
@@ -258,25 +309,25 @@ yarn add @mastra/nestjs@latest
|
|
|
258
309
|
bun add @mastra/nestjs@latest
|
|
259
310
|
```
|
|
260
311
|
|
|
261
|
-
**Tab
|
|
312
|
+
**Tab 27**:
|
|
262
313
|
|
|
263
314
|
```bash
|
|
264
315
|
npm install @mastra/nestjs@latest
|
|
265
316
|
```
|
|
266
317
|
|
|
267
|
-
**Tab
|
|
318
|
+
**Tab 28**:
|
|
268
319
|
|
|
269
320
|
```bash
|
|
270
321
|
pnpm add @mastra/nestjs@latest
|
|
271
322
|
```
|
|
272
323
|
|
|
273
|
-
**Tab
|
|
324
|
+
**Tab 29**:
|
|
274
325
|
|
|
275
326
|
```bash
|
|
276
327
|
yarn add @mastra/nestjs@latest
|
|
277
328
|
```
|
|
278
329
|
|
|
279
|
-
**Tab
|
|
330
|
+
**Tab 30**:
|
|
280
331
|
|
|
281
332
|
```bash
|
|
282
333
|
bun add @mastra/nestjs@latest
|
|
@@ -286,6 +337,25 @@ bun add @mastra/nestjs@latest
|
|
|
286
337
|
|
|
287
338
|
Initialize your app as usual, then create a `MastraServer` by passing in the `app` and your main `mastra` instance from `src/mastra/index.ts`. Calling `init()` automatically registers Mastra middleware and all available endpoints. You can continue adding your own routes as normal, either before or after `init()`, and they’ll run alongside Mastra’s endpoints.
|
|
288
339
|
|
|
340
|
+
**Elysia**:
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
import { Elysia } from 'elysia'
|
|
344
|
+
import { MastraServer } from '@mastra/elysia'
|
|
345
|
+
import { mastra } from './mastra'
|
|
346
|
+
|
|
347
|
+
const app = new Elysia()
|
|
348
|
+
const server = new MastraServer({ app, mastra })
|
|
349
|
+
|
|
350
|
+
await server.init()
|
|
351
|
+
|
|
352
|
+
app.listen(4111)
|
|
353
|
+
|
|
354
|
+
console.log('Server running on http://localhost:4111')
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
> **Note:** See the [Elysia Adapter](https://mastra.ai/reference/server/elysia-adapter) documentation for full configuration options.
|
|
358
|
+
|
|
289
359
|
**Express**:
|
|
290
360
|
|
|
291
361
|
```typescript
|
|
@@ -466,7 +536,7 @@ You can add your own routes to the app alongside Mastra's routes.
|
|
|
466
536
|
- When you want Mastra-managed auth and route metadata such as `requiresAuth`, prefer `registerApiRoute()`.
|
|
467
537
|
- When you mount routes directly on the framework app, use the adapter's exported `createAuthMiddleware()` helper if those routes need Mastra auth.
|
|
468
538
|
|
|
469
|
-
Visit "Adding custom routes" for [Express](https://mastra.ai/reference/server/express-adapter) and [Hono](https://mastra.ai/reference/server/hono-adapter) for more information.
|
|
539
|
+
Visit "Adding custom routes" for [Elysia](https://mastra.ai/reference/server/elysia-adapter), [Express](https://mastra.ai/reference/server/express-adapter), and [Hono](https://mastra.ai/reference/server/hono-adapter) for more information.
|
|
470
540
|
|
|
471
541
|
## Route prefixes
|
|
472
542
|
|
|
@@ -607,7 +677,7 @@ When using adapters, configure these features directly with your framework. For
|
|
|
607
677
|
|
|
608
678
|
Server adapters register MCP (Model Context Protocol) routes during `registerRoutes()` when MCP servers are configured in your Mastra instance. MCP allows external tools and services to connect to your Mastra server and interact with your agents.
|
|
609
679
|
|
|
610
|
-
|
|
680
|
+
Most adapters register routes for both HTTP and SSE (Server-Sent Events) transports, enabling different client connection patterns. The Elysia adapter currently supports MCP HTTP transport only.
|
|
611
681
|
|
|
612
682
|
### Serverless mode
|
|
613
683
|
|
|
@@ -643,6 +713,7 @@ See [MCP](https://mastra.ai/docs/connections/mcp) for configuration details and
|
|
|
643
713
|
|
|
644
714
|
## Related
|
|
645
715
|
|
|
716
|
+
- [Elysia Adapter](https://mastra.ai/reference/server/elysia-adapter) - Elysia-specific setup
|
|
646
717
|
- [Hono Adapter](https://mastra.ai/reference/server/hono-adapter) - Hono-specific setup
|
|
647
718
|
- [Express Adapter](https://mastra.ai/reference/server/express-adapter) - Express-specific setup
|
|
648
719
|
- [NestJS Adapter](https://mastra.ai/reference/server/nestjs-adapter) - NestJS-specific setup
|
package/.docs/docs/subagents.md
CHANGED
|
@@ -159,12 +159,12 @@ const stream = await parentAgent.stream('Research AI trends', {
|
|
|
159
159
|
|
|
160
160
|
The `context` object includes:
|
|
161
161
|
|
|
162
|
-
| Property | Description
|
|
163
|
-
| ------------- |
|
|
164
|
-
| `primitiveId` | The ID of the subagent that ran
|
|
165
|
-
| `result` | The subagent's response
|
|
166
|
-
| `error` | Error if the delegation failed
|
|
167
|
-
| `bail()` | Function to stop the parent agent's loop
|
|
162
|
+
| Property | Description |
|
|
163
|
+
| ------------- | --------------------------------------------------------------------------------------------- |
|
|
164
|
+
| `primitiveId` | The ID of the subagent that ran |
|
|
165
|
+
| `result` | The subagent's response, including `text`, `usage`, `finishReason`, and `subAgentToolResults` |
|
|
166
|
+
| `error` | Error if the delegation failed |
|
|
167
|
+
| `bail()` | Function to stop the parent agent's loop |
|
|
168
168
|
|
|
169
169
|
### Hook errors
|
|
170
170
|
|