@mastra/mcp-docs-server 1.1.18-alpha.1 → 1.1.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/agents/overview.md +4 -4
- package/.docs/docs/agents/processors.md +1 -1
- package/.docs/docs/community/licensing.md +7 -9
- package/.docs/docs/deployment/monorepo.md +0 -6
- package/.docs/docs/evals/built-in-scorers.md +1 -1
- package/.docs/docs/{observability → evals}/datasets/overview.md +12 -12
- package/.docs/docs/{observability → evals}/datasets/running-experiments.md +9 -9
- package/.docs/docs/evals/overview.md +8 -9
- package/.docs/docs/getting-started/manual-install.md +1 -2
- package/.docs/docs/index.md +1 -1
- package/.docs/docs/mastra-cloud/deployment.md +2 -2
- package/.docs/docs/mastra-cloud/observability.md +2 -2
- package/.docs/docs/mastra-cloud/overview.md +1 -1
- package/.docs/docs/mastra-cloud/setup.md +3 -3
- package/.docs/docs/mcp/publishing-mcp-server.md +20 -0
- package/.docs/docs/memory/message-history.md +6 -4
- package/.docs/docs/memory/observational-memory.md +20 -11
- package/.docs/docs/memory/overview.md +4 -4
- package/.docs/docs/memory/semantic-recall.md +28 -19
- package/.docs/docs/memory/storage.md +4 -4
- package/.docs/docs/observability/metrics/overview.md +114 -0
- package/.docs/docs/observability/overview.md +13 -5
- package/.docs/docs/observability/tracing/exporters/default.md +2 -4
- package/.docs/docs/observability/tracing/exporters/laminar.md +4 -4
- package/.docs/docs/observability/tracing/exporters/sentry.md +4 -4
- package/.docs/docs/observability/tracing/overview.md +2 -2
- package/.docs/docs/rag/chunking-and-embedding.md +2 -2
- package/.docs/docs/server/auth/composite-auth.md +1 -7
- package/.docs/docs/server/auth/custom-auth-provider.md +2 -4
- package/.docs/docs/server/auth/jwt.md +1 -1
- package/.docs/docs/server/auth/simple-auth.md +1 -7
- package/.docs/docs/server/auth.md +3 -3
- package/.docs/docs/server/custom-adapters.md +3 -1
- package/.docs/docs/server/custom-api-routes.md +1 -1
- package/.docs/docs/server/mastra-client.md +1 -3
- package/.docs/docs/server/mastra-server.md +8 -0
- package/.docs/docs/server/request-context.md +17 -17
- package/.docs/docs/server/server-adapters.md +8 -8
- package/.docs/docs/streaming/events.md +1 -90
- package/.docs/docs/streaming/overview.md +0 -42
- package/.docs/docs/studio/auth.md +142 -0
- package/.docs/docs/{deployment/studio.md → studio/deployment.md} +42 -16
- package/.docs/docs/studio/observability.md +98 -0
- package/.docs/docs/studio/overview.md +127 -0
- package/.docs/docs/workflows/agents-and-tools.md +7 -10
- package/.docs/docs/workflows/control-flow.md +1 -1
- package/.docs/docs/workflows/overview.md +12 -7
- package/.docs/docs/workflows/suspend-and-resume.md +1 -1
- package/.docs/guides/concepts/multi-agent-systems.md +4 -4
- package/.docs/guides/deployment/vercel.md +1 -1
- package/.docs/guides/getting-started/next-js.md +1 -1
- package/.docs/guides/getting-started/quickstart.md +1 -1
- package/.docs/guides/guide/ai-recruiter.md +1 -1
- package/.docs/guides/guide/chef-michel.md +1 -1
- package/.docs/guides/guide/code-review-bot.md +1 -1
- package/.docs/guides/guide/dev-assistant.md +1 -1
- package/.docs/guides/guide/docs-manager.md +1 -1
- package/.docs/guides/guide/github-actions-pr-description.md +1 -1
- package/.docs/guides/guide/notes-mcp-server.md +1 -1
- package/.docs/guides/guide/stock-agent.md +1 -1
- package/.docs/guides/guide/web-search.md +2 -2
- package/.docs/guides/index.md +1 -1
- package/.docs/guides/migrations/upgrade-to-v1/client.md +1 -1
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
- package/.docs/models/index.md +2 -2
- package/.docs/models/providers/aihubmix.md +17 -102
- package/.docs/models/providers/synthetic.md +2 -1
- package/.docs/models/providers.md +0 -1
- package/.docs/reference/agents/agent.md +1 -1
- package/.docs/reference/cli/mastra.md +3 -3
- package/.docs/reference/client-js/workflows.md +2 -2
- package/.docs/reference/configuration.md +4 -4
- package/.docs/reference/deployer/cloudflare.md +1 -1
- package/.docs/reference/deployer/vercel.md +1 -1
- package/.docs/reference/index.md +16 -14
- package/.docs/reference/memory/observational-memory.md +1 -1
- package/.docs/reference/observability/metrics/automatic-metrics.md +132 -0
- package/.docs/reference/storage/cloudflare-d1.md +1 -1
- package/.docs/reference/storage/cloudflare.md +3 -3
- package/.docs/reference/storage/convex.md +1 -1
- package/.docs/reference/storage/dynamodb.md +1 -1
- package/.docs/reference/storage/lance.md +1 -1
- package/.docs/reference/storage/upstash.md +1 -1
- package/.docs/reference/workspace/vercel.md +118 -0
- package/CHANGELOG.md +23 -0
- package/package.json +6 -6
- package/.docs/docs/getting-started/studio.md +0 -113
- package/.docs/docs/mastra-cloud/studio.md +0 -24
|
@@ -14,7 +14,7 @@ export const mastra = new Mastra({
|
|
|
14
14
|
})
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
> **Sharing the database with
|
|
17
|
+
> **Sharing the database with Studio:** When running `mastra dev` alongside your application (e.g., Next.js), use an absolute path to ensure both processes access the same database:
|
|
18
18
|
>
|
|
19
19
|
> ```typescript
|
|
20
20
|
> url: 'file:/absolute/path/to/your/project/mastra.db'
|
|
@@ -129,7 +129,7 @@ Mastra organizes conversations using two identifiers:
|
|
|
129
129
|
|
|
130
130
|
Both identifiers are required for agents to store information:
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
**.generate()**:
|
|
133
133
|
|
|
134
134
|
```typescript
|
|
135
135
|
const response = await agent.generate('hello', {
|
|
@@ -140,7 +140,7 @@ const response = await agent.generate('hello', {
|
|
|
140
140
|
})
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
**.stream()**:
|
|
144
144
|
|
|
145
145
|
```typescript
|
|
146
146
|
const stream = await agent.stream('hello', {
|
|
@@ -151,7 +151,7 @@ const stream = await agent.stream('hello', {
|
|
|
151
151
|
})
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
> **Note:** [Studio](https://mastra.ai/docs/
|
|
154
|
+
> **Note:** [Studio](https://mastra.ai/docs/studio/overview) automatically generates a thread and resource ID for you. When calling `stream()` or `generate()` yourself, remember to provide these identifiers explicitly.
|
|
155
155
|
|
|
156
156
|
### Thread title generation
|
|
157
157
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Metrics overview
|
|
2
|
+
|
|
3
|
+
Mastra automatically emits performance and usage metrics from traced execution. There's no manual instrumentation needed. Metrics are derived from spans as they complete.
|
|
4
|
+
|
|
5
|
+
Three categories of metrics are emitted automatically:
|
|
6
|
+
|
|
7
|
+
- **Duration metrics**: Execution time for agents, workflows, tools, model calls, and processors.
|
|
8
|
+
- **Token usage metrics**: Input and output token counts broken down by type (text, cache, audio, image, reasoning).
|
|
9
|
+
- **Cost estimation**: Estimated cost per model call based on an embedded pricing registry.
|
|
10
|
+
|
|
11
|
+
> **Note:** Metrics require a separate OLAP store for observability. Relational databases like PostgreSQL, LibSQL, etc. are not supported for metrics. In-memory storage resets on restart.
|
|
12
|
+
>
|
|
13
|
+
> For local development, you can use [DuckDB](https://mastra.ai/reference/vectors/duckdb). We don't recommend using in-memory/DuckDB for production, ClickHouse support is coming soon for scalable metrics storage.
|
|
14
|
+
|
|
15
|
+
## When to use metrics
|
|
16
|
+
|
|
17
|
+
- Monitor latency across agents, tools, workflows, and model calls
|
|
18
|
+
- Track token consumption and cost trends over time
|
|
19
|
+
- Identify error-heavy agents or tools by comparing success and error rates
|
|
20
|
+
- Compare performance before and after prompt, model, or code changes
|
|
21
|
+
|
|
22
|
+
## Get started
|
|
23
|
+
|
|
24
|
+
Install the required packages:
|
|
25
|
+
|
|
26
|
+
**npm**:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @mastra/observability @mastra/libsql @mastra/duckdb
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**pnpm**:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm add @mastra/observability @mastra/libsql @mastra/duckdb
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Yarn**:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
yarn add @mastra/observability @mastra/libsql @mastra/duckdb
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Bun**:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
bun add @mastra/observability @mastra/libsql @mastra/duckdb
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Then configure observability with a composite store that routes the observability domain to DuckDB:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
54
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
55
|
+
import { DuckDBStore } from '@mastra/duckdb'
|
|
56
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
57
|
+
import { Observability, DefaultExporter, SensitiveDataFilter } from '@mastra/observability'
|
|
58
|
+
|
|
59
|
+
export const mastra = new Mastra({
|
|
60
|
+
storage: new MastraCompositeStore({
|
|
61
|
+
id: 'composite-storage',
|
|
62
|
+
default: new LibSQLStore({
|
|
63
|
+
id: 'mastra-storage',
|
|
64
|
+
url: 'file:./mastra.db',
|
|
65
|
+
}),
|
|
66
|
+
domains: {
|
|
67
|
+
observability: await new DuckDBStore().getStore('observability'),
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
observability: new Observability({
|
|
71
|
+
configs: {
|
|
72
|
+
default: {
|
|
73
|
+
serviceName: 'mastra',
|
|
74
|
+
exporters: [new DefaultExporter()],
|
|
75
|
+
spanOutputProcessors: [new SensitiveDataFilter()],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Studio
|
|
83
|
+
|
|
84
|
+
The Studio metrics dashboard visualizes all automatic metrics with KPI cards, detailed breakdowns, and configurable time ranges. See [Studio observability](https://mastra.ai/docs/studio/observability) for a full walkthrough.
|
|
85
|
+
|
|
86
|
+
## What Mastra measures
|
|
87
|
+
|
|
88
|
+
Mastra emits three categories of metrics automatically:
|
|
89
|
+
|
|
90
|
+
- **Duration**: Execution time in milliseconds for agents, workflows, tools, model calls, and processors.
|
|
91
|
+
- **Token usage**: Input and output token counts, broken down by type (text, cache, audio, image, reasoning).
|
|
92
|
+
- **Cost estimation**: Estimated cost per model call, based on an embedded pricing registry.
|
|
93
|
+
|
|
94
|
+
Each metric carries trace correlation context so you can drill from a dashboard spike to the exact span that caused it.
|
|
95
|
+
|
|
96
|
+
For the full list of metric names, labels, and cost fields, see the [Automatic metrics reference](https://mastra.ai/reference/observability/metrics/automatic-metrics).
|
|
97
|
+
|
|
98
|
+
## How automatic metrics work
|
|
99
|
+
|
|
100
|
+
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:
|
|
101
|
+
|
|
102
|
+
1. **Duration**: Calculated from the span's start and end timestamps.
|
|
103
|
+
2. **Token usage**: Extracted from the `usage` attribute on model generation spans.
|
|
104
|
+
3. **Cost estimation**: Runs each token metric through an embedded pricing registry that matches by provider and model name.
|
|
105
|
+
|
|
106
|
+
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 `DefaultExporter`.
|
|
107
|
+
|
|
108
|
+
## Next steps
|
|
109
|
+
|
|
110
|
+
- [Automatic metrics reference](https://mastra.ai/reference/observability/metrics/automatic-metrics)
|
|
111
|
+
- [Tracing overview](https://mastra.ai/docs/observability/tracing/overview)
|
|
112
|
+
- [Studio observability](https://mastra.ai/docs/studio/observability)
|
|
113
|
+
- [Observability overview](https://mastra.ai/docs/observability/overview)
|
|
114
|
+
- [DefaultExporter reference](https://mastra.ai/docs/observability/tracing/exporters/default)
|
|
@@ -23,10 +23,12 @@ For production environments with high traffic, we recommend using **ClickHouse**
|
|
|
23
23
|
|
|
24
24
|
Configure Observability in your Mastra instance:
|
|
25
25
|
|
|
26
|
-
```
|
|
27
|
-
import { Mastra } from '@mastra/core'
|
|
26
|
+
```ts
|
|
27
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
28
28
|
import { PinoLogger } from '@mastra/loggers'
|
|
29
29
|
import { LibSQLStore } from '@mastra/libsql'
|
|
30
|
+
import { DuckDBStore } from '@mastra/duckdb'
|
|
31
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
30
32
|
import {
|
|
31
33
|
Observability,
|
|
32
34
|
DefaultExporter,
|
|
@@ -36,9 +38,15 @@ import {
|
|
|
36
38
|
|
|
37
39
|
export const mastra = new Mastra({
|
|
38
40
|
logger: new PinoLogger(),
|
|
39
|
-
storage: new
|
|
40
|
-
id: '
|
|
41
|
-
|
|
41
|
+
storage: new MastraCompositeStore({
|
|
42
|
+
id: 'composite-storage',
|
|
43
|
+
default: new LibSQLStore({
|
|
44
|
+
id: 'mastra-storage',
|
|
45
|
+
url: 'file:./mastra.db',
|
|
46
|
+
}),
|
|
47
|
+
domains: {
|
|
48
|
+
observability: await new DuckDBStore().getStore('observability'),
|
|
49
|
+
},
|
|
42
50
|
}),
|
|
43
51
|
observability: new Observability({
|
|
44
52
|
configs: {
|
|
@@ -58,7 +58,7 @@ export const mastra = new Mastra({
|
|
|
58
58
|
default: {
|
|
59
59
|
serviceName: 'mastra',
|
|
60
60
|
exporters: [
|
|
61
|
-
new DefaultExporter(), // Persists traces to storage for
|
|
61
|
+
new DefaultExporter(), // Persists traces to storage for Studio
|
|
62
62
|
new CloudExporter(), // Sends traces to Mastra Cloud (requires MASTRA_CLOUD_ACCESS_TOKEN)
|
|
63
63
|
],
|
|
64
64
|
spanOutputProcessors: [new SensitiveDataFilter()],
|
|
@@ -68,9 +68,7 @@ export const mastra = new Mastra({
|
|
|
68
68
|
})
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
##
|
|
72
|
-
|
|
73
|
-
### Studio
|
|
71
|
+
## Studio
|
|
74
72
|
|
|
75
73
|
Access your traces through Studio:
|
|
76
74
|
|
|
@@ -7,25 +7,25 @@
|
|
|
7
7
|
**npm**:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @mastra/laminar@
|
|
10
|
+
npm install @mastra/laminar@latest
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
**pnpm**:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
pnpm add @mastra/laminar@
|
|
16
|
+
pnpm add @mastra/laminar@latest
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
**Yarn**:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
yarn add @mastra/laminar@
|
|
22
|
+
yarn add @mastra/laminar@latest
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
**Bun**:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
bun add @mastra/laminar@
|
|
28
|
+
bun add @mastra/laminar@latest
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Configuration
|
|
@@ -7,25 +7,25 @@
|
|
|
7
7
|
**npm**:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @mastra/sentry@
|
|
10
|
+
npm install @mastra/sentry@latest
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
**pnpm**:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
pnpm add @mastra/sentry@
|
|
16
|
+
pnpm add @mastra/sentry@latest
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
**Yarn**:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
yarn add @mastra/sentry@
|
|
22
|
+
yarn add @mastra/sentry@latest
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
**Bun**:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
bun add @mastra/sentry@
|
|
28
|
+
bun add @mastra/sentry@latest
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Configuration
|
|
@@ -31,7 +31,7 @@ export const mastra = new Mastra({
|
|
|
31
31
|
default: {
|
|
32
32
|
serviceName: 'mastra',
|
|
33
33
|
exporters: [
|
|
34
|
-
new DefaultExporter(), // Persists traces to storage for
|
|
34
|
+
new DefaultExporter(), // Persists traces to storage for Studio
|
|
35
35
|
new CloudExporter(), // Sends traces to Mastra Cloud (if MASTRA_CLOUD_ACCESS_TOKEN is set)
|
|
36
36
|
],
|
|
37
37
|
spanOutputProcessors: [
|
|
@@ -55,7 +55,7 @@ This configuration includes:
|
|
|
55
55
|
|
|
56
56
|
- **Exporters**:
|
|
57
57
|
|
|
58
|
-
- `DefaultExporter` - Persists traces to your configured storage for
|
|
58
|
+
- `DefaultExporter` - Persists traces to your configured storage for Studio
|
|
59
59
|
- `CloudExporter` - Sends traces to Mastra Cloud (requires `MASTRA_CLOUD_ACCESS_TOKEN`)
|
|
60
60
|
|
|
61
61
|
- **Span Output Processors**: `SensitiveDataFilter` - Redacts sensitive fields
|
|
@@ -9,7 +9,7 @@ const docFromMarkdown = MDocument.fromMarkdown('# Your Markdown content...')
|
|
|
9
9
|
const docFromJSON = MDocument.fromJSON(`{ "key": "value" }`)
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## Document processing
|
|
13
13
|
|
|
14
14
|
Use `chunk` to split documents into manageable pieces. Mastra supports multiple chunking strategies optimized for different document types:
|
|
15
15
|
|
|
@@ -65,7 +65,7 @@ const chunks = await doc.chunk({
|
|
|
65
65
|
|
|
66
66
|
We go deeper into chunking strategies in our [`chunk()` reference documentation](https://mastra.ai/reference/rag/chunk).
|
|
67
67
|
|
|
68
|
-
##
|
|
68
|
+
## Embedding generation
|
|
69
69
|
|
|
70
70
|
Transform chunks into embeddings using your preferred provider. Mastra supports embedding models through the model router.
|
|
71
71
|
|
|
@@ -225,10 +225,4 @@ function handleUser(user: User) {
|
|
|
225
225
|
console.log('Clerk user:', user.email)
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Related
|
|
231
|
-
|
|
232
|
-
- [Auth Overview](https://mastra.ai/docs/server/auth) - Authentication concepts
|
|
233
|
-
- [Simple Auth](https://mastra.ai/docs/server/auth/simple-auth) - Token-to-user mapping
|
|
234
|
-
- [Custom Auth Provider](https://mastra.ai/docs/server/auth/custom-auth-provider) - Build your own provider
|
|
228
|
+
```
|
|
@@ -507,7 +507,5 @@ See the [source code](https://github.com/mastra-ai/mastra/tree/main/auth) for im
|
|
|
507
507
|
|
|
508
508
|
## Related
|
|
509
509
|
|
|
510
|
-
- [Auth Overview](https://mastra.ai/docs/server/auth)
|
|
511
|
-
- [
|
|
512
|
-
- [Clerk Auth](https://mastra.ai/docs/server/auth/clerk) - Clerk integration
|
|
513
|
-
- [Custom API Routes](https://mastra.ai/docs/server/custom-api-routes) - Controlling authentication on custom endpoints
|
|
510
|
+
- [Auth Overview](https://mastra.ai/docs/server/auth): Authentication concepts and configuration
|
|
511
|
+
- [Custom API Routes](https://mastra.ai/docs/server/custom-api-routes): Controlling authentication on custom endpoints
|
|
@@ -61,7 +61,7 @@ export const mastra = new Mastra({
|
|
|
61
61
|
|
|
62
62
|
> **Info:** Visit [MastraJwtAuth](https://mastra.ai/reference/auth/jwt) for all available configuration options.
|
|
63
63
|
|
|
64
|
-
Inside [Studio](https://mastra.ai/docs/
|
|
64
|
+
Inside [Studio](https://mastra.ai/docs/studio/overview), go to **Settings** and under **Headers** select the **"Add Header"** button. Enter `Authorization` as the header name and `Bearer <your-jwt>` as the value.
|
|
65
65
|
|
|
66
66
|
## Configuring `MastraClient`
|
|
67
67
|
|
|
@@ -171,10 +171,4 @@ SimpleAuth is designed for simplicity, not production security:
|
|
|
171
171
|
- No cryptographic verification
|
|
172
172
|
- All tokens must be known at startup
|
|
173
173
|
|
|
174
|
-
For production applications, consider using [JWT](https://mastra.ai/docs/server/auth/jwt), [Clerk](https://mastra.ai/docs/server/auth/clerk), [Auth0](https://mastra.ai/docs/server/auth/auth0), or another identity provider.
|
|
175
|
-
|
|
176
|
-
## Related
|
|
177
|
-
|
|
178
|
-
- [Auth Overview](https://mastra.ai/docs/server/auth) - Authentication concepts
|
|
179
|
-
- [JWT Auth](https://mastra.ai/docs/server/auth/jwt) - JSON Web Token authentication
|
|
180
|
-
- [Custom Auth Provider](https://mastra.ai/docs/server/auth/custom-auth-provider) - Build your own provider
|
|
174
|
+
For production applications, consider using [JWT](https://mastra.ai/docs/server/auth/jwt), [Clerk](https://mastra.ai/docs/server/auth/clerk), [Auth0](https://mastra.ai/docs/server/auth/auth0), or another identity provider.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Auth overview
|
|
2
2
|
|
|
3
|
-
Mastra lets you choose how you handle authentication, so you can secure access to your API and [Studio](https://mastra.ai/docs/
|
|
3
|
+
Mastra lets you choose how you handle authentication, so you can secure access to your API and [Studio](https://mastra.ai/docs/studio/overview) using the identity system that fits your stack.
|
|
4
4
|
|
|
5
|
-
You can start with basic shared secret JWT authentication and switch to providers
|
|
5
|
+
You can start with basic shared secret JWT authentication and switch to known providers when you need more advanced identity features.
|
|
6
6
|
|
|
7
7
|
## What auth secures
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ Configuring authentication locks down two things at once:
|
|
|
13
13
|
|
|
14
14
|
Authentication is optional. If no auth is configured, all routes and Studio are publicly accessible. Public access can be enabled on individual custom routes using `requiresAuth: false`.
|
|
15
15
|
|
|
16
|
-
See [Custom API Routes](https://mastra.ai/docs/server/custom-api-routes) for controlling authentication on custom endpoints.
|
|
16
|
+
See [Custom API Routes](https://mastra.ai/docs/server/custom-api-routes) for controlling authentication on custom endpoints. Visit the [Studio Auth docs](https://mastra.ai/docs/studio/auth) for more on securing your Studio deployment.
|
|
17
17
|
|
|
18
18
|
> **Note:** Authentication for Studio is currently supported by the following providers: Simple Auth, JWT, WorkOS, and Better Auth.
|
|
19
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Custom adapters
|
|
2
2
|
|
|
3
|
-
Create a custom adapter when
|
|
3
|
+
Create a custom adapter when the prebuilt server adapters (Hono, Express, Fastify, Koa) don't support your framework or you have specific request/response handling requirements.
|
|
4
4
|
|
|
5
5
|
A custom adapter translates between Mastra's route definitions and your framework's routing system. You'll implement methods that register middleware, handle requests, and send responses using your framework's APIs.
|
|
6
6
|
|
|
@@ -368,6 +368,8 @@ app.listen(4111)
|
|
|
368
368
|
```
|
|
369
369
|
|
|
370
370
|
> **Tip:** The existing [@mastra/hono](https://github.com/mastra-ai/mastra/blob/main/server-adapters/hono/src/index.ts) and [@mastra/express](https://github.com/mastra-ai/mastra/blob/main/server-adapters/express/src/index.ts) implementations are good references when building your custom adapter. They show how to handle framework-specific patterns for context storage, middleware registration, and response handling.
|
|
371
|
+
>
|
|
372
|
+
> If you want to use [Studio](https://mastra.ai/docs/studio/overview) with your server adapter, use [`mastra studio`](https://mastra.ai/reference/cli/mastra) to only launch the Studio UI.
|
|
371
373
|
|
|
372
374
|
## Related
|
|
373
375
|
|
|
@@ -262,7 +262,7 @@ For more information about authentication providers, see the [Auth documentation
|
|
|
262
262
|
|
|
263
263
|
## Continue generation after client disconnect
|
|
264
264
|
|
|
265
|
-
Built-in streaming helpers such as [`chatRoute()`](https://mastra.ai/reference/ai-sdk/chat-route) forward the incoming request's `AbortSignal` to `agent.stream()`. That
|
|
265
|
+
Built-in streaming helpers such as [`chatRoute()`](https://mastra.ai/reference/ai-sdk/chat-route) forward the incoming request's `AbortSignal` to `agent.stream()`. That's the right default when a browser disconnect should cancel the model call.
|
|
266
266
|
|
|
267
267
|
If you want the server to keep generating and persist the final response even after the client disconnects, build a custom route around the underlying `MastraModelOutput`. Start the agent stream without forwarding `c.req.raw.signal`, then call `consumeStream()` in the background so generation continues server-side.
|
|
268
268
|
|
|
@@ -10,9 +10,7 @@ To ensure smooth local development, make sure you have:
|
|
|
10
10
|
- TypeScript `v4.7` or higher (if using TypeScript)
|
|
11
11
|
- Your local Mastra server running (typically on port `4111`)
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
The Mastra Client SDK is designed for browser environments and uses the native `fetch` API for making HTTP requests to your Mastra server.
|
|
13
|
+
> **Note:** The Mastra Client SDK is designed for browser environments and uses the native `fetch` API for making HTTP requests to your Mastra server.
|
|
16
14
|
|
|
17
15
|
## Installation
|
|
18
16
|
|
|
@@ -43,6 +43,14 @@ export const mastra = new Mastra({
|
|
|
43
43
|
- **[Mastra Client SDK](https://mastra.ai/docs/server/mastra-client)**: Type-safe client for calling agents, workflows, and tools from browser or server environments.
|
|
44
44
|
- **[Authentication](https://mastra.ai/docs/server/auth)**: Secure endpoints with JWT, Clerk, Supabase, Firebase, Auth0, or WorkOS.
|
|
45
45
|
|
|
46
|
+
## REST API
|
|
47
|
+
|
|
48
|
+
You can explore all available endpoints in the OpenAPI specification at <http://localhost:4111/api/openapi.json>, which details every endpoint and its request and response schemas.
|
|
49
|
+
|
|
50
|
+
To explore the API interactively, visit the Swagger UI at <http://localhost:4111/swagger-ui>. Here, you can discover endpoints and test them directly from your browser.
|
|
51
|
+
|
|
52
|
+
> **Note:** The OpenAPI and Swagger endpoints are disabled in production by default. To enable them, set [`server.build.openAPIDocs`](https://mastra.ai/reference/configuration) and [`server.build.swaggerUI`](https://mastra.ai/reference/configuration) to `true` respectively.
|
|
53
|
+
|
|
46
54
|
## Stream data redaction
|
|
47
55
|
|
|
48
56
|
When streaming agent responses, the HTTP layer redacts system prompts, tool definitions, API keys, and similar data from each chunk before sending it to clients. This is enabled by default.
|
|
@@ -82,6 +82,23 @@ export const mastra = new Mastra({
|
|
|
82
82
|
|
|
83
83
|
> **Info:** Visit [Middleware](https://mastra.ai/docs/server/middleware) for how to use server middleware.
|
|
84
84
|
|
|
85
|
+
## Studio
|
|
86
|
+
|
|
87
|
+
When developing locally, you can define named presets in a JSON file and load them into [Studio](https://mastra.ai/docs/studio/overview) with the [`--request-context-presets`](https://mastra.ai/reference/cli/mastra) CLI flag. This adds a dropdown to the request context editor in Studio so you can quickly switch between configurations without manually editing JSON each time.
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
mastra dev --request-context-presets ./presets.json
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"development": { "userId": "dev-user", "env": "development" },
|
|
96
|
+
"production": { "userId": "prod-user", "env": "production" }
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
When you select a preset from the dropdown, the JSON editor populates with that preset's values. Editing the JSON manually switches the dropdown back to **"Custom"**.
|
|
101
|
+
|
|
85
102
|
## Accessing values with agents
|
|
86
103
|
|
|
87
104
|
You can access the `requestContext` argument from any supported configuration options in agents. These functions can be sync or `async`. Use the `.get()` method to read values from `requestContext`.
|
|
@@ -446,23 +463,6 @@ requestContextSchema: z.object({
|
|
|
446
463
|
|
|
447
464
|
**Handle tool validation errors**: Since tools return error objects instead of throwing, check for errors in your agent or workflow logic when tool execution is critical.
|
|
448
465
|
|
|
449
|
-
## Testing with Studio presets
|
|
450
|
-
|
|
451
|
-
When developing locally, you can define named presets in a JSON file and load them into Studio with the [`--request-context-presets`](https://mastra.ai/reference/cli/mastra) CLI flag. This adds a dropdown to the request context editor in Studio so you can quickly switch between configurations without manually editing JSON each time.
|
|
452
|
-
|
|
453
|
-
```bash
|
|
454
|
-
mastra dev --request-context-presets ./presets.json
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
```json
|
|
458
|
-
{
|
|
459
|
-
"development": { "userId": "dev-user", "env": "development" },
|
|
460
|
-
"production": { "userId": "prod-user", "env": "production" }
|
|
461
|
-
}
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
When you select a preset from the dropdown, the JSON editor populates with that preset's values. Editing the JSON manually switches the dropdown back to "Custom".
|
|
465
|
-
|
|
466
466
|
## Related
|
|
467
467
|
|
|
468
468
|
- [Agent Request Context](https://mastra.ai/docs/memory/overview)
|
|
@@ -10,7 +10,7 @@ Server adapters let you run Mastra with your own HTTP server instead of the Hono
|
|
|
10
10
|
|
|
11
11
|
> **Tip:** For deployments without custom server requirements, use `mastra build` instead. It configures server setup, registers middleware, and applies deployment settings based on your project configuration. See [Server Configuration](https://mastra.ai/docs/server/mastra-server).
|
|
12
12
|
>
|
|
13
|
-
> If you want to use [Studio](https://mastra.ai/docs/
|
|
13
|
+
> If you want to use [Studio](https://mastra.ai/docs/studio/overview) with your server adapter, use [`mastra studio`](https://mastra.ai/reference/cli/mastra) to only launch the Studio UI.
|
|
14
14
|
|
|
15
15
|
## Available adapters
|
|
16
16
|
|
|
@@ -553,10 +553,10 @@ See [MCP](https://mastra.ai/docs/mcp/overview) for configuration details and how
|
|
|
553
553
|
|
|
554
554
|
## Related
|
|
555
555
|
|
|
556
|
-
- [Hono Adapter](https://mastra.ai/reference/server/hono-adapter)
|
|
557
|
-
- [Express Adapter](https://mastra.ai/reference/server/express-adapter)
|
|
558
|
-
- [Custom Adapters](https://mastra.ai/docs/server/custom-adapters)
|
|
559
|
-
- [Server Configuration](https://mastra.ai/docs/server/mastra-server)
|
|
560
|
-
- [Authentication](https://mastra.ai/docs/server/auth)
|
|
561
|
-
- [MastraServer Reference](https://mastra.ai/reference/server/mastra-server)
|
|
562
|
-
- [createRoute() Reference](https://mastra.ai/reference/server/create-route)
|
|
556
|
+
- [Hono Adapter](https://mastra.ai/reference/server/hono-adapter): Hono-specific setup
|
|
557
|
+
- [Express Adapter](https://mastra.ai/reference/server/express-adapter): Express-specific setup
|
|
558
|
+
- [Custom Adapters](https://mastra.ai/docs/server/custom-adapters): Building adapters for other frameworks
|
|
559
|
+
- [Server Configuration](https://mastra.ai/docs/server/mastra-server): Using `mastra build` instead
|
|
560
|
+
- [Authentication](https://mastra.ai/docs/server/auth): Configuring auth for your server
|
|
561
|
+
- [MastraServer Reference](https://mastra.ai/reference/server/mastra-server): Full API reference
|
|
562
|
+
- [createRoute() Reference](https://mastra.ai/reference/server/create-route): Creating type-safe custom routes
|
|
@@ -145,93 +145,4 @@ Each progress event includes:
|
|
|
145
145
|
- **`totalCount`**: Total number of iterations
|
|
146
146
|
- **`currentIndex`**: Index of the iteration that completed
|
|
147
147
|
- **`iterationStatus`**: Status of the iteration (`success`, `failed`, or `suspended`)
|
|
148
|
-
- **`iterationOutput`**: Output of the iteration (when successful)
|
|
149
|
-
|
|
150
|
-
## Inspecting agent networks
|
|
151
|
-
|
|
152
|
-
When using multi-agent collaboration with `agent.network()`, iterate over the stream to track how tasks are delegated and executed across agents, workflows, and tools.
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
const networkAgent = mastra.getAgent('networkAgent')
|
|
156
|
-
|
|
157
|
-
const networkStream = await networkAgent.network('Research dolphins then write a report')
|
|
158
|
-
|
|
159
|
-
for await (const chunk of networkStream) {
|
|
160
|
-
console.log(chunk)
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
> **Info:** Visit [Agent.network()](https://mastra.ai/reference/agents/network) for more information.
|
|
165
|
-
|
|
166
|
-
### Example network output
|
|
167
|
-
|
|
168
|
-
Network streams emit events that track the orchestration flow. Each iteration begins with routing, followed by execution of the selected primitive.
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
// Routing agent decides what to do
|
|
172
|
-
{
|
|
173
|
-
type: 'routing-agent-start',
|
|
174
|
-
from: 'NETWORK',
|
|
175
|
-
runId: '7a3b9c2d-1e4f-5a6b-8c9d-0e1f2a3b4c5d',
|
|
176
|
-
payload: {
|
|
177
|
-
agentId: 'routing-agent',
|
|
178
|
-
// ...
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// Routing agent makes a selection
|
|
182
|
-
{
|
|
183
|
-
type: 'routing-agent-end',
|
|
184
|
-
from: 'NETWORK',
|
|
185
|
-
runId: '7a3b9c2d-1e4f-5a6b-8c9d-0e1f2a3b4c5d',
|
|
186
|
-
payload: {
|
|
187
|
-
// ...
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
// Delegated agent begins execution
|
|
191
|
-
{
|
|
192
|
-
type: 'agent-execution-start',
|
|
193
|
-
from: 'NETWORK',
|
|
194
|
-
runId: '8b4c0d3e-2f5a-6b7c-9d0e-1f2a3b4c5d6e',
|
|
195
|
-
payload: {
|
|
196
|
-
// ...
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
// Events from the delegated agent's execution
|
|
200
|
-
{
|
|
201
|
-
type: 'agent-execution-event-text-delta',
|
|
202
|
-
from: 'NETWORK',
|
|
203
|
-
runId: '8b4c0d3e-2f5a-6b7c-9d0e-1f2a3b4c5d6e',
|
|
204
|
-
payload: {
|
|
205
|
-
type: 'text-delta',
|
|
206
|
-
payload: {
|
|
207
|
-
// ...
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
### Filtering network events
|
|
214
|
-
|
|
215
|
-
You can filter events by type to track specific aspects of the network execution:
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
const networkStream = await networkAgent.network('Analyze data and create visualization')
|
|
219
|
-
|
|
220
|
-
for await (const chunk of networkStream) {
|
|
221
|
-
// Track routing decisions
|
|
222
|
-
if (chunk.type === 'routing-agent-end') {
|
|
223
|
-
console.log('Selected:', chunk.payload.resourceType, chunk.payload.resourceId)
|
|
224
|
-
console.log('Reason:', chunk.payload.selectionReason)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Track agent delegations
|
|
228
|
-
if (chunk.type === 'agent-execution-start') {
|
|
229
|
-
console.log('Delegating to agent:', chunk.payload.agentId)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Track workflow delegations
|
|
233
|
-
if (chunk.type === 'workflow-execution-start') {
|
|
234
|
-
console.log('Executing workflow:', chunk.payload.name)
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
```
|
|
148
|
+
- **`iterationOutput`**: Output of the iteration (when successful)
|
|
@@ -64,8 +64,6 @@ const stream = await testAgent.stream([{ role: 'user', content: 'Help me organiz
|
|
|
64
64
|
|
|
65
65
|
// Convert to AI SDK v5+ compatible stream
|
|
66
66
|
const aiSDKStream = toAISdkV5Stream(stream, { from: 'agent' })
|
|
67
|
-
|
|
68
|
-
// Use with AI SDK v5+ methods
|
|
69
67
|
```
|
|
70
68
|
|
|
71
69
|
For converting messages to AI SDK v5+ format, use the `toAISdkV5Messages()` utility from `@mastra/ai-sdk/ui`:
|
|
@@ -77,46 +75,6 @@ const messages = [{ role: 'user', content: 'Hello' }]
|
|
|
77
75
|
const aiSDKMessages = toAISdkV5Messages(messages)
|
|
78
76
|
```
|
|
79
77
|
|
|
80
|
-
### Using `Agent.network()`
|
|
81
|
-
|
|
82
|
-
The `network()` method enables multi-agent collaboration by executing a network loop where multiple agents can work together to handle complex tasks. The routing agent delegates tasks to appropriate subagents, workflows, and tools based on the conversation context.
|
|
83
|
-
|
|
84
|
-
> **Note**: This method is experimental and requires memory to be configured on the agent.
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
const testAgent = mastra.getAgent('testAgent')
|
|
88
|
-
|
|
89
|
-
const networkStream = await testAgent.network('Help me organize my day')
|
|
90
|
-
|
|
91
|
-
for await (const chunk of networkStream) {
|
|
92
|
-
console.log(chunk)
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
> **Info:** Visit [Agent.network()](https://mastra.ai/reference/agents/network) for more information.
|
|
97
|
-
|
|
98
|
-
#### Network stream properties
|
|
99
|
-
|
|
100
|
-
The network stream provides access to execution information:
|
|
101
|
-
|
|
102
|
-
- **`networkStream.status`**: Promise resolving to the workflow execution status
|
|
103
|
-
- **`networkStream.result`**: Promise resolving to the complete execution results
|
|
104
|
-
- **`networkStream.usage`**: Promise resolving to token usage information
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
const testAgent = mastra.getAgent('testAgent')
|
|
108
|
-
|
|
109
|
-
const networkStream = await testAgent.network('Research dolphins then write a report')
|
|
110
|
-
|
|
111
|
-
for await (const chunk of networkStream) {
|
|
112
|
-
console.log(chunk)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
console.log('Final status:', await networkStream.status)
|
|
116
|
-
console.log('Final result:', await networkStream.result)
|
|
117
|
-
console.log('Token usage:', await networkStream.usage)
|
|
118
|
-
```
|
|
119
|
-
|
|
120
78
|
## Streaming with workflows
|
|
121
79
|
|
|
122
80
|
Streaming from a workflow returns a sequence of structured events describing the run lifecycle, rather than incremental text chunks. This event-based format makes it possible to track and respond to workflow progress in real time once a run is created using `.createRun()`.
|