@mastra/mcp-docs-server 0.13.5 → 0.13.7-alpha.0
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/%40internal%2Fstorage-test-utils.md +84 -84
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +210 -210
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +99 -99
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +98 -98
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +189 -189
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +241 -241
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +170 -170
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +170 -170
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +236 -236
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +109 -109
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +80 -80
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +90 -90
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Flance.md +62 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +83 -83
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +50 -50
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +32 -32
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +145 -145
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +83 -83
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +76 -0
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +126 -126
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +245 -245
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Frag.md +87 -87
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +18 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +208 -208
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +101 -101
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +71 -71
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +8 -8
- package/.docs/organized/changelogs/create-mastra.md +127 -127
- package/.docs/organized/changelogs/mastra.md +250 -250
- package/.docs/organized/code-examples/a2a.md +1 -1
- package/.docs/organized/code-examples/agent.md +6 -0
- package/.docs/organized/code-examples/agui.md +5 -5
- package/.docs/organized/code-examples/ai-sdk-useChat.md +3 -3
- package/.docs/organized/code-examples/ai-sdk-v5.md +201 -0
- package/.docs/organized/code-examples/assistant-ui.md +3 -3
- package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +3 -3
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +3 -3
- package/.docs/organized/code-examples/client-side-tools.md +3 -3
- package/.docs/organized/code-examples/crypto-chatbot.md +6 -6
- package/.docs/organized/code-examples/fireworks-r1.md +1 -1
- package/.docs/organized/code-examples/memory-with-mem0.md +1 -1
- package/.docs/organized/code-examples/memory-with-pg.md +1 -0
- package/.docs/organized/code-examples/openapi-spec-writer.md +3 -3
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +1 -1
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +1 -1
- package/.docs/organized/code-examples/workflow-with-memory.md +1 -1
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +1 -1
- package/.docs/organized/code-examples/workflow-with-suspend-resume.md +181 -0
- package/.docs/raw/agents/agent-memory.mdx +126 -0
- package/.docs/raw/agents/dynamic-agents.mdx +34 -2
- package/.docs/raw/agents/overview.mdx +5 -0
- package/.docs/raw/agents/runtime-variables.mdx +1 -1
- package/.docs/raw/auth/index.mdx +24 -0
- package/.docs/raw/auth/jwt.mdx +99 -0
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +60 -26
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +6 -5
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +84 -14
- package/.docs/raw/deployment/cloud-providers/index.mdx +44 -9
- package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +9 -30
- package/.docs/raw/deployment/serverless-platforms/index.mdx +13 -13
- package/.docs/raw/evals/custom-eval.mdx +12 -12
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +291 -216
- package/.docs/raw/frameworks/agentic-uis/assistant-ui.mdx +0 -34
- package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +162 -181
- package/.docs/raw/frameworks/servers/express.mdx +1 -1
- package/.docs/raw/frameworks/web-frameworks/astro.mdx +2 -2
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +1 -1
- package/.docs/raw/frameworks/web-frameworks/sveltekit.mdx +4 -4
- package/.docs/raw/frameworks/web-frameworks/vite-react.mdx +1 -1
- package/.docs/raw/getting-started/installation.mdx +10 -7
- package/.docs/raw/getting-started/model-capability.mdx +1 -1
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/memory/overview.mdx +8 -0
- package/.docs/raw/memory/semantic-recall.mdx +6 -0
- package/.docs/raw/observability/tracing.mdx +30 -0
- package/.docs/raw/reference/agents/agent.mdx +2 -2
- package/.docs/raw/reference/auth/jwt.mdx +42 -0
- package/.docs/raw/reference/cli/create-mastra.mdx +7 -0
- package/.docs/raw/reference/cli/dev.mdx +4 -3
- package/.docs/raw/reference/client-js/agents.mdx +10 -10
- package/.docs/raw/reference/client-js/error-handling.mdx +1 -21
- package/.docs/raw/reference/client-js/logs.mdx +2 -10
- package/.docs/raw/reference/client-js/mastra-client.mdx +141 -0
- package/.docs/raw/reference/client-js/memory.mdx +6 -18
- package/.docs/raw/reference/client-js/telemetry.mdx +1 -9
- package/.docs/raw/reference/client-js/tools.mdx +2 -10
- package/.docs/raw/reference/client-js/vectors.mdx +1 -9
- package/.docs/raw/reference/client-js/workflows-legacy.mdx +3 -11
- package/.docs/raw/reference/client-js/workflows.mdx +5 -13
- package/.docs/raw/reference/core/mastra-class.mdx +6 -0
- package/.docs/raw/reference/memory/query.mdx +35 -14
- package/.docs/raw/reference/observability/providers/dash0.mdx +2 -2
- package/.docs/raw/reference/observability/providers/keywordsai.mdx +73 -0
- package/.docs/raw/reference/storage/mssql.mdx +108 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +29 -0
- package/.docs/raw/server-db/custom-api-routes.mdx +38 -26
- package/.docs/raw/tools-mcp/mcp-overview.mdx +24 -1
- package/.docs/raw/tools-mcp/overview.mdx +1 -1
- package/.docs/raw/workflows/control-flow.mdx +85 -87
- package/.docs/raw/workflows/input-data-mapping.mdx +31 -43
- package/.docs/raw/workflows/overview.mdx +22 -12
- package/.docs/raw/workflows/pausing-execution.mdx +49 -4
- package/.docs/raw/workflows/suspend-and-resume.mdx +17 -16
- package/.docs/raw/workflows/using-with-agents-and-tools.mdx +16 -13
- package/.docs/raw/workflows-legacy/overview.mdx +11 -0
- package/package.json +7 -9
- package/.docs/organized/changelogs/%40mastra%2Fagui.md +0 -302
- package/.docs/raw/frameworks/ai-sdk-v5.mdx +0 -91
|
@@ -14,7 +14,9 @@ When you build a workflow, you typically break down operations into smaller task
|
|
|
14
14
|
|
|
15
15
|
Chain steps to execute sequentially using `.then()`:
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
```typescript {8-9,4-5} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
18
20
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
19
21
|
import { z } from "zod";
|
|
20
22
|
|
|
@@ -29,11 +31,13 @@ export const testWorkflow = createWorkflow({...})
|
|
|
29
31
|
|
|
30
32
|
This does what you'd expect: it executes `step1`, then it executes `step2`.
|
|
31
33
|
|
|
32
|
-
##
|
|
34
|
+
## Simultaneous steps with `.parallel()`
|
|
35
|
+
|
|
36
|
+
Execute steps simultaneously using `.parallel()`:
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+

|
|
35
39
|
|
|
36
|
-
```typescript {8} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
40
|
+
```typescript {8,4-5} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
37
41
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
38
42
|
import { z } from "zod";
|
|
39
43
|
|
|
@@ -51,11 +55,13 @@ This executes `step1` and `step2` concurrently, then continues to `step3` after
|
|
|
51
55
|
|
|
52
56
|
> See [Parallel Execution with Steps](/examples/workflows/parallel-steps) for more information.
|
|
53
57
|
|
|
54
|
-
## Conditional
|
|
58
|
+
## Conditional logic with `.branch()`
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
Execute steps conditionally using `.branch()`:
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
```typescript {8-11,4-5} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
59
65
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
60
66
|
import { z } from "zod";
|
|
61
67
|
|
|
@@ -74,15 +80,20 @@ Branch conditions are evaluated sequentially, but steps with matching conditions
|
|
|
74
80
|
|
|
75
81
|
> See [Workflow with Conditional Branching](/examples/workflows/conditional-branching) for more information.
|
|
76
82
|
|
|
77
|
-
## Looping
|
|
83
|
+
## Looping steps
|
|
78
84
|
|
|
79
85
|
Workflows support two types of loops. When looping a step, or any step-compatible construct like a nested workflow, the initial `inputData` is sourced from the output of the previous step.
|
|
80
86
|
|
|
81
87
|
To ensure compatibility, the loop’s initial input must either match the shape of the previous step’s output, or be explicitly transformed using the `map` function.
|
|
82
88
|
|
|
83
|
-
|
|
89
|
+
- Match the shape of the previous step’s output, or
|
|
90
|
+
- Be explicitly transformed using the `map` function.
|
|
91
|
+
|
|
92
|
+
### Repeating with `.dowhile()`
|
|
84
93
|
|
|
85
|
-
Executes
|
|
94
|
+
Executes step repeatedly while a condition is true.
|
|
95
|
+
|
|
96
|
+

|
|
86
97
|
|
|
87
98
|
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
88
99
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
@@ -95,9 +106,11 @@ export const testWorkflow = createWorkflow({...})
|
|
|
95
106
|
.commit();
|
|
96
107
|
```
|
|
97
108
|
|
|
98
|
-
### `.dountil()`
|
|
109
|
+
### Repeating with `.dountil()`
|
|
110
|
+
|
|
111
|
+
Executes step repeatedly until a condition becomes true.
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+

|
|
101
114
|
|
|
102
115
|
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
103
116
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
@@ -110,10 +123,12 @@ export const testWorkflow = createWorkflow({...})
|
|
|
110
123
|
.commit();
|
|
111
124
|
```
|
|
112
125
|
|
|
113
|
-
### `.foreach()`
|
|
126
|
+
### Repeating with `.foreach()`
|
|
114
127
|
|
|
115
128
|
Sequentially executes the same step for each item from the `inputSchema`.
|
|
116
129
|
|
|
130
|
+

|
|
131
|
+
|
|
117
132
|
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
118
133
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
119
134
|
import { z } from "zod";
|
|
@@ -125,133 +140,116 @@ export const testWorkflow = createWorkflow({...})
|
|
|
125
140
|
.commit();
|
|
126
141
|
```
|
|
127
142
|
|
|
128
|
-
|
|
143
|
+
#### Setting concurrency limits
|
|
129
144
|
|
|
130
|
-
|
|
145
|
+
Use `concurrency` to execute steps in parallel with a limit on the number of concurrent executions.
|
|
131
146
|
|
|
132
147
|
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
133
148
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
134
149
|
import { z } from "zod";
|
|
135
150
|
|
|
136
|
-
const
|
|
137
|
-
id: 'step1',
|
|
138
|
-
execute: async ({ bail, inputData }) => {
|
|
139
|
-
return bail({ result: 'bailed' });
|
|
140
|
-
},
|
|
141
|
-
inputSchema: z.object({ value: z.string() }),
|
|
142
|
-
outputSchema: z.object({ result: z.string() }),
|
|
143
|
-
});
|
|
151
|
+
const mapStep = createStep({...})
|
|
144
152
|
|
|
145
153
|
export const testWorkflow = createWorkflow({...})
|
|
146
|
-
.
|
|
154
|
+
.foreach(mapStep, { concurrency: 2 })
|
|
147
155
|
.commit();
|
|
148
156
|
```
|
|
149
157
|
|
|
150
|
-
|
|
158
|
+
## Using a nested workflow
|
|
151
159
|
|
|
152
|
-
|
|
160
|
+
Use a nested workflow as a step by passing it to `.then()`. This runs each of its steps in sequence as part of the parent workflow.
|
|
161
|
+
|
|
162
|
+
```typescript {4,7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
153
163
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
154
164
|
import { z } from "zod";
|
|
155
165
|
|
|
156
|
-
const
|
|
157
|
-
id: 'step1',
|
|
158
|
-
execute: async ({ bail, inputData }) => {
|
|
159
|
-
throw new Error('bailed');
|
|
160
|
-
},
|
|
161
|
-
inputSchema: z.object({ value: z.string() }),
|
|
162
|
-
outputSchema: z.object({ result: z.string() }),
|
|
163
|
-
});
|
|
166
|
+
export const nestedWorkflow = createWorkflow({...})
|
|
164
167
|
|
|
165
168
|
export const testWorkflow = createWorkflow({...})
|
|
166
|
-
.then(
|
|
169
|
+
.then(nestedWorkflow)
|
|
167
170
|
.commit();
|
|
168
171
|
```
|
|
169
172
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
The following example demonstrates how to start a run with multiple inputs. Each input will pass through the `mapStep` sequentially.
|
|
173
|
-
|
|
174
|
-
```typescript {6} filename="src/test-workflow.ts" showLineNumbers copy
|
|
175
|
-
import { mastra } from "./mastra";
|
|
173
|
+
## Cloning a workflow
|
|
176
174
|
|
|
177
|
-
|
|
175
|
+
Use `cloneWorkflow` to duplicate an existing workflow. This lets you reuse its structure while overriding parameters like `id`.
|
|
178
176
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
```
|
|
177
|
+
```typescript {6,10} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
178
|
+
import { createWorkflow, createStep, cloneWorkflow } from "@mastra/core/workflows";
|
|
179
|
+
import { z } from "zod";
|
|
183
180
|
|
|
184
|
-
|
|
181
|
+
const step1 = createStep({...});
|
|
182
|
+
const parentWorkflow = createWorkflow({...})
|
|
183
|
+
const clonedWorkflow = cloneWorkflow(parentWorkflow, { id: "cloned-workflow" });
|
|
185
184
|
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
export const testWorkflow = createWorkflow({...})
|
|
186
|
+
.then(step1)
|
|
187
|
+
.then(clonedWorkflow)
|
|
188
|
+
.commit();
|
|
188
189
|
```
|
|
189
190
|
|
|
190
|
-
|
|
191
|
+
## Exiting early with `bail()`
|
|
191
192
|
|
|
192
|
-
|
|
193
|
+
Use `bail()` in a step to exit early with a successful result. This returns the provided payload as the step output and ends workflow execution.
|
|
193
194
|
|
|
194
195
|
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
195
196
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
196
197
|
import { z } from "zod";
|
|
197
198
|
|
|
198
|
-
const
|
|
199
|
+
const step1 = createStep({
|
|
200
|
+
id: 'step1',
|
|
201
|
+
execute: async ({ bail }) => {
|
|
202
|
+
return bail({ result: 'bailed' });
|
|
203
|
+
},
|
|
204
|
+
inputSchema: z.object({ value: z.string() }),
|
|
205
|
+
outputSchema: z.object({ result: z.string() }),
|
|
206
|
+
});
|
|
199
207
|
|
|
200
208
|
export const testWorkflow = createWorkflow({...})
|
|
201
|
-
.
|
|
209
|
+
.then(step1)
|
|
202
210
|
.commit();
|
|
203
211
|
```
|
|
204
212
|
|
|
205
|
-
##
|
|
206
|
-
|
|
207
|
-
For greater composability, you can re-use a workflow as a step in another workflow.
|
|
213
|
+
## Exiting early with `Error()`
|
|
208
214
|
|
|
209
|
-
|
|
215
|
+
Use `throw new Error()` in a step to exit with an error.
|
|
210
216
|
|
|
211
|
-
```typescript {
|
|
217
|
+
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
212
218
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
213
219
|
import { z } from "zod";
|
|
214
220
|
|
|
215
|
-
|
|
221
|
+
const step1 = createStep({
|
|
222
|
+
id: 'step1',
|
|
223
|
+
execute: async () => {
|
|
224
|
+
throw new Error('bailed');
|
|
225
|
+
},
|
|
226
|
+
inputSchema: z.object({ value: z.string() }),
|
|
227
|
+
outputSchema: z.object({ result: z.string() }),
|
|
228
|
+
});
|
|
216
229
|
|
|
217
230
|
export const testWorkflow = createWorkflow({...})
|
|
218
|
-
.then(
|
|
231
|
+
.then(step1)
|
|
219
232
|
.commit();
|
|
220
233
|
```
|
|
221
234
|
|
|
222
|
-
|
|
235
|
+
This throws an error from the step and stops workflow execution, returning the error as the result.
|
|
223
236
|
|
|
224
|
-
##
|
|
237
|
+
## Example Run Instance
|
|
225
238
|
|
|
226
|
-
|
|
239
|
+
The following example demonstrates how to start a run with multiple inputs. Each input will pass through the `mapStep` sequentially.
|
|
227
240
|
|
|
228
|
-
```typescript {
|
|
229
|
-
import {
|
|
230
|
-
import { z } from "zod";
|
|
241
|
+
```typescript {6} filename="src/test-workflow.ts" showLineNumbers copy
|
|
242
|
+
import { mastra } from "./mastra";
|
|
231
243
|
|
|
232
|
-
const
|
|
233
|
-
const workflow2 = createWorkflow({...});
|
|
244
|
+
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
|
|
234
245
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
246
|
+
const result = await run.start({
|
|
247
|
+
inputData: [{ number: 10 }, { number: 100 }, { number: 200 }]
|
|
248
|
+
});
|
|
238
249
|
```
|
|
239
250
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
## Cloning workflows
|
|
243
|
-
|
|
244
|
-
In the example below, `clonedWorkflow` is a clone of `workflow1` and is used as a step within `testWorkflow`. The `clonedWorkflow` is run sequentially after `step1`.
|
|
245
|
-
|
|
246
|
-
```typescript {5,9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
247
|
-
import { createWorkflow, createStep, cloneWorkflow } from "@mastra/core/workflows";
|
|
248
|
-
import { z } from "zod";
|
|
249
|
-
|
|
250
|
-
const step1 = createStep({...});
|
|
251
|
-
const clonedWorkflow = cloneWorkflow(step1, { id: "cloned-workflow" });
|
|
251
|
+
To execute this run from your terminal:
|
|
252
252
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
.then(clonedWorkflow)
|
|
256
|
-
.commit();
|
|
253
|
+
```bash copy
|
|
254
|
+
npx tsx src/test-workflow.ts
|
|
257
255
|
```
|
|
@@ -12,78 +12,75 @@ Input data mapping allows explicit mapping of values for the inputs of the next
|
|
|
12
12
|
- A constant value
|
|
13
13
|
- The initial input of the workflow
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Mapping with `.map()`
|
|
16
16
|
|
|
17
17
|
In this example the `output` from `step1` is transformed to match the `inputSchema` required for the `step2`. The value from `step1` is available using the `inputData` parameter of the `.map` function.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+
```typescript {9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
20
22
|
const step1 = createStep({...});
|
|
21
23
|
const step2 = createStep({...});
|
|
22
24
|
|
|
23
|
-
export const testWorkflow = createWorkflow({
|
|
24
|
-
id: "test-workflow",
|
|
25
|
-
description: 'Test workflow',
|
|
26
|
-
inputSchema: z.object({
|
|
27
|
-
input: z.number()
|
|
28
|
-
}),
|
|
29
|
-
outputSchema: z.object({
|
|
30
|
-
output: z.string()
|
|
31
|
-
})
|
|
32
|
-
})
|
|
25
|
+
export const testWorkflow = createWorkflow({...})
|
|
33
26
|
.then(step1)
|
|
34
|
-
.map(({ inputData }) => {
|
|
27
|
+
.map(async ({ inputData }) => {
|
|
35
28
|
const { value } = inputData;
|
|
36
29
|
return {
|
|
37
|
-
output:
|
|
30
|
+
output: `new ${value}`
|
|
38
31
|
};
|
|
39
32
|
})
|
|
40
33
|
.then(step2)
|
|
41
34
|
.commit();
|
|
42
35
|
```
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
## Using `inputData`
|
|
45
38
|
|
|
46
39
|
Use `inputData` to access the full output of the previous step:
|
|
47
40
|
|
|
48
|
-
```typescript {
|
|
41
|
+
```typescript {3} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
42
|
+
.then(step1)
|
|
49
43
|
.map(({ inputData }) => {
|
|
50
|
-
|
|
51
|
-
...
|
|
44
|
+
console.log(inputData);
|
|
52
45
|
})
|
|
53
46
|
```
|
|
54
47
|
|
|
55
|
-
|
|
48
|
+
## Using `getStepResult()`
|
|
56
49
|
|
|
57
50
|
Use `getStepResult` to access the full output of a specific step by referencing the step's instance:
|
|
58
51
|
|
|
59
|
-
```typescript {3} showLineNumbers
|
|
52
|
+
```typescript {3} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
60
53
|
.then(step1)
|
|
61
|
-
.map(({ getStepResult }) => {
|
|
54
|
+
.map(async ({ getStepResult }) => {
|
|
62
55
|
console.log(getStepResult(step1));
|
|
63
|
-
...
|
|
64
56
|
})
|
|
65
57
|
```
|
|
66
58
|
|
|
67
|
-
|
|
59
|
+
## Using `getInitData()`
|
|
68
60
|
|
|
69
61
|
Use `getInitData` to access the initial input data provided to the workflow:
|
|
70
62
|
|
|
71
|
-
```typescript {3} showLineNumbers
|
|
63
|
+
```typescript {3} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
72
64
|
.then(step1)
|
|
73
|
-
.map(({ getInitData }) => {
|
|
65
|
+
.map(async ({ getInitData }) => {
|
|
74
66
|
console.log(getInitData());
|
|
75
|
-
...
|
|
76
67
|
})
|
|
77
68
|
```
|
|
78
69
|
|
|
79
|
-
##
|
|
70
|
+
## Using `mapVariable()`
|
|
71
|
+
|
|
72
|
+
To use `mapVariable` import the necessary function from the workflows module:
|
|
80
73
|
|
|
81
|
-
|
|
74
|
+
```typescript filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
75
|
+
import { mapVariable } from "@mastra/core/workflows";
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Renaming step with `mapVariable()`
|
|
82
79
|
|
|
83
80
|
You can rename step outputs using the object syntax in `.map()`. In the example below, the `value` output from `step1` is renamed to `details`:
|
|
84
81
|
|
|
85
|
-
```typescript {3} showLineNumbers
|
|
86
|
-
.then(
|
|
82
|
+
```typescript {3-6} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
83
|
+
.then(step1)
|
|
87
84
|
.map({
|
|
88
85
|
details: mapVariable({
|
|
89
86
|
step: step,
|
|
@@ -92,24 +89,15 @@ You can rename step outputs using the object syntax in `.map()`. In the example
|
|
|
92
89
|
})
|
|
93
90
|
```
|
|
94
91
|
|
|
95
|
-
###
|
|
92
|
+
### Renaming workflows with `mapVariable()`
|
|
96
93
|
|
|
97
94
|
You can rename workflow outputs by using **referential composition**. This involves passing the workflow instance as the `initData`.
|
|
98
95
|
|
|
99
|
-
```typescript {
|
|
100
|
-
export const testWorkflow = createWorkflow({
|
|
101
|
-
id: "test-workflow",
|
|
102
|
-
description: 'Test workflow',
|
|
103
|
-
inputSchema: z.object({
|
|
104
|
-
input: z.string()
|
|
105
|
-
}),
|
|
106
|
-
outputSchema: z.object({
|
|
107
|
-
output: z.string()
|
|
108
|
-
})
|
|
109
|
-
});
|
|
96
|
+
```typescript {6-9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
97
|
+
export const testWorkflow = createWorkflow({...});
|
|
110
98
|
|
|
111
99
|
testWorkflow
|
|
112
|
-
.then(
|
|
100
|
+
.then(step1)
|
|
113
101
|
.map({
|
|
114
102
|
details: mapVariable({
|
|
115
103
|
initData: testWorkflow,
|
|
@@ -5,12 +5,14 @@ description: "Workflows in Mastra help you orchestrate complex sequences of oper
|
|
|
5
5
|
|
|
6
6
|
import { Steps } from "nextra/components";
|
|
7
7
|
|
|
8
|
-
# Workflows
|
|
8
|
+
# Workflows overview
|
|
9
9
|
|
|
10
10
|
Workflows let you define and orchestrate complex sequences of tasks as **typed steps** connected by data flows. Each step has clearly defined inputs and outputs validated by Zod schemas.
|
|
11
11
|
|
|
12
12
|
A workflow manages execution order, dependencies, branching, parallelism, and error handling — enabling you to build robust, reusable processes. Steps can be nested or cloned to compose larger workflows.
|
|
13
13
|
|
|
14
|
+

|
|
15
|
+
|
|
14
16
|
You create workflows by:
|
|
15
17
|
|
|
16
18
|
- Defining **steps** with `createStep`, specifying input/output schemas and business logic.
|
|
@@ -20,7 +22,7 @@ You create workflows by:
|
|
|
20
22
|
This structure provides full type safety and runtime validation, ensuring data integrity across the entire workflow.
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
## Getting
|
|
25
|
+
## Getting started
|
|
24
26
|
|
|
25
27
|
To use workflows, first import the necessary functions from the workflows module:
|
|
26
28
|
|
|
@@ -29,7 +31,7 @@ import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
|
29
31
|
import { z } from "zod";
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
### Create
|
|
34
|
+
### Create step
|
|
33
35
|
|
|
34
36
|
Steps are the building blocks of workflows. Create a step using `createStep`:
|
|
35
37
|
|
|
@@ -39,7 +41,7 @@ const step1 = createStep({...});
|
|
|
39
41
|
|
|
40
42
|
> See [createStep](/reference/workflows/step) for more information.
|
|
41
43
|
|
|
42
|
-
### Create
|
|
44
|
+
### Create workflow
|
|
43
45
|
|
|
44
46
|
Create a workflow using `createWorkflow` and complete it with `.commit()`.
|
|
45
47
|
|
|
@@ -65,7 +67,7 @@ export const testWorkflow = createWorkflow({
|
|
|
65
67
|
|
|
66
68
|
> See [workflow](/reference/workflows/workflow) for more information.
|
|
67
69
|
|
|
68
|
-
#### Composing
|
|
70
|
+
#### Composing steps
|
|
69
71
|
|
|
70
72
|
Workflow steps can be composed and executed sequentially using `.then()`.
|
|
71
73
|
|
|
@@ -93,8 +95,7 @@ export const testWorkflow = createWorkflow({
|
|
|
93
95
|
|
|
94
96
|
> Steps can be composed using a number of different methods. See [Control Flow](/docs/workflows/control-flow) for more information.
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
#### Cloning Steps
|
|
98
|
+
#### Cloning steps
|
|
98
99
|
|
|
99
100
|
Workflow steps can be cloned using `cloneStep()`, and used with any workflow method.
|
|
100
101
|
|
|
@@ -122,7 +123,7 @@ export const testWorkflow = createWorkflow({
|
|
|
122
123
|
.commit();
|
|
123
124
|
```
|
|
124
125
|
|
|
125
|
-
### Register
|
|
126
|
+
### Register workflow
|
|
126
127
|
|
|
127
128
|
Register a workflow using `workflows` in the main Mastra instance:
|
|
128
129
|
|
|
@@ -146,7 +147,7 @@ export const mastra = new Mastra({
|
|
|
146
147
|
});
|
|
147
148
|
```
|
|
148
149
|
|
|
149
|
-
### Run
|
|
150
|
+
### Run workflow
|
|
150
151
|
There are two ways to run and test workflows.
|
|
151
152
|
|
|
152
153
|
<Steps>
|
|
@@ -170,7 +171,13 @@ const result = await run.start({
|
|
|
170
171
|
}
|
|
171
172
|
});
|
|
172
173
|
|
|
174
|
+
// Dump the complete workflow result (includes status, steps and result)
|
|
173
175
|
console.log(JSON.stringify(result, null, 2));
|
|
176
|
+
|
|
177
|
+
// Get the workflow output value
|
|
178
|
+
if (result.status === 'success') {
|
|
179
|
+
console.log(`output value: ${result.result.output}`);
|
|
180
|
+
}
|
|
174
181
|
```
|
|
175
182
|
> see [createRunAsync](/reference/workflows/create-run) and [start](/reference/workflows/start) for more information.
|
|
176
183
|
|
|
@@ -182,7 +189,7 @@ npx tsx src/test-workflow.ts
|
|
|
182
189
|
|
|
183
190
|
</Steps>
|
|
184
191
|
|
|
185
|
-
#### Run
|
|
192
|
+
#### Run workflow results
|
|
186
193
|
|
|
187
194
|
The result of running a workflow using either `start()` or `resume()` will look like one of the following, depending on the outcome.
|
|
188
195
|
|
|
@@ -250,7 +257,7 @@ The result of running a workflow using either `start()` or `resume()` will look
|
|
|
250
257
|
```
|
|
251
258
|
- **error**: An optional field that includes the error message if the workflow fails
|
|
252
259
|
|
|
253
|
-
### Stream
|
|
260
|
+
### Stream workflow
|
|
254
261
|
|
|
255
262
|
Similar to the run method shown above, workflows can also be streamed:
|
|
256
263
|
|
|
@@ -294,7 +301,7 @@ const result = await run.start({
|
|
|
294
301
|
|
|
295
302
|
> See [watch](/reference/workflows/watch) for more information.
|
|
296
303
|
|
|
297
|
-
## More
|
|
304
|
+
## More resources
|
|
298
305
|
|
|
299
306
|
- The [Workflow Guide](../../guides/guide/ai-recruiter.mdx) in the Guides section is a tutorial that covers the main concepts.
|
|
300
307
|
- [Parallel Steps workflow example](../../examples/workflows/parallel-steps.mdx)
|
|
@@ -303,4 +310,7 @@ const result = await run.start({
|
|
|
303
310
|
- [Suspend and Resume workflow example](../../examples/workflows/human-in-the-loop.mdx)
|
|
304
311
|
|
|
305
312
|
|
|
313
|
+
## Workflows (Legacy)
|
|
314
|
+
|
|
315
|
+
For legacy workflow documentation, see [Workflows (Legacy)](/docs/workflows-legacy/overview).
|
|
306
316
|
|
|
@@ -16,7 +16,7 @@ You can pause execution using:
|
|
|
16
16
|
|
|
17
17
|
When using any of these methods, the workflow status is set to `waiting` until execution resumes.
|
|
18
18
|
|
|
19
|
-
## sleep
|
|
19
|
+
## Pausing with `.sleep()`
|
|
20
20
|
|
|
21
21
|
The `sleep()` method pauses execution between steps for a specified number of milliseconds.
|
|
22
22
|
|
|
@@ -34,7 +34,28 @@ export const testWorkflow = createWorkflow({...})
|
|
|
34
34
|
.commit();
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
### Pausing with `.sleep(callback)`
|
|
38
|
+
|
|
39
|
+
The `sleep()` method also accepts a callback that returns the number of milliseconds to pause. The callback receives `inputData`, allowing the delay to be computed dynamically.
|
|
40
|
+
|
|
41
|
+
```typescript {9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
42
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
43
|
+
import { z } from "zod";
|
|
44
|
+
|
|
45
|
+
const step1 = createStep({...});
|
|
46
|
+
const step2 = createStep({...});
|
|
47
|
+
|
|
48
|
+
export const testWorkflow = createWorkflow({...})
|
|
49
|
+
.then(step1)
|
|
50
|
+
.sleep(async ({ inputData }) => {
|
|
51
|
+
const { delayInMs } = inputData
|
|
52
|
+
return delayInMs;
|
|
53
|
+
})
|
|
54
|
+
.then(step2)
|
|
55
|
+
.commit();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Pausing with `.sleepUntil()`
|
|
38
59
|
|
|
39
60
|
The `sleepUntil()` method pauses execution between steps until a specified date.
|
|
40
61
|
|
|
@@ -52,12 +73,36 @@ export const testWorkflow = createWorkflow({...})
|
|
|
52
73
|
.commit();
|
|
53
74
|
```
|
|
54
75
|
|
|
76
|
+
### Pausing with `.sleepUntil(callback)`
|
|
77
|
+
|
|
78
|
+
The `sleepUntil()` method also accepts a callback that returns a `Date` object. The callback receives `inputData`, allowing the target time to be computed dynamically.
|
|
79
|
+
|
|
80
|
+
```typescript {9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
81
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
82
|
+
import { z } from "zod";
|
|
83
|
+
|
|
84
|
+
const step1 = createStep({...});
|
|
85
|
+
const step2 = createStep({...});
|
|
86
|
+
|
|
87
|
+
export const testWorkflow = createWorkflow({...})
|
|
88
|
+
.then(step1)
|
|
89
|
+
.sleepUntil(async ({ inputData }) => {
|
|
90
|
+
const { delayInMs } = inputData
|
|
91
|
+
return new Date(Date.now() + delayInMs);
|
|
92
|
+
})
|
|
93
|
+
.then(step2)
|
|
94
|
+
.commit();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
|
|
55
98
|
> `Date.now()` is evaluated when the workflow starts, not at the moment the `sleepUntil()` method is called.
|
|
56
99
|
|
|
57
|
-
## waitForEvent
|
|
100
|
+
## Pausing with `.waitForEvent()`
|
|
58
101
|
|
|
59
102
|
The `waitForEvent()` method pauses execution until a specific event is received. Use `run.sendEvent()` to send the event. You must provide both the event name and the step to resume.
|
|
60
103
|
|
|
104
|
+

|
|
105
|
+
|
|
61
106
|
```typescript {10} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
62
107
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
63
108
|
import { z } from "zod";
|
|
@@ -72,7 +117,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
72
117
|
.then(step3)
|
|
73
118
|
.commit();
|
|
74
119
|
```
|
|
75
|
-
## sendEvent
|
|
120
|
+
## Sending an event with `.sendEvent()`
|
|
76
121
|
|
|
77
122
|
The `.sendEvent()` method sends an event to the workflow. It accepts the event name and optional event data, which can be any JSON-serializable value.
|
|
78
123
|
|