@mastra/mcp-docs-server 1.1.24 → 1.1.25-alpha.3
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/deployment/cloud-providers.md +5 -1
- package/.docs/docs/deployment/overview.md +11 -8
- package/.docs/docs/index.md +2 -2
- package/.docs/docs/mastra-platform/configuration.md +36 -0
- package/.docs/docs/mastra-platform/overview.md +76 -0
- package/.docs/docs/memory/storage.md +0 -2
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/overview.md +1 -1
- package/.docs/docs/observability/tracing/exporters/cloud.md +126 -73
- package/.docs/docs/observability/tracing/exporters/default.md +1 -1
- package/.docs/docs/observability/tracing/overview.md +3 -3
- package/.docs/docs/server/middleware.md +46 -18
- package/.docs/docs/server/request-context.md +12 -1
- package/.docs/docs/studio/deployment.md +24 -6
- package/.docs/docs/studio/observability.md +1 -1
- package/.docs/docs/studio/overview.md +2 -4
- package/.docs/guides/deployment/mastra-platform.md +70 -0
- package/.docs/guides/migrations/mastra-cloud.md +247 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
- package/.docs/reference/cli/mastra.md +140 -0
- package/.docs/reference/client-js/agents.md +0 -14
- package/.docs/reference/configuration.md +4 -1
- package/.docs/reference/index.md +1 -0
- package/.docs/reference/logging/pino-logger.md +0 -2
- package/.docs/reference/mastra-platform/api.md +108 -0
- package/CHANGELOG.md +14 -0
- package/package.json +3 -3
- package/.docs/docs/mastra-cloud/deployment.md +0 -77
- package/.docs/docs/mastra-cloud/observability.md +0 -38
- package/.docs/docs/mastra-cloud/overview.md +0 -23
- package/.docs/docs/mastra-cloud/setup.md +0 -42
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Mastra applications can be deployed to cloud providers and serverless platforms. Mastra includes optional built-in deployers for Vercel, Netlify, and Cloudflare to automate the deployment process.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Mastra platform
|
|
6
|
+
|
|
7
|
+
Mastra provides a platform to deploy your server to the cloud. Read the [Mastra platform deployment guide](https://mastra.ai/guides/deployment/mastra-platform) to learn more.
|
|
8
|
+
|
|
9
|
+
## Cloud providers
|
|
6
10
|
|
|
7
11
|
The following guides show how to deploy Mastra to specific cloud providers:
|
|
8
12
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Deployment overview
|
|
2
2
|
|
|
3
|
-
Mastra applications can be deployed to any Node.js-compatible environment. You can deploy a Mastra server, integrate with an existing web framework, deploy to cloud providers, or use Mastra
|
|
3
|
+
Mastra applications can be deployed to any Node.js-compatible environment. You can deploy a Mastra server, integrate with an existing web framework, deploy to cloud providers, or use [Mastra platform](https://mastra.ai/docs/mastra-platform/overview) for Studio and server deployment.
|
|
4
4
|
|
|
5
5
|
## Runtime support
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ Mastra can run against any of these runtime environments:
|
|
|
13
13
|
|
|
14
14
|
## Deployment options
|
|
15
15
|
|
|
16
|
-
### Mastra
|
|
16
|
+
### Mastra server
|
|
17
17
|
|
|
18
18
|
Mastra provides a [server](https://mastra.ai/docs/server/mastra-server) powered by Hono that can be deployed independently. Use the `mastra build` command to build your application and deploy the output to your preferred VM, container, or PaaS platform.
|
|
19
19
|
|
|
@@ -25,6 +25,15 @@ Deploy a Mastra server as part of a monorepo setup, following the same approach
|
|
|
25
25
|
|
|
26
26
|
Read about [monorepo deployment](https://mastra.ai/docs/deployment/monorepo).
|
|
27
27
|
|
|
28
|
+
### Mastra platform
|
|
29
|
+
|
|
30
|
+
The [Mastra platform](https://mastra.ai/docs/mastra-platform/overview) provides two products for deploying and managing AI applications built with the Mastra framework:
|
|
31
|
+
|
|
32
|
+
- **Studio**: A hosted visual environment for testing agents, running workflows, and inspecting traces
|
|
33
|
+
- **Server**: A production deployment target that runs your Mastra application as an API server
|
|
34
|
+
|
|
35
|
+
Learn more in the [Studio deployment guide](https://mastra.ai/docs/studio/deployment) and [Server deployment guide](https://mastra.ai/guides/deployment/mastra-platform).
|
|
36
|
+
|
|
28
37
|
### Cloud Providers
|
|
29
38
|
|
|
30
39
|
Mastra applications can be deployed to cloud providers and serverless platforms. Mastra includes optional built-in deployers for Vercel, Netlify, and Cloudflare to automate the build and deployment process.
|
|
@@ -49,12 +58,6 @@ Use these guides when adding Mastra to an existing Next.js or Astro application.
|
|
|
49
58
|
- [With Astro on Vercel](https://mastra.ai/docs/deployment/web-framework)
|
|
50
59
|
- [With Astro on Netlify](https://mastra.ai/docs/deployment/web-framework)
|
|
51
60
|
|
|
52
|
-
### Mastra Cloud
|
|
53
|
-
|
|
54
|
-
We're building Mastra Cloud to be the easiest place to deploy and observe your Mastra agents. It's currently in beta.
|
|
55
|
-
|
|
56
|
-
Learn more in the [Mastra Cloud docs](https://mastra.ai/docs/mastra-cloud/overview).
|
|
57
|
-
|
|
58
61
|
## Workflow runners
|
|
59
62
|
|
|
60
63
|
Mastra workflows run using the built-in execution engine by default. For production workloads requiring managed infrastructure, workflows can also be deployed to specialized platforms like [Inngest](https://www.inngest.com) that provide step memoization, automatic retries, and real-time monitoring.
|
package/.docs/docs/index.md
CHANGED
|
@@ -4,7 +4,7 @@ Build AI agents your users actually depend on. Mastra is a TypeScript framework
|
|
|
4
4
|
|
|
5
5
|
## Quickstart
|
|
6
6
|
|
|
7
|
-
Run this command to create a new project
|
|
7
|
+
Run this command to create a new project:
|
|
8
8
|
|
|
9
9
|
**npm**:
|
|
10
10
|
|
|
@@ -30,7 +30,7 @@ yarn create mastra
|
|
|
30
30
|
bunx create-mastra
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
See the [quickstart guide](https://mastra.ai/guides/getting-started/quickstart) for a full walkthrough.
|
|
33
|
+
You can open [Studio](https://mastra.ai/docs/studio/overview) immediately, which is an interactive UI for your Mastra project. See the [quickstart guide](https://mastra.ai/guides/getting-started/quickstart) for a full walkthrough.
|
|
34
34
|
|
|
35
35
|
## Integrate with your framework
|
|
36
36
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
When you deploy to the Mastra platform, the CLI generates a `.mastra-project.json` config file and reads environment variables from your local `.env` files.
|
|
4
|
+
|
|
5
|
+
This page explains both mechanisms and how they differ between Studio and Server deployments.
|
|
6
|
+
|
|
7
|
+
## Project config
|
|
8
|
+
|
|
9
|
+
The `.mastra-project.json` file is auto-generated on your first Studio or Server deploy. It links your local project to a platform project.
|
|
10
|
+
|
|
11
|
+
Commit it to your version control so that subsequent deploys (including from CI) target the correct project.
|
|
12
|
+
|
|
13
|
+
Your file will look something like this:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"projectId": "06daaac4-89b1-40f0-9e3f-0993e039a627",
|
|
18
|
+
"projectName": "my-project",
|
|
19
|
+
"organizationId": "org_01KNA5YSP52SX4M6YVSXC2MAHP"
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
| Field | Description |
|
|
24
|
+
| -------------- | ---------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| projectId | UUID for the project. Assigned when the project is created. |
|
|
26
|
+
| projectName | Human-readable project name. Used as a display label in the dashboard and CLI output. |
|
|
27
|
+
| organizationId | The organization that owns the project. All deploys, API keys, and resources are scoped to this org. |
|
|
28
|
+
|
|
29
|
+
## Environment variables
|
|
30
|
+
|
|
31
|
+
The CLI reads from `.env` and `.env.local` files in your project directory during deploy. Variables from `.env.local` override those in `.env`.
|
|
32
|
+
|
|
33
|
+
You can set environment variables like so:
|
|
34
|
+
|
|
35
|
+
- **Studio**: Environment variables are read from your local `.env` files and bundled into the deploy artifact. To update them, redeploy.
|
|
36
|
+
- **Server**: On the first deploy, the CLI automatically seeds environment variables from your local `.env` files. After that, manage them per-project through the dashboard or API.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Mastra platform
|
|
2
|
+
|
|
3
|
+
The Mastra platform provides two products for deploying and managing AI applications built with the Mastra framework:
|
|
4
|
+
|
|
5
|
+
- **Studio**: A hosted visual environment for testing agents, running workflows, and inspecting traces
|
|
6
|
+
- **Server**: A production deployment target that runs your Mastra application as an API server
|
|
7
|
+
|
|
8
|
+
## Quickstart
|
|
9
|
+
|
|
10
|
+
Before you begin, ensure you have Node.js 22.13.0 or later installed.
|
|
11
|
+
|
|
12
|
+
1. Follow the [get started guide](https://mastra.ai/docs) to create your first Mastra project.
|
|
13
|
+
|
|
14
|
+
2. Install the `mastra` CLI globally:
|
|
15
|
+
|
|
16
|
+
**npm**:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g mastra
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**pnpm**:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add -g mastra
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Yarn**:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
yarn global add mastra
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Bun**:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun add --global mastra
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. Deploy Studio with a single command:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
mastra studio deploy
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
On a successful deploy, the CLI will output the URL of your deployed Studio instance.
|
|
47
|
+
|
|
48
|
+
4. Deploy Server with a single command:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
mastra server deploy
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
On a successful deploy, the CLI will output the URL of your deployed Server instance.
|
|
55
|
+
|
|
56
|
+
You have now successfully deployed both Studio and Server instances of your Mastra application. The CLI created a `.mastra-project.json` file in your project directory.
|
|
57
|
+
|
|
58
|
+
This file links your local project to a platform project. It's auto-generated on your first deploy and contains the `projectId`, `projectName`, and `organizationId`. Commit this file to your repository so CI/CD knows which project to deploy to.
|
|
59
|
+
|
|
60
|
+
## Key Concepts
|
|
61
|
+
|
|
62
|
+
**Projects** are the shared parent entity across all products. A single project can have a Studio deployment and a Server deployment. Projects belong to an **Organization**, which is the multi-tenant container for your team.
|
|
63
|
+
|
|
64
|
+
Your Mastra application is built from three building blocks:
|
|
65
|
+
|
|
66
|
+
- [Agents](https://mastra.ai/docs/agents/overview): AI agents that can use tools, follow instructions, and maintain context
|
|
67
|
+
- [Tools](https://mastra.ai/docs/agents/using-tools): Callable functions and integrations available to your agents
|
|
68
|
+
- [Workflows](https://mastra.ai/docs/workflows/overview): Multi-step orchestration pipelines that coordinate agents and tools
|
|
69
|
+
|
|
70
|
+
## Going to production
|
|
71
|
+
|
|
72
|
+
Develop your project locally with [`mastra dev`](https://mastra.ai/reference/cli/mastra) and open [Studio](https://mastra.ai/docs/studio/overview) to test your agents, workflows, and tools in a visual environment.
|
|
73
|
+
|
|
74
|
+
Once you're ready to deploy your application to production, use [`mastra studio deploy`](https://mastra.ai/reference/cli/mastra) and [`mastra server deploy`](https://mastra.ai/reference/cli/mastra) to push your application to the cloud.
|
|
75
|
+
|
|
76
|
+
Follow the [Studio deployment guide](https://mastra.ai/docs/studio/deployment) and [Server deployment guide](https://mastra.ai/guides/deployment/mastra-platform) for step-by-step instructions.
|
|
@@ -118,8 +118,6 @@ export const agent = new Agent({
|
|
|
118
118
|
})
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
> **Warning:** Agent-level storage isn't supported when using [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment). If you use Mastra Cloud Store, configure storage on the Mastra instance instead. This limitation doesn't apply if you bring your own database.
|
|
122
|
-
|
|
123
121
|
## Threads and resources
|
|
124
122
|
|
|
125
123
|
Mastra organizes conversations using two identifiers:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Mastra's logging system captures function execution, input data, and output responses in a structured format.
|
|
4
4
|
|
|
5
|
-
When deploying to Mastra
|
|
5
|
+
When deploying to the Mastra platform, logs are shown in the dashboard. In self-hosted or custom environments, logs can be directed to files or external services depending on the configured transports.
|
|
6
6
|
|
|
7
7
|
## Configuring logs with `PinoLogger`
|
|
8
8
|
|
|
@@ -83,7 +83,7 @@ export const mastra = new Mastra({
|
|
|
83
83
|
serviceName: 'mastra',
|
|
84
84
|
exporters: [
|
|
85
85
|
new DefaultExporter(), // Persists traces to storage for Mastra Studio
|
|
86
|
-
new CloudExporter(), // Sends
|
|
86
|
+
new CloudExporter(), // Sends observability data to Mastra platform (if MASTRA_CLOUD_ACCESS_TOKEN is set)
|
|
87
87
|
],
|
|
88
88
|
spanOutputProcessors: [
|
|
89
89
|
new SensitiveDataFilter(), // Redacts sensitive data like passwords, tokens, keys
|
|
@@ -1,32 +1,85 @@
|
|
|
1
1
|
# Cloud exporter
|
|
2
2
|
|
|
3
|
-
The `CloudExporter` sends traces
|
|
3
|
+
The `CloudExporter` sends traces, logs, metrics, scores, and feedback to the Mastra platform. Use it to route observability data from any Mastra app to a hosted project in the Mastra platform.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quickstart
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
To connect `CloudExporter`, create an access token, find the destination `projectId`, and add the exporter to your observability config.
|
|
8
8
|
|
|
9
|
-
1.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
### 1. Create an access token
|
|
10
|
+
|
|
11
|
+
Run the following command:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
mastra auth tokens create exporter-token
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This command prints a token secret that you can use as `MASTRA_CLOUD_ACCESS_TOKEN`.
|
|
18
|
+
|
|
19
|
+
If you already have a Mastra Cloud access token, copy the **Observability** value from Mastra Cloud instead. You can find it in either of these places:
|
|
20
|
+
|
|
21
|
+
- On the **Projects** page, open the project list and find the **Observability** row on the project card.
|
|
22
|
+
- On the project **Overview** page, find the **Observability** row directly below the deployment URL.
|
|
23
|
+
|
|
24
|
+
Set the token as an environment variable:
|
|
13
25
|
|
|
14
26
|
```bash
|
|
15
|
-
MASTRA_CLOUD_ACCESS_TOKEN
|
|
27
|
+
MASTRA_CLOUD_ACCESS_TOKEN=<your-cloud-access-token>
|
|
16
28
|
```
|
|
17
29
|
|
|
18
|
-
|
|
30
|
+
### 2. Find your `projectId`
|
|
31
|
+
|
|
32
|
+
Run the following command:
|
|
19
33
|
|
|
20
34
|
```bash
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
mastra studio deploy list
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The output looks similar to this:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
✅ <your-project-name> (<your-project-id>)
|
|
42
|
+
Latest: 00000000-0000-0000-0000-000000000000 — running
|
|
43
|
+
URL: https://260407.studio.mastra.cloud
|
|
23
44
|
```
|
|
24
45
|
|
|
25
|
-
|
|
46
|
+
In this output, the value in parentheses is the `projectId`:
|
|
26
47
|
|
|
27
|
-
|
|
48
|
+
```text
|
|
49
|
+
<your-project-id>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Set it as an environment variable:
|
|
28
53
|
|
|
29
|
-
```
|
|
54
|
+
```bash
|
|
55
|
+
MASTRA_PROJECT_ID=<your-project-id>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Set your environment variables
|
|
59
|
+
|
|
60
|
+
Tokens created with `mastra auth tokens create` are organization-scoped, so `MASTRA_PROJECT_ID` is required.
|
|
61
|
+
|
|
62
|
+
If you use a project-scoped token from Mastra Cloud instead, `CloudExporter` can route without `projectId`, but setting it explicitly is still supported.
|
|
63
|
+
|
|
64
|
+
Add both values to your environment:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
MASTRA_CLOUD_ACCESS_TOKEN=<your-cloud-access-token>
|
|
68
|
+
MASTRA_PROJECT_ID=<your-project-id>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
For example:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
MASTRA_CLOUD_ACCESS_TOKEN=<your-cloud-access-token>
|
|
75
|
+
MASTRA_PROJECT_ID=<your-project-id>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 4. Enable `CloudExporter`
|
|
79
|
+
|
|
80
|
+
The following example demonstrates how to add `CloudExporter` to your observability config:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
30
83
|
import { Mastra } from '@mastra/core'
|
|
31
84
|
import { Observability, CloudExporter } from '@mastra/observability'
|
|
32
85
|
|
|
@@ -36,7 +89,10 @@ export const mastra = new Mastra({
|
|
|
36
89
|
production: {
|
|
37
90
|
serviceName: 'my-service',
|
|
38
91
|
exporters: [
|
|
39
|
-
new CloudExporter(
|
|
92
|
+
new CloudExporter({
|
|
93
|
+
accessToken: process.env.MASTRA_CLOUD_ACCESS_TOKEN,
|
|
94
|
+
projectId: process.env.MASTRA_PROJECT_ID,
|
|
95
|
+
}),
|
|
40
96
|
],
|
|
41
97
|
},
|
|
42
98
|
},
|
|
@@ -44,24 +100,45 @@ export const mastra = new Mastra({
|
|
|
44
100
|
})
|
|
45
101
|
```
|
|
46
102
|
|
|
47
|
-
|
|
103
|
+
Set `serviceName` in code on the observability config, not on `CloudExporter` itself. In the example above, the value is `configs.production.serviceName`.
|
|
48
104
|
|
|
49
|
-
|
|
105
|
+
For example:
|
|
50
106
|
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
107
|
+
```ts
|
|
108
|
+
import { Mastra } from '@mastra/core'
|
|
109
|
+
import { Observability, CloudExporter } from '@mastra/observability'
|
|
110
|
+
|
|
111
|
+
export const mastra = new Mastra({
|
|
112
|
+
observability: new Observability({
|
|
113
|
+
configs: {
|
|
114
|
+
production: {
|
|
115
|
+
serviceName: 'api-server',
|
|
116
|
+
exporters: [new CloudExporter()],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
55
120
|
})
|
|
56
121
|
```
|
|
57
122
|
|
|
58
|
-
|
|
123
|
+
Use a stable `serviceName` value. In Studio, traces can be filtered by **Deployments → Service Name**, so a consistent name makes traces easier to find.
|
|
124
|
+
|
|
125
|
+
Visit [Observability configuration reference](https://mastra.ai/reference/observability/tracing/configuration) for the full observability config shape.
|
|
126
|
+
|
|
127
|
+
If you prefer, rely entirely on environment variables:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
new CloudExporter()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
With `MASTRA_CLOUD_ACCESS_TOKEN` and `MASTRA_PROJECT_ID` set, `CloudExporter` automatically sends data to the correct Mastra Cloud project.
|
|
59
134
|
|
|
60
|
-
|
|
135
|
+
> **Note:** Visit [CloudExporter reference](https://mastra.ai/reference/observability/tracing/exporters/cloud-exporter) for the full list of configuration options.
|
|
61
136
|
|
|
62
|
-
|
|
137
|
+
## Recommended configuration
|
|
63
138
|
|
|
64
|
-
|
|
139
|
+
Include `DefaultExporter` if you also want to inspect local traces in Studio or persist observability data to your configured storage.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
65
142
|
import { Mastra } from '@mastra/core'
|
|
66
143
|
import {
|
|
67
144
|
Observability,
|
|
@@ -75,10 +152,7 @@ export const mastra = new Mastra({
|
|
|
75
152
|
configs: {
|
|
76
153
|
default: {
|
|
77
154
|
serviceName: 'mastra',
|
|
78
|
-
exporters: [
|
|
79
|
-
new DefaultExporter(),
|
|
80
|
-
new CloudExporter(), // Sends traces to Mastra Cloud (requires MASTRA_CLOUD_ACCESS_TOKEN)
|
|
81
|
-
],
|
|
155
|
+
exporters: [new DefaultExporter(), new CloudExporter()],
|
|
82
156
|
spanOutputProcessors: [new SensitiveDataFilter()],
|
|
83
157
|
},
|
|
84
158
|
},
|
|
@@ -86,68 +160,47 @@ export const mastra = new Mastra({
|
|
|
86
160
|
})
|
|
87
161
|
```
|
|
88
162
|
|
|
89
|
-
|
|
163
|
+
## Complete configuration
|
|
164
|
+
|
|
165
|
+
The following example demonstrates how to configure custom endpoints and batching behavior:
|
|
90
166
|
|
|
91
|
-
```
|
|
167
|
+
```ts
|
|
92
168
|
new CloudExporter({
|
|
93
|
-
// Optional - defaults to env var
|
|
94
169
|
accessToken: process.env.MASTRA_CLOUD_ACCESS_TOKEN,
|
|
95
|
-
|
|
96
|
-
// Optional - required for organization API keys or any project-scoped collector route
|
|
97
|
-
// Letters, numbers, hyphens, and underscores only
|
|
98
170
|
projectId: process.env.MASTRA_PROJECT_ID,
|
|
99
|
-
|
|
100
|
-
// Optional - for self-hosted Mastra Cloud
|
|
101
171
|
endpoint: 'https://cloud.your-domain.com',
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
maxBatchWaitMs: 5000, // Max wait before sending batch
|
|
106
|
-
|
|
107
|
-
// Diagnostic logging
|
|
108
|
-
logLevel: 'info', // debug | info | warn | error
|
|
172
|
+
maxBatchSize: 1000,
|
|
173
|
+
maxBatchWaitMs: 5000,
|
|
174
|
+
logLevel: 'info',
|
|
109
175
|
})
|
|
110
176
|
```
|
|
111
177
|
|
|
112
|
-
## Viewing
|
|
113
|
-
|
|
114
|
-
### Mastra Cloud Dashboard
|
|
115
|
-
|
|
116
|
-
1. Navigate to [cloud.mastra.ai](https://cloud.mastra.ai)
|
|
117
|
-
|
|
118
|
-
2. Select the project associated with your access token
|
|
119
|
-
|
|
120
|
-
3. Go to **Observability → Traces**
|
|
121
|
-
|
|
122
|
-
4. Use filters to find specific traces:
|
|
178
|
+
## Viewing data in Mastra Cloud
|
|
123
179
|
|
|
124
|
-
|
|
125
|
-
- Time range
|
|
126
|
-
- Trace ID
|
|
127
|
-
- Error status
|
|
180
|
+
After you enable `CloudExporter`, open your project in [Mastra Cloud](https://cloud.mastra.ai) to inspect the exported data.
|
|
128
181
|
|
|
129
|
-
|
|
182
|
+
- Open your project and select **Open Studio**.
|
|
183
|
+
- In Studio, go to **Traces** to inspect agent and workflow traces.
|
|
184
|
+
- Open the filter menu and use **Deployments → Service Name** to isolate traces from a specific app or deployment.
|
|
185
|
+
- Use the **Logs** page in the project dashboard to inspect exported logs.
|
|
186
|
+
- Use the project named by `MASTRA_PROJECT_ID` when you work with organization-scoped tokens.
|
|
130
187
|
|
|
131
|
-
|
|
188
|
+
> **Note:** If you use a project-scoped token, open the project that issued the token. If you use an organization-scoped token, open the project named by `MASTRA_PROJECT_ID`.
|
|
132
189
|
|
|
133
|
-
|
|
134
|
-
- **Span Details** - Inputs, outputs, metadata
|
|
135
|
-
- **Performance Metrics** - Latency, token usage
|
|
136
|
-
- **Team Collaboration** - Share trace links
|
|
190
|
+
When you deploy with Mastra Cloud, set **Deployment → Service Name** to a stable value and keep it aligned with the `serviceName` in your observability config. This makes traces easier to filter in Studio through **Deployments → Service Name** when multiple services or deployments send data to the same project.
|
|
137
191
|
|
|
138
192
|
## Performance
|
|
139
193
|
|
|
140
|
-
> **Info:** CloudExporter uses
|
|
194
|
+
> **Info:** CloudExporter uses batching to optimize network usage. Events are buffered and sent in batches, reducing overhead while maintaining near real-time visibility.
|
|
141
195
|
|
|
142
|
-
### Batching
|
|
196
|
+
### Batching behavior
|
|
143
197
|
|
|
144
|
-
-
|
|
145
|
-
- Batches are sent when full or after `maxBatchWaitMs` (default: 5 seconds)
|
|
146
|
-
- Failed batches are retried with exponential backoff
|
|
147
|
-
-
|
|
198
|
+
- Events are batched up to `maxBatchSize` (default: 1000).
|
|
199
|
+
- Batches are sent when full or after `maxBatchWaitMs` (default: 5 seconds).
|
|
200
|
+
- Failed batches are retried with exponential backoff.
|
|
201
|
+
- The exporter degrades gracefully if Mastra Cloud is unreachable.
|
|
148
202
|
|
|
149
203
|
## Related
|
|
150
204
|
|
|
151
205
|
- [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview)
|
|
152
|
-
- [DefaultExporter](https://mastra.ai/docs/observability/tracing/exporters/default)
|
|
153
|
-
- [Mastra Cloud Documentation](https://mastra.ai/docs/mastra-cloud/overview)
|
|
206
|
+
- [DefaultExporter](https://mastra.ai/docs/observability/tracing/exporters/default)
|
|
@@ -59,7 +59,7 @@ export const mastra = new Mastra({
|
|
|
59
59
|
serviceName: 'mastra',
|
|
60
60
|
exporters: [
|
|
61
61
|
new DefaultExporter(), // Persists traces to storage for Studio
|
|
62
|
-
new CloudExporter(), // Sends
|
|
62
|
+
new CloudExporter(), // Sends observability data to Mastra platform (requires MASTRA_CLOUD_ACCESS_TOKEN)
|
|
63
63
|
],
|
|
64
64
|
spanOutputProcessors: [new SensitiveDataFilter()],
|
|
65
65
|
},
|
|
@@ -32,7 +32,7 @@ export const mastra = new Mastra({
|
|
|
32
32
|
serviceName: 'mastra',
|
|
33
33
|
exporters: [
|
|
34
34
|
new DefaultExporter(), // Persists traces to storage for Studio
|
|
35
|
-
new CloudExporter(), // Sends
|
|
35
|
+
new CloudExporter(), // Sends observability data to Mastra platform (if MASTRA_CLOUD_ACCESS_TOKEN is set)
|
|
36
36
|
],
|
|
37
37
|
spanOutputProcessors: [
|
|
38
38
|
new SensitiveDataFilter(), // Redacts sensitive data like passwords, tokens, keys
|
|
@@ -56,7 +56,7 @@ This configuration includes:
|
|
|
56
56
|
- **Exporters**:
|
|
57
57
|
|
|
58
58
|
- `DefaultExporter` - Persists traces to your configured storage for Studio
|
|
59
|
-
- `CloudExporter` - Sends
|
|
59
|
+
- `CloudExporter` - Sends observability data to Mastra platform (requires `MASTRA_CLOUD_ACCESS_TOKEN`)
|
|
60
60
|
|
|
61
61
|
- **Span Output Processors**: `SensitiveDataFilter` - Redacts sensitive fields
|
|
62
62
|
|
|
@@ -69,7 +69,7 @@ Exporters determine where your trace data is sent and how it's stored. They inte
|
|
|
69
69
|
Mastra provides two built-in exporters:
|
|
70
70
|
|
|
71
71
|
- **[Default](https://mastra.ai/docs/observability/tracing/exporters/default)** - Persists traces to local storage for viewing in Studio
|
|
72
|
-
- **[Cloud](https://mastra.ai/docs/observability/tracing/exporters/cloud)** - Sends
|
|
72
|
+
- **[Cloud](https://mastra.ai/docs/observability/tracing/exporters/cloud)** - Sends observability data to Mastra platform for production monitoring and collaboration
|
|
73
73
|
|
|
74
74
|
### External Exporters
|
|
75
75
|
|
|
@@ -97,22 +97,62 @@ export const mastra = new Mastra({
|
|
|
97
97
|
|
|
98
98
|
### Authorization (User Isolation)
|
|
99
99
|
|
|
100
|
-
Authentication verifies who the user is. Authorization controls what they can access. Without
|
|
100
|
+
Authentication verifies who the user is. Authorization controls what they can access. Without resource ID scoping, an authenticated user could access other users' threads by guessing IDs or manipulating the `resourceId` parameter.
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
The simplest way to scope memory and threads to the authenticated user is the `mapUserToResourceId` callback in the auth config:
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
105
|
import { Mastra } from '@mastra/core'
|
|
106
|
-
import { MASTRA_RESOURCE_ID_KEY } from '@mastra/core/request-context'
|
|
107
|
-
import { getAuthenticatedUser } from '@mastra/server/auth'
|
|
108
106
|
|
|
109
107
|
export const mastra = new Mastra({
|
|
110
108
|
server: {
|
|
111
109
|
auth: {
|
|
112
110
|
authenticateToken: async token => {
|
|
113
|
-
//
|
|
114
|
-
return verifyToken(token) // { id: 'user-123', ... }
|
|
111
|
+
return verifyToken(token) // { id: 'user-123', orgId: 'org-456', ... }
|
|
115
112
|
},
|
|
113
|
+
mapUserToResourceId: user => user.id,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
After successful authentication, `mapUserToResourceId` is called with the authenticated user object. The returned value is set as `MASTRA_RESOURCE_ID_KEY` on the request context, which works across all server adapters (Hono, Express, Next.js, etc.).
|
|
120
|
+
|
|
121
|
+
The resource ID doesn't have to be `user.id`. Common patterns:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Org-scoped
|
|
125
|
+
mapUserToResourceId: user => `${user.orgId}:${user.id}`
|
|
126
|
+
|
|
127
|
+
// From a JWT claim
|
|
128
|
+
mapUserToResourceId: user => user.tenantId
|
|
129
|
+
|
|
130
|
+
// Composite key
|
|
131
|
+
mapUserToResourceId: user => `${user.workspaceId}:${user.projectId}:${user.id}`
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
With a resource ID set, the server automatically:
|
|
135
|
+
|
|
136
|
+
- **Filters thread listing** to only return threads owned by the user
|
|
137
|
+
- **Validates thread access** and returns 403 if accessing another user's thread
|
|
138
|
+
- **Forces thread creation** to use the authenticated user's ID
|
|
139
|
+
- **Validates message operations** including deletion, ensuring messages belong to owned threads
|
|
140
|
+
|
|
141
|
+
Even if a client passes `?resourceId=other-user-id`, the auth-set value takes precedence. Attempts to access threads or messages owned by other users will return a 403 error.
|
|
142
|
+
|
|
143
|
+
#### Advanced: Setting resource ID in middleware
|
|
144
|
+
|
|
145
|
+
For more complex scenarios (e.g., looking up the resource ID from a database), you can set `MASTRA_RESOURCE_ID_KEY` directly in middleware:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { Mastra } from '@mastra/core'
|
|
149
|
+
import { MASTRA_RESOURCE_ID_KEY } from '@mastra/core/request-context'
|
|
150
|
+
import { getAuthenticatedUser } from '@mastra/server/auth'
|
|
151
|
+
|
|
152
|
+
export const mastra = new Mastra({
|
|
153
|
+
server: {
|
|
154
|
+
auth: {
|
|
155
|
+
authenticateToken: async token => verifyToken(token),
|
|
116
156
|
},
|
|
117
157
|
middleware: [
|
|
118
158
|
{
|
|
@@ -134,10 +174,7 @@ export const mastra = new Mastra({
|
|
|
134
174
|
return c.json({ error: 'Unauthorized' }, 401)
|
|
135
175
|
}
|
|
136
176
|
|
|
137
|
-
// Force all API operations to use this user's ID
|
|
138
|
-
// This takes precedence over any client-provided resourceId
|
|
139
177
|
requestContext.set(MASTRA_RESOURCE_ID_KEY, user.id)
|
|
140
|
-
|
|
141
178
|
return next()
|
|
142
179
|
},
|
|
143
180
|
},
|
|
@@ -148,15 +185,6 @@ export const mastra = new Mastra({
|
|
|
148
185
|
|
|
149
186
|
`server.middleware` runs before Mastra's per-route auth checks. When middleware needs the authenticated user, call `getAuthenticatedUser()` to resolve it from the configured auth provider without changing the default route auth flow.
|
|
150
187
|
|
|
151
|
-
With this middleware, the server automatically:
|
|
152
|
-
|
|
153
|
-
- **Filters thread listing** to only return threads owned by the user
|
|
154
|
-
- **Validates thread access** and returns 403 if accessing another user's thread
|
|
155
|
-
- **Forces thread creation** to use the authenticated user's ID
|
|
156
|
-
- **Validates message operations** including deletion, ensuring messages belong to owned threads
|
|
157
|
-
|
|
158
|
-
Even if a client passes `?resourceId=other-user-id`, the middleware-set value takes precedence. Attempts to access threads or messages owned by other users will return a 403 error.
|
|
159
|
-
|
|
160
188
|
#### Using `MASTRA_THREAD_ID_KEY`
|
|
161
189
|
|
|
162
190
|
You can also set `MASTRA_THREAD_ID_KEY` to override the client-provided thread ID:
|
|
@@ -234,7 +234,18 @@ export const weatherTool = createTool({
|
|
|
234
234
|
|
|
235
235
|
## Reserved keys
|
|
236
236
|
|
|
237
|
-
Mastra reserves special context keys for security purposes. When set
|
|
237
|
+
Mastra reserves special context keys for security purposes. When set, these keys take precedence over client-provided values. The server automatically validates ownership and returns 403 errors when users attempt to access resources they don't own.
|
|
238
|
+
|
|
239
|
+
The easiest way to set `MASTRA_RESOURCE_ID_KEY` is via the `mapUserToResourceId` callback in auth config:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
auth: {
|
|
243
|
+
authenticateToken: async token => verifyToken(token),
|
|
244
|
+
mapUserToResourceId: user => user.id,
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
You can also set these keys manually in middleware:
|
|
238
249
|
|
|
239
250
|
```typescript
|
|
240
251
|
import { MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from '@mastra/core/request-context'
|