@mastra/mcp-docs-server 0.13.5 → 0.13.6

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.
Files changed (80) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +76 -76
  2. package/.docs/organized/changelogs/%40mastra%2Fagui.md +61 -61
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +54 -54
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +194 -194
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +75 -75
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +91 -91
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +171 -171
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +237 -237
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +143 -143
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +143 -143
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +233 -233
  12. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +84 -84
  13. package/.docs/organized/changelogs/%40mastra%2Fevals.md +56 -56
  14. package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
  15. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +62 -62
  16. package/.docs/organized/changelogs/%40mastra%2Flance.md +55 -0
  17. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +56 -56
  18. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +25 -25
  19. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +25 -25
  20. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +119 -119
  21. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +58 -58
  22. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +69 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fpg.md +119 -119
  24. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +244 -244
  25. package/.docs/organized/changelogs/%40mastra%2Frag.md +61 -61
  26. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +18 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +195 -195
  28. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +76 -76
  29. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +44 -44
  30. package/.docs/organized/changelogs/create-mastra.md +119 -119
  31. package/.docs/organized/changelogs/mastra.md +256 -256
  32. package/.docs/organized/code-examples/agent.md +6 -0
  33. package/.docs/organized/code-examples/agui.md +3 -3
  34. package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
  35. package/.docs/organized/code-examples/ai-sdk-v5.md +201 -0
  36. package/.docs/organized/code-examples/assistant-ui.md +2 -2
  37. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +2 -2
  38. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +2 -2
  39. package/.docs/organized/code-examples/client-side-tools.md +1 -1
  40. package/.docs/organized/code-examples/crypto-chatbot.md +5 -5
  41. package/.docs/organized/code-examples/openapi-spec-writer.md +2 -2
  42. package/.docs/organized/code-examples/workflow-with-suspend-resume.md +181 -0
  43. package/.docs/raw/agents/agent-memory.mdx +126 -0
  44. package/.docs/raw/agents/dynamic-agents.mdx +34 -2
  45. package/.docs/raw/agents/overview.mdx +5 -0
  46. package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +60 -26
  47. package/.docs/raw/deployment/cloud-providers/index.mdx +44 -9
  48. package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +9 -30
  49. package/.docs/raw/deployment/serverless-platforms/index.mdx +13 -13
  50. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +291 -216
  51. package/.docs/raw/frameworks/agentic-uis/assistant-ui.mdx +0 -34
  52. package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +162 -181
  53. package/.docs/raw/frameworks/servers/express.mdx +1 -1
  54. package/.docs/raw/frameworks/web-frameworks/astro.mdx +2 -2
  55. package/.docs/raw/frameworks/web-frameworks/next-js.mdx +1 -1
  56. package/.docs/raw/frameworks/web-frameworks/sveltekit.mdx +4 -4
  57. package/.docs/raw/frameworks/web-frameworks/vite-react.mdx +1 -1
  58. package/.docs/raw/getting-started/installation.mdx +10 -7
  59. package/.docs/raw/getting-started/model-capability.mdx +1 -1
  60. package/.docs/raw/memory/overview.mdx +8 -0
  61. package/.docs/raw/memory/semantic-recall.mdx +6 -0
  62. package/.docs/raw/observability/tracing.mdx +30 -0
  63. package/.docs/raw/reference/agents/agent.mdx +2 -2
  64. package/.docs/raw/reference/cli/create-mastra.mdx +7 -0
  65. package/.docs/raw/reference/cli/dev.mdx +4 -3
  66. package/.docs/raw/reference/client-js/agents.mdx +8 -0
  67. package/.docs/raw/reference/memory/query.mdx +35 -14
  68. package/.docs/raw/reference/observability/providers/keywordsai.mdx +73 -0
  69. package/.docs/raw/reference/storage/mssql.mdx +108 -0
  70. package/.docs/raw/server-db/custom-api-routes.mdx +38 -26
  71. package/.docs/raw/tools-mcp/mcp-overview.mdx +24 -1
  72. package/.docs/raw/workflows/control-flow.mdx +85 -87
  73. package/.docs/raw/workflows/input-data-mapping.mdx +31 -43
  74. package/.docs/raw/workflows/overview.mdx +22 -12
  75. package/.docs/raw/workflows/pausing-execution.mdx +49 -4
  76. package/.docs/raw/workflows/suspend-and-resume.mdx +17 -16
  77. package/.docs/raw/workflows/using-with-agents-and-tools.mdx +16 -13
  78. package/.docs/raw/workflows-legacy/overview.mdx +11 -0
  79. package/package.json +6 -8
  80. 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
- ```typescript {8-9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
17
+ ![Chaining steps with .then()](/image/workflows/workflows-control-flow-then.jpg)
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
- ## Parallel steps with `.parallel()`:
34
+ ## Simultaneous steps with `.parallel()`
35
+
36
+ Execute steps simultaneously using `.parallel()`:
33
37
 
34
- Execute steps in parallel using `.parallel()`:
38
+ ![Concurrent steps with .parallel()](/image/workflows/workflows-control-flow-parallel.jpg)
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 branching (`.branch()`)
58
+ ## Conditional logic with `.branch()`
55
59
 
56
- Create conditional branches using `.branch()`:
60
+ Execute steps conditionally using `.branch()`:
57
61
 
58
- ```typescript {8-11} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
62
+ ![Conditional branching with .branch()](/image/workflows/workflows-control-flow-branch.jpg)
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 commands
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
- ### `.dowhile()`
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 a step repeatedly while a condition is true.
94
+ Executes step repeatedly while a condition is true.
95
+
96
+ ![Repeating with .dowhile()](/image/workflows/workflows-control-flow-dowhile.jpg)
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
- Executes a step repeatedly until a condition becomes true.
113
+ ![Repeating with .dountil()](/image/workflows/workflows-control-flow-dountil.jpg)
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
+ ![Repeating with .foreach()](/image/workflows/workflows-control-flow-foreach.jpg)
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
- ### Early exit with `.bail()`
143
+ #### Setting concurrency limits
129
144
 
130
- You can bail out of a workflow execution successfully by calling `bail()` in a step. This returns whatever payload is passed to the `bail()` function as the result of the workflow.
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 step1 = createStep({
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
- .then(step1)
154
+ .foreach(mapStep, { concurrency: 2 })
147
155
  .commit();
148
156
  ```
149
157
 
150
- Unsuccessful bails happen through throwing an error in the step.
158
+ ## Using a nested workflow
151
159
 
152
- ```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
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 step1 = createStep({
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(step1)
169
+ .then(nestedWorkflow)
167
170
  .commit();
168
171
  ```
169
172
 
170
- #### Example Run Instance
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
- const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
175
+ Use `cloneWorkflow` to duplicate an existing workflow. This lets you reuse its structure while overriding parameters like `id`.
178
176
 
179
- const result = await run.start({
180
- inputData: [{ number: 10 }, { number: 100 }, { number: 200 }]
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
- To execute this run from your terminal:
181
+ const step1 = createStep({...});
182
+ const parentWorkflow = createWorkflow({...})
183
+ const clonedWorkflow = cloneWorkflow(parentWorkflow, { id: "cloned-workflow" });
185
184
 
186
- ```bash copy
187
- npx tsx src/test-workflow.ts
185
+ export const testWorkflow = createWorkflow({...})
186
+ .then(step1)
187
+ .then(clonedWorkflow)
188
+ .commit();
188
189
  ```
189
190
 
190
- #### Concurrency
191
+ ## Exiting early with `bail()`
191
192
 
192
- Optionally, using `concurrency` allows you to execute steps in parallel with a limit on the number of concurrent executions.
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 mapStep = createStep({...})
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
- .foreach(mapStep, { concurrency: 2 })
209
+ .then(step1)
202
210
  .commit();
203
211
  ```
204
212
 
205
- ## Using a workflow as a step
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
- In the example below, `nestedWorkflow` is used as a step within `testWorkflow`. The `testWorkflow` uses `step1` while the `nestedWorkflow` composes `step2` and `step3`:
215
+ Use `throw new Error()` in a step to exit with an error.
210
216
 
211
- ```typescript {4,7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
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
- export const nestedWorkflow = createWorkflow({...})
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(nestedWorkflow)
231
+ .then(step1)
219
232
  .commit();
220
233
  ```
221
234
 
222
- When using `.branch()` or `.parallel()` to build more complex control flows, executing more than one step requires wrapping those steps in a nested workflow, along with a clear definition of how they should be executed.
235
+ This throws an error from the step and stops workflow execution, returning the error as the result.
223
236
 
224
- ## Running nested workflows in parallel
237
+ ## Example Run Instance
225
238
 
226
- Workflows themselves can also be executed in parallel.
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 {4-5,8} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
229
- import { createWorkflow, createStep } from "@mastra/core/workflows";
230
- import { z } from "zod";
241
+ ```typescript {6} filename="src/test-workflow.ts" showLineNumbers copy
242
+ import { mastra } from "./mastra";
231
243
 
232
- const workflow1 = createWorkflow({...});
233
- const workflow2 = createWorkflow({...});
244
+ const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
234
245
 
235
- export const testWorkflow = createWorkflow({...})
236
- .parallel([workflow1, workflow2])
237
- .commit();
246
+ const result = await run.start({
247
+ inputData: [{ number: 10 }, { number: 100 }, { number: 200 }]
248
+ });
238
249
  ```
239
250
 
240
- Parallel steps receive previous step results as input. Their outputs are passed into the next step input as an object where the key is the step `id` and the value is the step `output`.
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
- export const testWorkflow = createWorkflow({...})
254
- .then(step1)
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
- ## Map
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
- ```typescript {18} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
19
+ ![Mapping with .map()](/image/workflows/workflows-data-mapping-map.jpg)
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: `${value}`
30
+ output: `new ${value}`
38
31
  };
39
32
  })
40
33
  .then(step2)
41
34
  .commit();
42
35
  ```
43
36
 
44
- ### inputData
37
+ ## Using `inputData`
45
38
 
46
39
  Use `inputData` to access the full output of the previous step:
47
40
 
48
- ```typescript {2} showLineNumbers
41
+ ```typescript {3} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
42
+ .then(step1)
49
43
  .map(({ inputData }) => {
50
- const { value} = inputData;
51
- ...
44
+ console.log(inputData);
52
45
  })
53
46
  ```
54
47
 
55
- ### getStepResult
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
- ### getInitData
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
- ## Renaming Outputs
70
+ ## Using `mapVariable()`
71
+
72
+ To use `mapVariable` import the necessary function from the workflows module:
80
73
 
81
- ### Step Outputs
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(step)
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
- ### Workflow Outputs
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 {12, 16} showLineNumbers
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(cityCoordinatesStep)
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 Overview
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
+ ![Workflows overview](/image/workflows/workflows-overview.jpg)
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 Started
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 Step
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 Workflow
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 Steps
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 Workflow
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 Workflow
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 Workflow Results
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 Workflow
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 Resources
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
- ## sleepUntil
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
+ ![Pausing with .waitForEvent()](/image/workflows/workflows-sleep-events-waitforevent.jpg)
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