@mastra/mcp-docs-server 1.0.0-beta.5 → 1.0.0-beta.7
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/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +110 -110
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +60 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +358 -358
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +79 -79
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +61 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Flance.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +55 -55
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +125 -125
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +59 -59
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +77 -77
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Freact.md +16 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +113 -113
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
- package/.docs/organized/changelogs/create-mastra.md +15 -15
- package/.docs/organized/changelogs/mastra.md +30 -30
- package/.docs/organized/code-examples/agui.md +1 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
- package/.docs/organized/code-examples/ai-sdk-v5.md +2 -1
- package/.docs/organized/code-examples/assistant-ui.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
- package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/organized/code-examples/server-express-adapter.md +87 -0
- package/.docs/organized/code-examples/server-hono-adapter.md +85 -0
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +13 -9
- package/.docs/raw/agents/networks.mdx +1 -0
- package/.docs/raw/agents/overview.mdx +8 -152
- package/.docs/raw/agents/processors.mdx +279 -0
- package/.docs/raw/agents/structured-output.mdx +224 -0
- package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- package/.docs/raw/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
- package/.docs/raw/getting-started/start.mdx +1 -1
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
- package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +37 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/memory/memory-processors.mdx +265 -79
- package/.docs/raw/memory/working-memory.mdx +11 -2
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +200 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +36 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +83 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +34 -22
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +20 -0
- package/.docs/raw/observability/tracing/overview.mdx +76 -6
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/retrieval.mdx +23 -6
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- package/.docs/raw/reference/agents/network.mdx +44 -0
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- package/.docs/raw/reference/deployer/netlify.mdx +1 -2
- package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
- package/.docs/raw/reference/index.mdx +1 -0
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +177 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +29 -0
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +43 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +33 -43
- package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
- package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
- package/.docs/raw/reference/processors/language-detector.mdx +9 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- package/.docs/raw/reference/server/create-route.mdx +314 -0
- package/.docs/raw/reference/server/express-adapter.mdx +193 -0
- package/.docs/raw/reference/server/hono-adapter.mdx +174 -0
- package/.docs/raw/reference/server/mastra-server.mdx +316 -0
- package/.docs/raw/reference/server/routes.mdx +250 -0
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/convex.mdx +164 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
- package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
- package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
- package/.docs/raw/reference/tools/mcp-client.mdx +128 -18
- package/.docs/raw/reference/vectors/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- package/.docs/raw/reference/voice/google.mdx +159 -20
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
- package/.docs/raw/reference/workflows/run.mdx +27 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/custom-adapters.mdx +380 -0
- package/.docs/raw/server-db/mastra-server.mdx +16 -8
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/server-adapters.mdx +286 -0
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +6 -6
- package/.docs/raw/streaming/tool-streaming.mdx +2 -2
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- package/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +16 -0
- package/package.json +4 -4
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Structured Output | Agents"
|
|
3
|
+
description: "Learn how to generate structured data from agents using schemas and validation."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import Tabs from "@theme/Tabs";
|
|
7
|
+
import TabItem from "@theme/TabItem";
|
|
8
|
+
|
|
9
|
+
# Structured Output
|
|
10
|
+
|
|
11
|
+
Structured output lets an agent return an object that matches the shape defined by a schema instead of returning text. The schema tells the model what fields to produce, and the model ensures the final result fits that shape.
|
|
12
|
+
|
|
13
|
+
## When to use structured output
|
|
14
|
+
|
|
15
|
+
Use structured output when you need an agent to return a data object rather than text. Having well defined fields can make it simpler to pull out the values you need for API calls, UI rendering, or application logic.
|
|
16
|
+
|
|
17
|
+
## Defining schemas
|
|
18
|
+
|
|
19
|
+
Agents can return structured data by defining the expected output with either [Zod](https://zod.dev/) or [JSON Schema](https://json-schema.org/). Zod is recommended because it provides TypeScript type inference and runtime validation, while JSON Schema is useful when you need a language agnostic format.
|
|
20
|
+
|
|
21
|
+
<Tabs>
|
|
22
|
+
<TabItem value="zod" label="Zod">
|
|
23
|
+
|
|
24
|
+
Define the `output` shape using [Zod](https://zod.dev/):
|
|
25
|
+
|
|
26
|
+
```typescript showLineNumbers copy
|
|
27
|
+
import { z } from "zod";
|
|
28
|
+
|
|
29
|
+
const response = await testAgent.generate("Help me plan my day.", {
|
|
30
|
+
structuredOutput: {
|
|
31
|
+
schema: z.array(
|
|
32
|
+
z.object({
|
|
33
|
+
name: z.string(),
|
|
34
|
+
activities: z.array(z.string()),
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(response.object);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
</TabItem>
|
|
44
|
+
<TabItem value="json-schema" label="JSON Schema">
|
|
45
|
+
|
|
46
|
+
You can also use JSON Schema to define your output structure:
|
|
47
|
+
|
|
48
|
+
```typescript showLineNumbers copy
|
|
49
|
+
const response = await testAgent.generate("Help me plan my day.", {
|
|
50
|
+
structuredOutput: {
|
|
51
|
+
schema: {
|
|
52
|
+
type: "array",
|
|
53
|
+
items: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {
|
|
56
|
+
name: { type: "string" },
|
|
57
|
+
activities: {
|
|
58
|
+
type: "array",
|
|
59
|
+
items: { type: "string" },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
required: ["name", "activities"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log(response.object);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
</TabItem>
|
|
72
|
+
</Tabs>
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
> See [.generate()](/reference/v1/agents/generate#structuredoutput) for a full list of configuration options.
|
|
76
|
+
|
|
77
|
+
### Example output
|
|
78
|
+
|
|
79
|
+
The `response.object` will contain the structured data as defined by the schema.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
[
|
|
83
|
+
{
|
|
84
|
+
"name": "Morning Routine",
|
|
85
|
+
"activities": ["Wake up at 7am", "Exercise", "Shower", "Breakfast"]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "Work",
|
|
89
|
+
"activities": ["Check emails", "Team meeting", "Lunch break"]
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"name": "Evening",
|
|
93
|
+
"activities": ["Dinner", "Relax", "Read a book", "Sleep by 10pm"]
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Streaming
|
|
99
|
+
|
|
100
|
+
Streaming also supports structured output. The final structured object is available on `stream.fullStream` and after the stream completes on `stream.object`. Text stream chunks are still emitted, but they contain natural language text rather than structured data.
|
|
101
|
+
|
|
102
|
+
```typescript showLineNumbers copy
|
|
103
|
+
import { z } from "zod";
|
|
104
|
+
|
|
105
|
+
const stream = await testAgent.stream("Help me plan my day.", {
|
|
106
|
+
structuredOutput: {
|
|
107
|
+
schema: z.array(
|
|
108
|
+
z.object({
|
|
109
|
+
name: z.string(),
|
|
110
|
+
activities: z.array(z.string())
|
|
111
|
+
})
|
|
112
|
+
),
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
for await (const chunk of stream.fullStream) {
|
|
117
|
+
if (chunk.type === "object-result") {
|
|
118
|
+
console.log("\n", JSON.stringify(chunk, null, 2));
|
|
119
|
+
}
|
|
120
|
+
process.stdout.write(JSON.stringify(chunk));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log(await stream.object)
|
|
124
|
+
|
|
125
|
+
for await (const chunk of stream.textStream) {
|
|
126
|
+
process.stdout.write(chunk);
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Structuring agent
|
|
131
|
+
|
|
132
|
+
When your main agent isn't proficient at creating structured output you can provide a `model` to `structuredOutput`. In this case, Mastra uses a second agent under the hood to extract structured data from the main agent's natural language response. This makes two LLM calls, one to generate the response and another to turn that response into the structured object, which adds some latency and cost but can improve accuracy for complex structuring tasks.
|
|
133
|
+
|
|
134
|
+
```typescript showLineNumbers copy
|
|
135
|
+
import { z } from "zod";
|
|
136
|
+
|
|
137
|
+
const response = await testAgent.generate("Analyze the TypeScript programming language.", {
|
|
138
|
+
structuredOutput: {
|
|
139
|
+
schema: z.object({
|
|
140
|
+
overview: z.string(),
|
|
141
|
+
strengths: z.array(z.string()),
|
|
142
|
+
weaknesses: z.array(z.string()),
|
|
143
|
+
useCases: z.array(z.object({
|
|
144
|
+
scenario: z.string(),
|
|
145
|
+
reasoning: z.string(),
|
|
146
|
+
})),
|
|
147
|
+
comparison: z.object({
|
|
148
|
+
similarTo: z.array(z.string()),
|
|
149
|
+
differentiators: z.array(z.string()),
|
|
150
|
+
}),
|
|
151
|
+
}),
|
|
152
|
+
model: "openai/gpt-4o",
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
console.log(response.object);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Response format
|
|
160
|
+
|
|
161
|
+
By default, Mastra passes the schema to the model provider using the `response_format` API parameter. Most model providers have built-in support for this, which reliably enforces the schema.
|
|
162
|
+
|
|
163
|
+
If your model provider doesn't support `response_format`, you'll get an error from the API. When this happens, set `jsonPromptInjection: true`. This adds the schema to the system prompt instead, instructing the model to output JSON. This is less reliable than the API parameter approach.
|
|
164
|
+
|
|
165
|
+
```typescript showLineNumbers copy
|
|
166
|
+
import { z } from "zod";
|
|
167
|
+
|
|
168
|
+
const response = await testAgent.generate("Help me plan my day.", {
|
|
169
|
+
structuredOutput: {
|
|
170
|
+
schema: z.array(
|
|
171
|
+
z.object({
|
|
172
|
+
name: z.string(),
|
|
173
|
+
activities: z.array(z.string()),
|
|
174
|
+
}),
|
|
175
|
+
),
|
|
176
|
+
jsonPromptInjection: true,
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
console.log(response.object);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
:::info[Gemini 2.5 with tools]
|
|
184
|
+
|
|
185
|
+
Gemini 2.5 models do not support combining `response_format` (structured output) with function calling (tools) in the same API call. If your agent has tools and you're using `structuredOutput` with a Gemini 2.5 model, you must set `jsonPromptInjection: true` to avoid the error `Function calling with a response mime type: 'application/json' is unsupported`.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const response = await agentWithTools.generate("Your prompt", {
|
|
189
|
+
structuredOutput: {
|
|
190
|
+
schema: yourSchema,
|
|
191
|
+
jsonPromptInjection: true, // Required for Gemini 2.5 when tools are present
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
:::
|
|
196
|
+
|
|
197
|
+
## Error handling
|
|
198
|
+
|
|
199
|
+
When schema validation fails, you can control how errors are handled using `errorStrategy`. The default `strict` strategy throws an error, while `warn` logs a warning and continues. The `fallback` strategy returns the values provided using `fallbackValue`.
|
|
200
|
+
|
|
201
|
+
```typescript showLineNumbers copy
|
|
202
|
+
import { z } from "zod";
|
|
203
|
+
|
|
204
|
+
const response = await testAgent.generate("Tell me about TypeScript.", {
|
|
205
|
+
structuredOutput: {
|
|
206
|
+
schema: z.object({
|
|
207
|
+
summary: z.string(),
|
|
208
|
+
keyFeatures: z.array(z.string())
|
|
209
|
+
}),
|
|
210
|
+
errorStrategy: "fallback",
|
|
211
|
+
fallbackValue: {
|
|
212
|
+
summary: "TypeScript is a typed superset of JavaScript",
|
|
213
|
+
keyFeatures: ["Static typing", "Compiles to JavaScript", "Better tooling"]
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
console.log(response.object);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Related
|
|
222
|
+
|
|
223
|
+
- [Using Tools](/docs/v1/agents/using-tools)
|
|
224
|
+
- [Agent Memory](/docs/v1/agents/agent-memory)
|
|
@@ -15,7 +15,6 @@ Standalone Mastra applications can be deployed to popular cloud providers, see o
|
|
|
15
15
|
- [Netlify](/docs/v1/deployment/cloud-providers/netlify-deployer)
|
|
16
16
|
- [Vercel](/docs/v1/deployment/cloud-providers/vercel-deployer)
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
For self-hosted Node.js server deployment, see the [Creating A Mastra Server](/docs/v1/deployment/building-mastra) guide.
|
|
20
19
|
|
|
21
20
|
## Prerequisites
|
|
@@ -30,33 +29,27 @@ Before deploying to a cloud provider, ensure you have:
|
|
|
30
29
|
|
|
31
30
|
## LibSQLStore
|
|
32
31
|
|
|
33
|
-
`LibSQLStore` writes to the local filesystem, which is not supported in cloud environments that use ephemeral file systems. If you're deploying to platforms like
|
|
32
|
+
`LibSQLStore` writes to the local filesystem, which is not supported in cloud environments that use ephemeral file systems. If you're deploying to platforms like AWS Lambda, Netlify, Azure App Services, or Digital Ocean App Platform, you must remove all usage of `LibSQLStore`.
|
|
34
33
|
|
|
35
|
-
Specifically, ensure you've removed it from
|
|
34
|
+
Specifically, ensure you've removed it from all Mastra files, including configuration on the main Mastra instance and any agents using it, e.g. for memory storage.
|
|
36
35
|
|
|
37
|
-
```
|
|
38
|
-
export const mastra = new Mastra({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
url: ":memory:", // [!code --]
|
|
45
|
-
}), //[!code --]
|
|
46
|
-
});
|
|
36
|
+
```diff title="src/mastra/index.ts"
|
|
37
|
+
export const mastra = new Mastra({
|
|
38
|
+
- storage: new LibSQLStore({
|
|
39
|
+
- id: 'mastra-storage',
|
|
40
|
+
- url: ":memory:",
|
|
41
|
+
- }),
|
|
42
|
+
});
|
|
47
43
|
```
|
|
48
44
|
|
|
49
|
-
```
|
|
50
|
-
export const weatherAgent = new Agent({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}), // [!code --]
|
|
60
|
-
}), // [!code --]
|
|
61
|
-
});
|
|
45
|
+
```diff
|
|
46
|
+
export const weatherAgent = new Agent({
|
|
47
|
+
id: "weather-agent",
|
|
48
|
+
memory: new Memory({
|
|
49
|
+
- storage: new LibSQLStore({
|
|
50
|
+
- id: 'mastra-storage',
|
|
51
|
+
- url: "file:../mastra.db",
|
|
52
|
+
- }),
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
62
55
|
```
|
|
@@ -15,12 +15,11 @@ npm install @mastra/deployer-netlify@beta
|
|
|
15
15
|
|
|
16
16
|
## Usage example
|
|
17
17
|
|
|
18
|
-
```typescript title="src/mastra/index.ts"
|
|
18
|
+
```typescript title="src/mastra/index.ts" copy
|
|
19
19
|
import { Mastra } from "@mastra/core";
|
|
20
20
|
import { NetlifyDeployer } from "@mastra/deployer-netlify";
|
|
21
21
|
|
|
22
22
|
export const mastra = new Mastra({
|
|
23
|
-
// ...
|
|
24
23
|
deployer: new NetlifyDeployer(),
|
|
25
24
|
});
|
|
26
25
|
```
|
|
@@ -43,32 +42,64 @@ Your project is now configured with automatic deployments which occur whenever y
|
|
|
43
42
|
|
|
44
43
|
## Manual deployment
|
|
45
44
|
|
|
46
|
-
Manual deployments are also possible using the [Netlify CLI](https://docs.netlify.com/cli/get-started/). With the Netlify CLI installed run the following from your project root to deploy your application.
|
|
45
|
+
Manual deployments are also possible using the [Netlify CLI](https://docs.netlify.com/cli/get-started/). With the Netlify CLI installed run the following from your project root to deploy your application. You can also run `netlify dev` from your project root to test your Mastra application locally.
|
|
47
46
|
|
|
48
47
|
```bash copy
|
|
49
48
|
netlify deploy --prod
|
|
50
49
|
```
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
:::warning
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
When using `netlify deploy` instead of continuous deployment, you need to create a `netlify.toml` file with these contents:
|
|
54
|
+
|
|
55
|
+
```toml
|
|
56
|
+
[build]
|
|
57
|
+
command = "npm run build"
|
|
58
|
+
publish = ".netlify/v1/functions"
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
[functions]
|
|
61
|
+
directory = ".netlify/v1/functions"
|
|
62
|
+
node_bundler = "none"
|
|
63
|
+
included_files = [".netlify/v1/functions/**"]
|
|
57
64
|
|
|
65
|
+
[[redirects]]
|
|
66
|
+
from = "/*"
|
|
67
|
+
to = "/.netlify/functions/api/:splat"
|
|
68
|
+
status = 200
|
|
69
|
+
|
|
70
|
+
[build.environment]
|
|
71
|
+
NODE_VERSION = "22.13.0"
|
|
58
72
|
```
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
|
|
74
|
+
Adjust the `build.command` to your project.
|
|
75
|
+
|
|
76
|
+
:::
|
|
77
|
+
|
|
78
|
+
## Build output
|
|
79
|
+
|
|
80
|
+
The build output for Mastra applications using the `NetlifyDeployer` includes all agents, tools, and workflows in your project, along with Mastra-specific files required to run your application on Netlify.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
your-project/
|
|
84
|
+
└── .netlify/
|
|
85
|
+
└── v1/
|
|
86
|
+
├── config.json
|
|
87
|
+
└── functions/
|
|
88
|
+
└── api/
|
|
89
|
+
├── index.js
|
|
90
|
+
├── package.json
|
|
91
|
+
└── node_modules/
|
|
66
92
|
```
|
|
67
93
|
|
|
68
94
|
The `NetlifyDeployer` automatically generates a `config.json` configuration file in `.netlify/v1` with the following settings:
|
|
69
95
|
|
|
70
96
|
```json
|
|
71
97
|
{
|
|
98
|
+
"functions": {
|
|
99
|
+
"directory": ".netlify/v1/functions",
|
|
100
|
+
"node_bundler": "none",
|
|
101
|
+
"included_files": [".netlify/v1/functions/**"]
|
|
102
|
+
},
|
|
72
103
|
"redirects": [
|
|
73
104
|
{
|
|
74
105
|
"force": true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Manual Install |
|
|
2
|
+
title: "Manual Install | Getting Started"
|
|
3
3
|
description: Set up a Mastra project manually without using the create mastra CLI.
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -11,7 +11,7 @@ import StepItem from "@site/src/components/StepItem";
|
|
|
11
11
|
# Manual Install
|
|
12
12
|
|
|
13
13
|
:::info
|
|
14
|
-
Use this guide to manually build a standalone Mastra server step by step. In most cases, it's quicker to follow
|
|
14
|
+
Use this guide to manually build a standalone Mastra server step by step. In most cases, it's quicker to follow a [getting-started guide](/docs/v1/getting-started/start), which achieves the same result using the [`mastra create`](/reference/v1/cli/create-mastra) command. For existing projects, you can also use [`mastra init`](/reference/v1/cli/mastra#mastra-init).
|
|
15
15
|
:::
|
|
16
16
|
|
|
17
17
|
If you prefer not to use our automatic CLI tool, you can set up your project yourself by following the guide below.
|
|
@@ -6,7 +6,7 @@ description: Choose how to get started with Mastra - quickstart, framework integ
|
|
|
6
6
|
import { CardGrid, CardGridItem } from "@site/src/components/cards/card-grid";
|
|
7
7
|
|
|
8
8
|
# Start
|
|
9
|
-
|
|
9
|
+
Create a new Mastra project, or integrate Mastra with your preferred framework to start building.
|
|
10
10
|
|
|
11
11
|
## New project
|
|
12
12
|
|
|
@@ -142,6 +142,12 @@ const { error, status, sendMessage, messages, regenerate, stop } = useChat({
|
|
|
142
142
|
});
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
+
:::tip Agent streaming in workflows
|
|
146
|
+
When a workflow step pipes an agent's stream to the workflow writer (e.g., `await response.fullStream.pipeTo(writer)`), the agent's text chunks and tool calls are automatically streamed to the UI in real-time. This provides a seamless streaming experience even when agents are running inside workflow steps.
|
|
147
|
+
|
|
148
|
+
Learn more in [Workflow Streaming](/docs/v1/streaming/workflow-streaming#streaming-agent-text-chunks-to-ui).
|
|
149
|
+
:::
|
|
150
|
+
|
|
145
151
|
### `networkRoute()`
|
|
146
152
|
|
|
147
153
|
Use the `networkRoute()` utility to create a route handler that automatically formats the agent network stream into an AI SDK-compatible format.
|
|
@@ -292,6 +298,7 @@ export async function POST(req: Request) {
|
|
|
292
298
|
|
|
293
299
|
// Transform stream into AI SDK format and create UI messages stream
|
|
294
300
|
const uiMessageStream = createUIMessageStream({
|
|
301
|
+
originalMessages: messages,
|
|
295
302
|
execute: async ({ writer }) => {
|
|
296
303
|
for await (const part of toAISdkStream(stream, { from: "agent" })!) {
|
|
297
304
|
writer.write(part);
|
|
@@ -384,6 +391,7 @@ export async function POST(req: Request) {
|
|
|
384
391
|
});
|
|
385
392
|
|
|
386
393
|
const uiMessageStream = createUIMessageStream({
|
|
394
|
+
initialMessages: messages,
|
|
387
395
|
execute: async ({ writer }) => {
|
|
388
396
|
for await (const part of toAISdkStream(stream, {
|
|
389
397
|
from: "agent",
|
|
@@ -13,7 +13,7 @@ import { VideoPlayer } from "@site/src/components/video-player";
|
|
|
13
13
|
|
|
14
14
|
The `create mastra` CLI command is the quickest way to get started. It walks you through setup and creates example agents, workflows, and tools for you to run locally or adapt
|
|
15
15
|
|
|
16
|
-
If you need more control over the setup, see the [manual installation guide](/
|
|
16
|
+
If you need more control over the setup, see the [manual installation guide](/docs/v1/getting-started/manual-install). You can also use [`mastra init`](/reference/v1/cli/mastra#mastra-init) for existing projects.
|
|
17
17
|
|
|
18
18
|
## Before you begin
|
|
19
19
|
|