@mastra/mcp-docs-server 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012
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/adding-voice.md +18 -17
- package/.docs/docs/agents/background-tasks.md +242 -0
- package/.docs/docs/agents/channels.md +2 -1
- package/.docs/docs/agents/overview.md +4 -0
- package/.docs/docs/agents/processors.md +177 -5
- package/.docs/docs/agents/structured-output.md +66 -1
- package/.docs/docs/agents/supervisor-agents.md +65 -0
- package/.docs/docs/agents/using-tools.md +73 -0
- package/.docs/docs/browser/agent-browser.md +78 -0
- package/.docs/docs/browser/browser-viewer.md +144 -0
- package/.docs/docs/browser/overview.md +168 -0
- package/.docs/docs/browser/stagehand.md +129 -0
- package/.docs/docs/deployment/cloud-providers.md +5 -1
- package/.docs/docs/deployment/mastra-server.md +4 -4
- package/.docs/docs/deployment/monorepo.md +3 -3
- package/.docs/docs/deployment/overview.md +11 -8
- package/.docs/docs/editor/overview.md +290 -0
- package/.docs/docs/editor/prompts.md +134 -0
- package/.docs/docs/editor/tools.md +152 -0
- package/.docs/docs/evals/custom-scorers.md +63 -3
- package/.docs/docs/evals/datasets/overview.md +1 -1
- package/.docs/docs/index.md +2 -2
- package/.docs/docs/mastra-platform/configuration.md +36 -0
- package/.docs/docs/mastra-platform/overview.md +78 -0
- package/.docs/docs/mcp/overview.md +17 -0
- package/.docs/docs/memory/memory-processors.md +3 -3
- package/.docs/docs/memory/message-history.md +8 -2
- package/.docs/docs/memory/observational-memory.md +65 -8
- package/.docs/docs/memory/storage.md +1 -2
- package/.docs/docs/memory/working-memory.md +2 -2
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/metrics/overview.md +2 -2
- package/.docs/docs/observability/overview.md +1 -1
- package/.docs/docs/observability/tracing/bridges/datadog.md +217 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +2 -2
- package/.docs/docs/observability/tracing/exporters/arthur.md +163 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +135 -63
- package/.docs/docs/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/docs/observability/tracing/exporters/default.md +5 -5
- package/.docs/docs/observability/tracing/exporters/laminar.md +22 -14
- package/.docs/docs/observability/tracing/exporters/langfuse.md +50 -33
- package/.docs/docs/observability/tracing/overview.md +87 -20
- package/.docs/docs/server/custom-adapters.md +5 -5
- package/.docs/docs/server/custom-api-routes.md +3 -3
- package/.docs/docs/server/mastra-client.md +2 -2
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/server/middleware.md +46 -42
- package/.docs/docs/server/request-context.md +13 -2
- package/.docs/docs/server/server-adapters.md +91 -8
- package/.docs/docs/streaming/background-task-streaming.md +80 -0
- package/.docs/docs/streaming/overview.md +3 -0
- package/.docs/docs/studio/deployment.md +24 -6
- package/.docs/docs/studio/observability.md +1 -1
- package/.docs/docs/studio/overview.md +4 -4
- package/.docs/docs/voice/overview.md +74 -5
- package/.docs/docs/voice/speech-to-speech.md +45 -1
- package/.docs/docs/voice/speech-to-text.md +7 -7
- package/.docs/docs/voice/text-to-speech.md +10 -10
- package/.docs/docs/workflows/agents-and-tools.md +1 -1
- package/.docs/docs/workflows/overview.md +105 -4
- package/.docs/docs/workflows/scheduled-workflows.md +181 -0
- package/.docs/docs/workspace/filesystem.md +64 -6
- package/.docs/docs/workspace/lsp.md +76 -4
- package/.docs/docs/workspace/overview.md +62 -15
- package/.docs/docs/workspace/sandbox.md +3 -1
- package/.docs/docs/workspace/search.md +41 -2
- package/.docs/docs/workspace/skills.md +19 -19
- package/.docs/guides/agent-frameworks/ai-sdk.md +4 -4
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +56 -9
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/guides/deployment/mastra-platform.md +191 -0
- package/.docs/guides/deployment/netlify.md +16 -1
- package/.docs/guides/getting-started/nestjs.md +238 -0
- package/.docs/guides/getting-started/next-js.md +0 -4
- package/.docs/guides/guide/code-review-bot.md +2 -2
- package/.docs/guides/guide/dev-assistant.md +4 -4
- package/.docs/{docs/mcp → guides/guide}/publishing-mcp-server.md +21 -1
- package/.docs/guides/guide/slack-assistant.md +191 -0
- package/.docs/guides/migrations/mastra-cloud.md +368 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
- package/.docs/models/embeddings.md +3 -3
- package/.docs/models/gateways/azure-openai.md +74 -35
- package/.docs/models/gateways/mastra.md +64 -0
- package/.docs/models/gateways/netlify.md +7 -3
- package/.docs/models/gateways/openrouter.md +28 -12
- package/.docs/models/gateways/vercel.md +22 -2
- package/.docs/models/gateways.md +1 -0
- package/.docs/models/index.md +43 -8
- package/.docs/models/providers/302ai.md +37 -4
- package/.docs/models/providers/abliteration-ai.md +71 -0
- package/.docs/models/providers/alibaba-cn.md +8 -2
- package/.docs/models/providers/alibaba-coding-plan-cn.md +3 -2
- package/.docs/models/providers/alibaba-coding-plan.md +3 -2
- package/.docs/models/providers/alibaba.md +8 -1
- package/.docs/models/providers/anthropic.md +18 -5
- package/.docs/models/providers/baseten.md +3 -1
- package/.docs/models/providers/berget.md +10 -12
- package/.docs/models/providers/chutes.md +4 -2
- package/.docs/models/providers/cloudflare-workers-ai.md +14 -48
- package/.docs/models/providers/cortecs.md +22 -2
- package/.docs/models/providers/deepinfra.md +8 -2
- package/.docs/models/providers/deepseek.md +6 -4
- package/.docs/models/providers/digitalocean.md +133 -0
- package/.docs/models/providers/fireworks-ai.md +6 -1
- package/.docs/models/providers/firmware.md +12 -10
- package/.docs/models/providers/friendli.md +6 -7
- package/.docs/models/providers/google.md +9 -3
- package/.docs/models/providers/helicone.md +1 -2
- package/.docs/models/providers/hpc-ai.md +73 -0
- package/.docs/models/providers/huggingface.md +6 -2
- package/.docs/models/providers/inception.md +9 -11
- package/.docs/models/providers/kilo.md +359 -339
- package/.docs/models/providers/kimi-for-coding.md +2 -1
- package/.docs/models/providers/llmgateway.md +67 -77
- package/.docs/models/providers/mistral.md +3 -2
- package/.docs/models/providers/mixlayer.md +75 -0
- package/.docs/models/providers/moonshotai-cn.md +3 -2
- package/.docs/models/providers/moonshotai.md +3 -2
- package/.docs/models/providers/nano-gpt.md +8 -2
- package/.docs/models/providers/neuralwatt.md +84 -0
- package/.docs/models/providers/novita-ai.md +19 -4
- package/.docs/models/providers/nvidia.md +8 -1
- package/.docs/models/providers/ollama-cloud.md +7 -2
- package/.docs/models/providers/openai.md +7 -2
- package/.docs/models/providers/opencode-go.md +21 -13
- package/.docs/models/providers/opencode.md +11 -4
- package/.docs/models/providers/ovhcloud.md +6 -8
- package/.docs/models/providers/poe.md +10 -15
- package/.docs/models/providers/regolo-ai.md +83 -0
- package/.docs/models/providers/siliconflow-cn.md +5 -2
- package/.docs/models/providers/siliconflow.md +6 -3
- package/.docs/models/providers/stepfun.md +8 -7
- package/.docs/models/providers/synthetic.md +5 -2
- package/.docs/models/providers/tencent-token-plan.md +71 -0
- package/.docs/models/providers/tencent-tokenhub.md +71 -0
- package/.docs/models/providers/togetherai.md +8 -7
- package/.docs/models/providers/vivgrid.md +7 -3
- package/.docs/models/providers/vultr.md +7 -6
- package/.docs/models/providers/wafer.ai.md +73 -0
- package/.docs/models/providers/wandb.md +3 -2
- package/.docs/models/providers/xai.md +6 -1
- package/.docs/models/providers/xiaomi-token-plan-ams.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-cn.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-sgp.md +75 -0
- package/.docs/models/providers/xiaomi.md +4 -2
- package/.docs/models/providers/zai-coding-plan.md +11 -19
- package/.docs/models/providers/zai.md +2 -1
- package/.docs/models/providers/zenmux.md +17 -6
- package/.docs/models/providers/zhipuai-coding-plan.md +11 -21
- package/.docs/models/providers/zhipuai.md +2 -1
- package/.docs/models/providers.md +11 -0
- package/.docs/reference/agents/agent.md +1 -1
- package/.docs/reference/agents/channels.md +3 -3
- package/.docs/reference/agents/generate.md +88 -6
- package/.docs/reference/agents/generateLegacy.md +1 -1
- package/.docs/reference/ai-sdk/chat-route.md +2 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +19 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +2 -0
- package/.docs/reference/ai-sdk/network-route.md +2 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +95 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +15 -0
- package/.docs/reference/browser/agent-browser.md +375 -0
- package/.docs/reference/browser/browser-viewer.md +228 -0
- package/.docs/reference/browser/mastra-browser.md +286 -0
- package/.docs/reference/browser/stagehand-browser.md +286 -0
- package/.docs/reference/cli/mastra.md +703 -0
- package/.docs/reference/client-js/agents.md +166 -0
- package/.docs/reference/client-js/conversations.md +1 -1
- package/.docs/reference/client-js/mastra-client.md +23 -0
- package/.docs/reference/client-js/observability.md +2 -2
- package/.docs/reference/client-js/responses.md +1 -1
- package/.docs/reference/client-js/workflows.md +62 -1
- package/.docs/reference/configuration.md +67 -1
- package/.docs/reference/core/addGateway.md +5 -5
- package/.docs/reference/core/getEditor.md +35 -0
- package/.docs/reference/core/getGateway.md +5 -5
- package/.docs/reference/core/getGatewayById.md +5 -5
- package/.docs/reference/core/getMCPServer.md +2 -2
- package/.docs/reference/core/getMCPServerById.md +2 -2
- package/.docs/reference/core/getScorer.md +3 -3
- package/.docs/reference/core/getScorerById.md +3 -3
- package/.docs/reference/core/listGateways.md +5 -5
- package/.docs/reference/core/listMCPServers.md +2 -2
- package/.docs/reference/core/listScorers.md +3 -3
- package/.docs/reference/core/mastra-class.md +11 -1
- package/.docs/reference/core/mastra-model-gateway.md +5 -5
- package/.docs/reference/datasets/create.md +4 -4
- package/.docs/reference/datasets/startExperiment.md +28 -2
- package/.docs/reference/datasets/update.md +4 -4
- package/.docs/reference/deployer/cloudflare.md +14 -1
- package/.docs/reference/deployer/netlify.md +50 -2
- package/.docs/reference/editor/mastra-editor.md +168 -0
- package/.docs/reference/editor/tool-provider.md +85 -0
- package/.docs/reference/evals/context-precision.md +3 -3
- package/.docs/reference/evals/context-relevance.md +3 -3
- package/.docs/reference/evals/create-scorer.md +5 -3
- package/.docs/reference/evals/filter-run.md +117 -0
- package/.docs/reference/evals/mastra-scorer.md +4 -4
- package/.docs/reference/evals/noise-sensitivity.md +6 -6
- package/.docs/reference/evals/prompt-alignment.md +12 -12
- package/.docs/reference/evals/run-evals.md +6 -6
- package/.docs/reference/evals/scorer-utils.md +3 -3
- package/.docs/reference/evals/trajectory-accuracy.md +3 -3
- package/.docs/reference/harness/harness-class.md +152 -53
- package/.docs/reference/index.md +25 -0
- package/.docs/reference/logging/pino-logger.md +0 -2
- package/.docs/reference/mastra-platform/api.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +4 -2
- package/.docs/reference/memory/cloneThread.md +4 -2
- package/.docs/reference/memory/observational-memory.md +4 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +3 -3
- package/.docs/reference/observability/tracing/bridges/datadog.md +211 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +3 -3
- package/.docs/reference/observability/tracing/configuration.md +18 -11
- package/.docs/reference/observability/tracing/exporters/arthur.md +122 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +102 -21
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/langfuse.md +25 -32
- package/.docs/reference/observability/tracing/exporters/otel.md +3 -3
- package/.docs/reference/observability/tracing/instances.md +7 -7
- package/.docs/reference/observability/tracing/interfaces.md +23 -6
- package/.docs/reference/observability/tracing/span-filtering.md +95 -0
- package/.docs/reference/observability/tracing/spans.md +6 -6
- package/.docs/reference/processors/prefill-error-handler.md +70 -0
- package/.docs/reference/processors/processor-interface.md +400 -40
- package/.docs/reference/processors/skill-search-processor.md +20 -1
- package/.docs/reference/processors/stream-error-retry-processor.md +54 -0
- package/.docs/reference/processors/tool-call-filter.md +23 -0
- package/.docs/reference/server/create-route.md +3 -3
- package/.docs/reference/server/express-adapter.md +4 -4
- package/.docs/reference/server/fastify-adapter.md +4 -4
- package/.docs/reference/server/hono-adapter.md +4 -4
- package/.docs/reference/server/koa-adapter.md +4 -4
- package/.docs/reference/server/mastra-server.md +3 -3
- package/.docs/reference/server/nestjs-adapter.md +169 -0
- package/.docs/reference/server/register-api-route.md +4 -4
- package/.docs/reference/server/routes.md +11 -10
- package/.docs/reference/storage/clickhouse.md +300 -0
- package/.docs/reference/storage/cloudflare-d1.md +42 -42
- package/.docs/reference/storage/composite.md +5 -3
- package/.docs/reference/storage/duckdb.md +150 -0
- package/.docs/reference/storage/overview.md +1 -1
- package/.docs/reference/storage/redis.md +266 -0
- package/.docs/reference/streaming/ChunkType.md +143 -3
- package/.docs/reference/streaming/agents/MastraModelOutput.md +2 -2
- package/.docs/reference/streaming/agents/stream.md +10 -2
- package/.docs/reference/streaming/agents/streamUntilIdle.md +94 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +2 -0
- package/.docs/reference/templates/overview.md +88 -14
- package/.docs/reference/tools/create-tool.md +107 -5
- package/.docs/reference/tools/mcp-client.md +45 -0
- package/.docs/reference/tools/mcp-server.md +1 -3
- package/.docs/reference/tools/perplexity.md +155 -0
- package/.docs/reference/tools/tavily.md +307 -0
- package/.docs/reference/vectors/mongodb.md +0 -2
- package/.docs/reference/voice/aws-nova-sonic.md +247 -0
- package/.docs/reference/voice/cloudflare.md +3 -3
- package/.docs/reference/voice/sarvam.md +29 -23
- package/.docs/reference/voice/voice.connect.md +4 -4
- package/.docs/reference/voice/voice.listen.md +3 -3
- package/.docs/reference/workflows/run-methods/resume.md +24 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +1 -1
- package/.docs/reference/workflows/step.md +88 -7
- package/.docs/reference/workflows/workflow-methods/foreach.md +14 -1
- package/.docs/reference/workflows/workflow.md +88 -4
- package/.docs/reference/workspace/azure-blob-filesystem.md +219 -0
- package/.docs/reference/workspace/docker-sandbox.md +196 -0
- package/.docs/reference/workspace/gcs-filesystem.md +1 -0
- package/.docs/reference/workspace/google-drive-filesystem.md +185 -0
- package/.docs/reference/workspace/modal-sandbox.md +168 -0
- package/.docs/reference/workspace/process-manager.md +1 -1
- package/.docs/reference/workspace/s3-filesystem.md +80 -5
- package/.docs/reference/workspace/vercel.md +1 -1
- package/.docs/reference/workspace/workspace-class.md +37 -6
- package/CHANGELOG.md +500 -4
- package/dist/stdio.js.map +1 -1
- package/dist/utils.d.ts +1 -4
- package/dist/utils.d.ts.map +1 -1
- package/package.json +11 -11
- 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,7 @@
|
|
|
2
2
|
|
|
3
3
|
The `DefaultExporter` persists traces to your configured storage backend, making them accessible through Studio. It's automatically enabled when using the default observability configuration and requires no external services.
|
|
4
4
|
|
|
5
|
-
> **Production Observability:** Observability data can quickly overwhelm general-purpose databases in production. For high-traffic applications,
|
|
5
|
+
> **Production Observability:** Observability data can quickly overwhelm general-purpose databases in production. For high-traffic applications, route the observability storage domain to [ClickHouse](https://mastra.ai/reference/storage/clickhouse) through [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](#production-recommendations) for details.
|
|
6
6
|
|
|
7
7
|
## Configuration
|
|
8
8
|
|
|
@@ -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 hosted Mastra Studio (requires MASTRA_CLOUD_ACCESS_TOKEN)
|
|
63
63
|
],
|
|
64
64
|
spanOutputProcessors: [new SensitiveDataFilter()],
|
|
65
65
|
},
|
|
@@ -114,7 +114,7 @@ If you set the strategy to `'auto'`, the `DefaultExporter` automatically selects
|
|
|
114
114
|
|
|
115
115
|
| Storage Provider | Preferred Strategy | Supported Strategies | Recommended Use |
|
|
116
116
|
| ---------------------------------------------------------------- | ------------------ | ------------------------------- | ------------------------------------- |
|
|
117
|
-
| **ClickHouse
|
|
117
|
+
| **[ClickHouse](https://mastra.ai/reference/storage/clickhouse)** | insert-only | insert-only | Production (high-volume) |
|
|
118
118
|
| **[PostgreSQL](https://mastra.ai/reference/storage/postgresql)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
119
119
|
| **[MSSQL](https://mastra.ai/reference/storage/mssql)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
120
120
|
| **[MongoDB](https://mastra.ai/reference/storage/mongodb)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
@@ -143,7 +143,7 @@ Observability data grows quickly in production environments. A single agent inte
|
|
|
143
143
|
|
|
144
144
|
### Recommended: ClickHouse for High-Volume Production
|
|
145
145
|
|
|
146
|
-
[ClickHouse](https://mastra.ai/reference/storage/
|
|
146
|
+
[ClickHouse](https://mastra.ai/reference/storage/clickhouse) is a columnar database designed for high-volume analytics workloads. It's the recommended choice for production observability because:
|
|
147
147
|
|
|
148
148
|
- **Optimized for writes**: Handles millions of inserts per second
|
|
149
149
|
- **Efficient compression**: Reduces storage costs for trace data
|
|
@@ -203,5 +203,5 @@ new DefaultExporter({
|
|
|
203
203
|
|
|
204
204
|
- [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview)
|
|
205
205
|
- [CloudExporter](https://mastra.ai/docs/observability/tracing/exporters/cloud)
|
|
206
|
-
- [Composite Storage](https://mastra.ai/reference/storage/composite)
|
|
206
|
+
- [Composite Storage](https://mastra.ai/reference/storage/composite): Combine multiple storage providers
|
|
207
207
|
- [Storage Configuration](https://mastra.ai/docs/memory/storage)
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
# Laminar exporter
|
|
2
2
|
|
|
3
|
-
[Laminar](https://laminar.sh/) is an open-source platform for
|
|
3
|
+
[Laminar](https://laminar.sh/) is an open-source, OpenTelemetry-native observability platform for AI agents. Trace, debug, and monitor every Mastra agent run, model step, tool call, and sub-agent with a single `MastraExporter` wired into your `Observability` config.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
**npm**:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @
|
|
10
|
+
npm install @lmnr-ai/lmnr
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
**pnpm**:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
pnpm add @
|
|
16
|
+
pnpm add @lmnr-ai/lmnr
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
**Yarn**:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
yarn add @
|
|
22
|
+
yarn add @lmnr-ai/lmnr
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
**Bun**:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
bun add @
|
|
28
|
+
bun add @lmnr-ai/lmnr
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Configuration
|
|
@@ -42,7 +42,6 @@ LMNR_PROJECT_API_KEY=lmnr_...
|
|
|
42
42
|
|
|
43
43
|
# Optional
|
|
44
44
|
LMNR_BASE_URL=https://api.lmnr.ai
|
|
45
|
-
LAMINAR_ENDPOINT=https://api.lmnr.ai/v1/traces
|
|
46
45
|
```
|
|
47
46
|
|
|
48
47
|
### Zero-Config Setup
|
|
@@ -52,14 +51,16 @@ With environment variables set, use the exporter with no configuration:
|
|
|
52
51
|
```typescript
|
|
53
52
|
import { Mastra } from '@mastra/core'
|
|
54
53
|
import { Observability } from '@mastra/observability'
|
|
55
|
-
import {
|
|
54
|
+
import { Laminar, MastraExporter } from '@lmnr-ai/lmnr'
|
|
55
|
+
|
|
56
|
+
Laminar.initialize()
|
|
56
57
|
|
|
57
58
|
export const mastra = new Mastra({
|
|
58
59
|
observability: new Observability({
|
|
59
60
|
configs: {
|
|
60
61
|
laminar: {
|
|
61
62
|
serviceName: 'my-service',
|
|
62
|
-
exporters: [new
|
|
63
|
+
exporters: [new MastraExporter()],
|
|
63
64
|
},
|
|
64
65
|
},
|
|
65
66
|
}),
|
|
@@ -73,7 +74,13 @@ You can also pass credentials directly (takes precedence over environment variab
|
|
|
73
74
|
```typescript
|
|
74
75
|
import { Mastra } from '@mastra/core'
|
|
75
76
|
import { Observability } from '@mastra/observability'
|
|
76
|
-
import {
|
|
77
|
+
import { Laminar, MastraExporter } from '@lmnr-ai/lmnr'
|
|
78
|
+
|
|
79
|
+
Laminar.initialize({
|
|
80
|
+
projectApiKey: process.env.LMNR_PROJECT_API_KEY!,
|
|
81
|
+
baseUrl: process.env.LMNR_BASE_URL, // Optional
|
|
82
|
+
// ...other options
|
|
83
|
+
})
|
|
77
84
|
|
|
78
85
|
export const mastra = new Mastra({
|
|
79
86
|
observability: new Observability({
|
|
@@ -81,10 +88,7 @@ export const mastra = new Mastra({
|
|
|
81
88
|
laminar: {
|
|
82
89
|
serviceName: 'my-service',
|
|
83
90
|
exporters: [
|
|
84
|
-
new
|
|
85
|
-
apiKey: process.env.LMNR_PROJECT_API_KEY!,
|
|
86
|
-
baseUrl: process.env.LMNR_BASE_URL, // Optional
|
|
87
|
-
endpoint: process.env.LAMINAR_ENDPOINT, // Optional
|
|
91
|
+
new MastraExporter({
|
|
88
92
|
realtime: process.env.NODE_ENV === 'development', // Optional
|
|
89
93
|
}),
|
|
90
94
|
],
|
|
@@ -94,7 +98,11 @@ export const mastra = new Mastra({
|
|
|
94
98
|
})
|
|
95
99
|
```
|
|
96
100
|
|
|
101
|
+
> **Note:** For advanced usage, including the full `MastraExporter` options and multi-agent trace examples, see [Laminar's Mastra integration guide](https://laminar.sh/docs/tracing/integrations/mastra).
|
|
102
|
+
|
|
103
|
+
Mastra also ships a standalone [`LaminarExporter`](https://mastra.ai/reference/observability/tracing/exporters/laminar) in `@mastra/laminar` that sends spans over OTLP/HTTP. It cannot inherit an active OTel context and does not fully map Mastra spans to Laminar's native format, so use the `@lmnr-ai/lmnr` integration above for `observe()` wrappers, multi-agent root spans, and accurate Laminar rendering.
|
|
104
|
+
|
|
97
105
|
## Related
|
|
98
106
|
|
|
99
107
|
- [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview)
|
|
100
|
-
- [Laminar Documentation](https://
|
|
108
|
+
- [Laminar Documentation](https://laminar.sh/docs)
|
|
@@ -82,9 +82,8 @@ export const mastra = new Mastra({
|
|
|
82
82
|
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
|
|
83
83
|
secretKey: process.env.LANGFUSE_SECRET_KEY!,
|
|
84
84
|
baseUrl: process.env.LANGFUSE_BASE_URL,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
85
|
+
environment: process.env.NODE_ENV,
|
|
86
|
+
release: process.env.GIT_COMMIT,
|
|
88
87
|
}),
|
|
89
88
|
],
|
|
90
89
|
},
|
|
@@ -123,6 +122,35 @@ new LangfuseExporter({
|
|
|
123
122
|
})
|
|
124
123
|
```
|
|
125
124
|
|
|
125
|
+
#### Batch Tuning for High-Volume Traces
|
|
126
|
+
|
|
127
|
+
For self-hosted Langfuse deployments or streamed runs that produce many spans per second, you can tune the OTEL batch size and flush interval to reduce request pressure on the Langfuse ingestion endpoint:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
new LangfuseExporter({
|
|
131
|
+
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
|
|
132
|
+
secretKey: process.env.LANGFUSE_SECRET_KEY!,
|
|
133
|
+
flushAt: 500, // Maximum spans per OTEL export batch
|
|
134
|
+
flushInterval: 20, // Maximum seconds between flushes
|
|
135
|
+
})
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
To suppress high-volume span types entirely (for example `MODEL_CHUNK` spans from streamed responses), use the observability-level [`excludeSpanTypes` option](https://mastra.ai/reference/observability/tracing/span-filtering) rather than configuring the exporter:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { SpanType } from '@mastra/core/observability'
|
|
142
|
+
|
|
143
|
+
new Observability({
|
|
144
|
+
configs: {
|
|
145
|
+
langfuse: {
|
|
146
|
+
serviceName: 'my-service',
|
|
147
|
+
exporters: [new LangfuseExporter()],
|
|
148
|
+
excludeSpanTypes: [SpanType.MODEL_CHUNK],
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
```
|
|
153
|
+
|
|
126
154
|
### Complete Configuration
|
|
127
155
|
|
|
128
156
|
```typescript
|
|
@@ -134,14 +162,13 @@ new LangfuseExporter({
|
|
|
134
162
|
// Optional settings
|
|
135
163
|
baseUrl: process.env.LANGFUSE_BASE_URL, // Default: https://cloud.langfuse.com
|
|
136
164
|
realtime: process.env.NODE_ENV === 'development', // Dynamic mode selection
|
|
165
|
+
flushAt: 500, // Maximum spans per OTEL export batch
|
|
166
|
+
flushInterval: 20, // Maximum seconds between flushes
|
|
137
167
|
logLevel: 'info', // Diagnostic logging: debug | info | warn | error
|
|
138
168
|
|
|
139
|
-
// Langfuse-specific
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
version: process.env.APP_VERSION, // Track different versions
|
|
143
|
-
release: process.env.GIT_COMMIT, // Git commit hash
|
|
144
|
-
},
|
|
169
|
+
// Langfuse-specific settings
|
|
170
|
+
environment: process.env.NODE_ENV, // Shows in Langfuse UI for filtering
|
|
171
|
+
release: process.env.GIT_COMMIT, // Git commit hash for version tracking
|
|
145
172
|
})
|
|
146
173
|
```
|
|
147
174
|
|
|
@@ -156,26 +183,26 @@ Use `withLangfusePrompt` with `buildTracingOptions` for the cleanest API:
|
|
|
156
183
|
```typescript
|
|
157
184
|
import { Agent } from '@mastra/core/agent'
|
|
158
185
|
import { buildTracingOptions } from '@mastra/observability'
|
|
159
|
-
import { withLangfusePrompt } from '@mastra/langfuse'
|
|
160
|
-
import { Langfuse } from 'langfuse'
|
|
186
|
+
import { LangfuseExporter, withLangfusePrompt } from '@mastra/langfuse'
|
|
161
187
|
|
|
162
|
-
|
|
163
|
-
const langfuse = new Langfuse()
|
|
188
|
+
const exporter = new LangfuseExporter()
|
|
164
189
|
|
|
165
|
-
// Fetch the prompt from Langfuse Prompt Management
|
|
166
|
-
const prompt = await
|
|
190
|
+
// Fetch the prompt from Langfuse Prompt Management via the client
|
|
191
|
+
const prompt = await exporter.client.prompt.get('customer-support', { type: 'text' })
|
|
167
192
|
|
|
168
193
|
export const supportAgent = new Agent({
|
|
169
194
|
name: 'support-agent',
|
|
170
|
-
instructions: prompt.
|
|
195
|
+
instructions: prompt.compile(), // Use the prompt text from Langfuse
|
|
171
196
|
model: 'openai/gpt-5.4',
|
|
172
197
|
defaultGenerateOptions: {
|
|
173
|
-
tracingOptions: buildTracingOptions(
|
|
198
|
+
tracingOptions: buildTracingOptions(
|
|
199
|
+
withLangfusePrompt({ name: prompt.name, version: prompt.version }),
|
|
200
|
+
),
|
|
174
201
|
},
|
|
175
202
|
})
|
|
176
203
|
```
|
|
177
204
|
|
|
178
|
-
The `withLangfusePrompt` helper
|
|
205
|
+
The `withLangfusePrompt` helper accepts `name` and `version` fields for prompt linking. Langfuse v5 requires both fields.
|
|
179
206
|
|
|
180
207
|
### Manual Fields
|
|
181
208
|
|
|
@@ -183,26 +210,16 @@ You can also pass manual fields if you're not using the Langfuse SDK:
|
|
|
183
210
|
|
|
184
211
|
```typescript
|
|
185
212
|
const tracingOptions = buildTracingOptions(withLangfusePrompt({ name: 'my-prompt', version: 1 }))
|
|
186
|
-
|
|
187
|
-
// Or with just an ID
|
|
188
|
-
const tracingOptions = buildTracingOptions(withLangfusePrompt({ id: 'prompt-uuid-12345' }))
|
|
189
213
|
```
|
|
190
214
|
|
|
191
215
|
### Prompt Object Fields
|
|
192
216
|
|
|
193
|
-
The prompt object
|
|
194
|
-
|
|
195
|
-
| Field | Type | Description |
|
|
196
|
-
| --------- | ------ | ---------------------------------- |
|
|
197
|
-
| `name` | string | The prompt name in Langfuse |
|
|
198
|
-
| `version` | number | The prompt version number |
|
|
199
|
-
| `id` | string | The prompt UUID for direct linking |
|
|
200
|
-
|
|
201
|
-
You can link prompts using either:
|
|
217
|
+
The prompt object requires both `name` and `version`:
|
|
202
218
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
219
|
+
| Field | Type | Description |
|
|
220
|
+
| --------- | ------ | --------------------------- |
|
|
221
|
+
| `name` | string | The prompt name in Langfuse |
|
|
222
|
+
| `version` | number | The prompt version number |
|
|
206
223
|
|
|
207
224
|
When set on a `MODEL_GENERATION` span, the Langfuse exporter automatically links the generation to the corresponding prompt.
|
|
208
225
|
|
|
@@ -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 hosted Mastra Studio (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 hosted Mastra Studio (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 hosted Mastra Studio for production monitoring and collaboration
|
|
73
73
|
|
|
74
74
|
### External Exporters
|
|
75
75
|
|
|
@@ -272,9 +272,9 @@ export const mastra = new Mastra({
|
|
|
272
272
|
|
|
273
273
|
### Common Configuration Patterns & Troubleshooting
|
|
274
274
|
|
|
275
|
-
#### Maintaining Studio
|
|
275
|
+
#### Maintaining Studio access
|
|
276
276
|
|
|
277
|
-
When adding external exporters, include `DefaultExporter` and `CloudExporter` to maintain access to Studio
|
|
277
|
+
When adding external exporters, include `DefaultExporter` and `CloudExporter` to maintain access to Studio:
|
|
278
278
|
|
|
279
279
|
```ts
|
|
280
280
|
import {
|
|
@@ -309,7 +309,7 @@ This configuration sends traces to all three destinations simultaneously:
|
|
|
309
309
|
|
|
310
310
|
- **Arize Phoenix/AX** for external observability
|
|
311
311
|
- **DefaultExporter** for Studio
|
|
312
|
-
- **CloudExporter** for
|
|
312
|
+
- **CloudExporter** for hosted Studio dashboard
|
|
313
313
|
|
|
314
314
|
> **Info:** Remember: A single trace can be sent to multiple exporters. You don't need separate configs for each exporter unless you want different sampling rates or processors.
|
|
315
315
|
|
|
@@ -341,6 +341,28 @@ execute: async (inputData, context) => {
|
|
|
341
341
|
|
|
342
342
|
Metadata set here will be shown in all configured exporters.
|
|
343
343
|
|
|
344
|
+
### Tagging traces with the deployment environment
|
|
345
|
+
|
|
346
|
+
Set the top-level `environment` field on Mastra to automatically attach the deployment environment to all observability signals without passing `tracingOptions.metadata.environment` on each call.
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
export const mastra = new Mastra({
|
|
350
|
+
environment: 'production',
|
|
351
|
+
observability: new Observability({
|
|
352
|
+
configs: {
|
|
353
|
+
default: {
|
|
354
|
+
serviceName: 'my-service',
|
|
355
|
+
exporters: [new DefaultExporter()],
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
}),
|
|
359
|
+
})
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
If `environment` is not set, Mastra falls back to `process.env.NODE_ENV`. If neither is set, the field is left undefined rather than guessed.
|
|
363
|
+
|
|
364
|
+
Per-call `tracingOptions.metadata.environment` always takes precedence, so individual calls can still override the value when needed.
|
|
365
|
+
|
|
344
366
|
### Automatic Metadata from `RequestContext`
|
|
345
367
|
|
|
346
368
|
Instead of manually adding metadata to each span, you can configure Mastra to automatically extract values from RequestContext and attach them as metadata to all spans in a trace. This is useful for consistently tracking user identifiers, environment information, feature flags, or any request-scoped data across your entire trace.
|
|
@@ -660,6 +682,50 @@ Processors are executed in the order they're defined, allowing you to chain mult
|
|
|
660
682
|
- Normalizing data formats
|
|
661
683
|
- Enriching spans with business context
|
|
662
684
|
|
|
685
|
+
## Span filtering
|
|
686
|
+
|
|
687
|
+
Span filtering lets you reduce noise and per-span costs before data reaches your observability platform. Configure it per observability instance, so different exporters or environments can keep different levels of detail.
|
|
688
|
+
|
|
689
|
+
- Use `excludeSpanTypes` to drop entire categories of spans with minimal configuration.
|
|
690
|
+
- Use `spanFilter` when you need custom logic based on the exported span data.
|
|
691
|
+
|
|
692
|
+
The following example demonstrates how to combine both options in a single config:
|
|
693
|
+
|
|
694
|
+
```ts
|
|
695
|
+
import { Mastra } from '@mastra/core'
|
|
696
|
+
import { SpanType } from '@mastra/core/observability'
|
|
697
|
+
import { Observability, DefaultExporter } from '@mastra/observability'
|
|
698
|
+
import { LangfuseExporter } from '@mastra/langfuse'
|
|
699
|
+
|
|
700
|
+
export const mastra = new Mastra({
|
|
701
|
+
observability: new Observability({
|
|
702
|
+
configs: {
|
|
703
|
+
default: {
|
|
704
|
+
serviceName: 'my-app',
|
|
705
|
+
exporters: [new DefaultExporter(), new LangfuseExporter()],
|
|
706
|
+
excludeSpanTypes: [SpanType.MODEL_CHUNK, SpanType.MODEL_STEP],
|
|
707
|
+
spanFilter: span => {
|
|
708
|
+
if (span.type === SpanType.TOOL_CALL && span.attributes?.success) {
|
|
709
|
+
return false
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
return true
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
}),
|
|
717
|
+
})
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
Filtering happens at export time in this order:
|
|
721
|
+
|
|
722
|
+
1. Internal spans are dropped unless `includeInternalSpans` is `true`.
|
|
723
|
+
2. `excludeSpanTypes` removes matching span types.
|
|
724
|
+
3. `spanOutputProcessors` transform the remaining spans.
|
|
725
|
+
4. `spanFilter` decides whether to keep the final exported span.
|
|
726
|
+
|
|
727
|
+
If `spanFilter` throws, Mastra keeps the span and logs the error to avoid silent data loss. For the full span type list and more examples, see the [Span filtering reference](https://mastra.ai/reference/observability/tracing/span-filtering).
|
|
728
|
+
|
|
663
729
|
### Custom Span Formatters
|
|
664
730
|
|
|
665
731
|
Custom span formatters transform how spans appear in specific observability platforms. Unlike span processors, formatters are configured per-exporter, allowing different formatting for different destinations. Formatters support both synchronous and asynchronous operations.
|
|
@@ -1087,26 +1153,27 @@ Mastra automatically creates spans for:
|
|
|
1087
1153
|
|
|
1088
1154
|
### Reference Documentation
|
|
1089
1155
|
|
|
1090
|
-
- [Configuration API](https://mastra.ai/reference/observability/tracing/configuration)
|
|
1091
|
-
- [Tracing Classes](https://mastra.ai/reference/observability/tracing/instances)
|
|
1092
|
-
- [Span Interfaces](https://mastra.ai/reference/observability/tracing/spans)
|
|
1093
|
-
- [Type Definitions](https://mastra.ai/reference/observability/tracing/interfaces)
|
|
1156
|
+
- [Configuration API](https://mastra.ai/reference/observability/tracing/configuration): ObservabilityConfig details
|
|
1157
|
+
- [Tracing Classes](https://mastra.ai/reference/observability/tracing/instances): Core classes and methods
|
|
1158
|
+
- [Span Interfaces](https://mastra.ai/reference/observability/tracing/spans): Span types and lifecycle
|
|
1159
|
+
- [Type Definitions](https://mastra.ai/reference/observability/tracing/interfaces): Complete interface reference
|
|
1160
|
+
- [Span filtering](https://mastra.ai/reference/observability/tracing/span-filtering): Filtering behavior, span types, and examples
|
|
1094
1161
|
|
|
1095
1162
|
### Exporters
|
|
1096
1163
|
|
|
1097
|
-
- [DefaultExporter](https://mastra.ai/reference/observability/tracing/exporters/default-exporter)
|
|
1098
|
-
- [CloudExporter](https://mastra.ai/reference/observability/tracing/exporters/cloud-exporter)
|
|
1099
|
-
- [ConsoleExporter](https://mastra.ai/reference/observability/tracing/exporters/console-exporter)
|
|
1100
|
-
- [Arize](https://mastra.ai/reference/observability/tracing/exporters/arize)
|
|
1101
|
-
- [Braintrust](https://mastra.ai/reference/observability/tracing/exporters/braintrust)
|
|
1102
|
-
- [Langfuse](https://mastra.ai/reference/observability/tracing/exporters/langfuse)
|
|
1103
|
-
- [MLflow](https://mastra.ai/docs/observability/tracing/exporters/otel)
|
|
1104
|
-
- [OpenTelemetry](https://mastra.ai/reference/observability/tracing/exporters/otel)
|
|
1164
|
+
- [DefaultExporter](https://mastra.ai/reference/observability/tracing/exporters/default-exporter): Storage persistence
|
|
1165
|
+
- [CloudExporter](https://mastra.ai/reference/observability/tracing/exporters/cloud-exporter): Mastra platform integration
|
|
1166
|
+
- [ConsoleExporter](https://mastra.ai/reference/observability/tracing/exporters/console-exporter): Debug output
|
|
1167
|
+
- [Arize](https://mastra.ai/reference/observability/tracing/exporters/arize): Arize Phoenix and Arize AX integration
|
|
1168
|
+
- [Braintrust](https://mastra.ai/reference/observability/tracing/exporters/braintrust): Braintrust integration
|
|
1169
|
+
- [Langfuse](https://mastra.ai/reference/observability/tracing/exporters/langfuse): Langfuse integration
|
|
1170
|
+
- [MLflow](https://mastra.ai/docs/observability/tracing/exporters/otel): MLflow OTLP endpoint setup
|
|
1171
|
+
- [OpenTelemetry](https://mastra.ai/reference/observability/tracing/exporters/otel): OTEL-compatible platforms
|
|
1105
1172
|
|
|
1106
1173
|
### Bridges
|
|
1107
1174
|
|
|
1108
|
-
- [OpenTelemetry Bridge](https://mastra.ai/reference/observability/tracing/bridges/otel)
|
|
1175
|
+
- [OpenTelemetry Bridge](https://mastra.ai/reference/observability/tracing/bridges/otel): OTEL context integration
|
|
1109
1176
|
|
|
1110
1177
|
### Processors
|
|
1111
1178
|
|
|
1112
|
-
- [Sensitive Data Filter](https://mastra.ai/docs/observability/tracing/processors/sensitive-data-filter)
|
|
1179
|
+
- [Sensitive Data Filter](https://mastra.ai/docs/observability/tracing/processors/sensitive-data-filter): Data redaction
|
|
@@ -373,8 +373,8 @@ app.listen(4111)
|
|
|
373
373
|
|
|
374
374
|
## Related
|
|
375
375
|
|
|
376
|
-
- [Server Adapters](https://mastra.ai/docs/server/server-adapters)
|
|
377
|
-
- [Hono Adapter](https://mastra.ai/reference/server/hono-adapter)
|
|
378
|
-
- [Express Adapter](https://mastra.ai/reference/server/express-adapter)
|
|
379
|
-
- [MastraServer Reference](https://mastra.ai/reference/server/mastra-server)
|
|
380
|
-
- [createRoute() Reference](https://mastra.ai/reference/server/create-route)
|
|
376
|
+
- [Server Adapters](https://mastra.ai/docs/server/server-adapters): Overview and shared concepts
|
|
377
|
+
- [Hono Adapter](https://mastra.ai/reference/server/hono-adapter): Reference implementation
|
|
378
|
+
- [Express Adapter](https://mastra.ai/reference/server/express-adapter): Reference implementation
|
|
379
|
+
- [MastraServer Reference](https://mastra.ai/reference/server/mastra-server): Full API reference
|
|
380
|
+
- [createRoute() Reference](https://mastra.ai/reference/server/create-route): Creating type-safe custom routes
|
|
@@ -318,6 +318,6 @@ export const mastra = new Mastra({
|
|
|
318
318
|
|
|
319
319
|
## Related
|
|
320
320
|
|
|
321
|
-
- [registerApiRoute() Reference](https://mastra.ai/reference/server/register-api-route)
|
|
322
|
-
- [Server Middleware](https://mastra.ai/docs/server/middleware)
|
|
323
|
-
- [Mastra Server](https://mastra.ai/docs/server/mastra-server)
|
|
321
|
+
- [registerApiRoute() Reference](https://mastra.ai/reference/server/register-api-route): Full API reference
|
|
322
|
+
- [Server Middleware](https://mastra.ai/docs/server/middleware): Global middleware configuration
|
|
323
|
+
- [Mastra Server](https://mastra.ai/docs/server/mastra-server): Server configuration options
|
|
@@ -61,8 +61,8 @@ The Mastra Client SDK exposes all resources served by the Mastra Server.
|
|
|
61
61
|
- **[Tools](https://mastra.ai/reference/client-js/tools)**: Executed and managed tools.
|
|
62
62
|
- **[Workflows](https://mastra.ai/reference/client-js/workflows)**: Trigger workflows and track their execution.
|
|
63
63
|
- **[Vectors](https://mastra.ai/reference/client-js/vectors)**: Use vector embeddings for semantic search.
|
|
64
|
-
- **[Responses](https://mastra.ai/reference/client-js/responses)**:
|
|
65
|
-
- **[Conversations](https://mastra.ai/reference/client-js/conversations)**: Work with
|
|
64
|
+
- **[Responses](https://mastra.ai/reference/client-js/responses)**: Use Mastra Agents as a Responses API with an OpenAI-compatible, agent-backed interface. This API is currently experimental.
|
|
65
|
+
- **[Conversations](https://mastra.ai/reference/client-js/conversations)**: Work with the stored conversation threads and item history behind Mastra Agents as a Responses API. This API is currently experimental.
|
|
66
66
|
- **[Logs](https://mastra.ai/reference/client-js/logs)**: View logs and debug system behavior.
|
|
67
67
|
- **[Telemetry](https://mastra.ai/reference/client-js/telemetry)**: View app performance and trace activity.
|
|
68
68
|
|
|
@@ -53,7 +53,7 @@ To explore the API interactively, visit the Swagger UI at <http://localhost:4111
|
|
|
53
53
|
|
|
54
54
|
## OpenAI Responses API
|
|
55
55
|
|
|
56
|
-
Mastra exposes OpenAI-compatible Responses and Conversations routes. These routes are agent-backed adapters over Mastra agents, memory, and storage, so requests run through the selected Mastra agent instead of acting as a raw provider proxy.
|
|
56
|
+
Mastra exposes OpenAI-compatible Responses and Conversations routes that let you use Mastra Agents as a Responses API. These routes are agent-backed adapters over Mastra agents, memory, and storage, so requests run through the selected Mastra agent instead of acting as a raw provider proxy.
|
|
57
57
|
|
|
58
58
|
These APIs are currently experimental.
|
|
59
59
|
|
|
@@ -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:
|
|
@@ -207,30 +235,6 @@ This is useful when you want to restrict operations to a specific thread that yo
|
|
|
207
235
|
}
|
|
208
236
|
```
|
|
209
237
|
|
|
210
|
-
### Special Mastra headers
|
|
211
|
-
|
|
212
|
-
When integrating with Mastra Cloud or custom clients the following headers can be inspected by middleware to tailor behavior:
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
{
|
|
216
|
-
handler: async (c, next) => {
|
|
217
|
-
const isFromMastraCloud = c.req.header('x-mastra-cloud') === 'true';
|
|
218
|
-
const clientType = c.req.header('x-mastra-client-type');
|
|
219
|
-
const isStudio =
|
|
220
|
-
c.req.header('x-studio') === 'true';
|
|
221
|
-
|
|
222
|
-
if (isFromMastraCloud) {
|
|
223
|
-
// Special handling
|
|
224
|
-
}
|
|
225
|
-
await next();
|
|
226
|
-
},
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
- `x-mastra-cloud`: request originates from Mastra Cloud
|
|
231
|
-
- `x-mastra-client-type`: identifies the client SDK, e.g. `js` or `python`
|
|
232
|
-
- `x-studio`: request triggered from Studio
|
|
233
|
-
|
|
234
238
|
# Related
|
|
235
239
|
|
|
236
240
|
- [Request Context](https://mastra.ai/docs/server/request-context)
|