@mastra/mcp-docs-server 0.13.5-alpha.0 → 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.
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +76 -76
- package/.docs/organized/changelogs/%40mastra%2Fagui.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +54 -54
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +211 -211
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +75 -75
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +91 -91
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +185 -185
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +237 -237
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +143 -143
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +143 -143
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +235 -235
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +84 -84
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +75 -75
- package/.docs/organized/changelogs/%40mastra%2Flance.md +55 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +38 -38
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +119 -119
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +58 -58
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +69 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +119 -119
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +244 -244
- package/.docs/organized/changelogs/%40mastra%2Frag.md +73 -73
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +24 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +211 -211
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +76 -76
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +44 -44
- package/.docs/organized/changelogs/create-mastra.md +126 -126
- package/.docs/organized/changelogs/mastra.md +256 -256
- package/.docs/organized/code-examples/agent.md +6 -0
- package/.docs/organized/code-examples/agui.md +3 -3
- package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
- package/.docs/organized/code-examples/ai-sdk-v5.md +201 -0
- package/.docs/organized/code-examples/assistant-ui.md +2 -2
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +2 -2
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +2 -2
- package/.docs/organized/code-examples/client-side-tools.md +1 -1
- package/.docs/organized/code-examples/crypto-chatbot.md +5 -5
- package/.docs/organized/code-examples/openapi-spec-writer.md +2 -2
- 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 +21 -33
- package/.docs/raw/community/licensing.mdx +27 -19
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +60 -26
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +44 -9
- package/.docs/raw/deployment/server-deployment.mdx +56 -0
- package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +9 -30
- package/.docs/raw/deployment/serverless-platforms/index.mdx +13 -13
- 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/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/rag/retrieval.mdx +24 -5
- package/.docs/raw/reference/agents/agent.mdx +2 -2
- 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 +8 -0
- package/.docs/raw/reference/memory/query.mdx +35 -14
- package/.docs/raw/reference/observability/providers/keywordsai.mdx +73 -0
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +213 -0
- package/.docs/raw/reference/storage/mssql.mdx +108 -0
- package/.docs/raw/server-db/custom-api-routes.mdx +67 -0
- package/.docs/raw/server-db/production-server.mdx +66 -0
- package/.docs/raw/tools-mcp/mcp-overview.mdx +28 -7
- package/.docs/raw/workflows/control-flow.mdx +91 -93
- 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/LICENSE.md +11 -42
- package/package.json +7 -9
- package/.docs/raw/deployment/custom-api-routes.mdx +0 -55
- package/.docs/raw/deployment/server.mdx +0 -116
- package/.docs/raw/frameworks/ai-sdk-v5.mdx +0 -91
- /package/.docs/raw/{local-dev/mastra-dev.mdx → server-db/local-dev-playground.mdx} +0 -0
- /package/.docs/raw/{client-js/overview.mdx → server-db/mastra-client.mdx} +0 -0
- /package/.docs/raw/{deployment → server-db}/middleware.mdx +0 -0
- /package/.docs/raw/{storage/overview.mdx → server-db/storage.mdx} +0 -0
|
@@ -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
|
|
|
@@ -7,7 +7,6 @@ description: "Suspend and resume in Mastra workflows allows you to pause executi
|
|
|
7
7
|
|
|
8
8
|
Workflows can be paused at any step, with their current state persisted as a snapshot in storage. Execution can then be resumed from this saved snapshot when ready. Persisting the snapshot ensures the workflow state is maintained across sessions, deployments, and server restarts, essential for workflows that may remain suspended while awaiting external input or resources.
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
Common scenarios for suspending workflows include:
|
|
12
11
|
|
|
13
12
|
- Waiting for human approval or input
|
|
@@ -16,7 +15,7 @@ Common scenarios for suspending workflows include:
|
|
|
16
15
|
- Rate limiting or throttling expensive operations
|
|
17
16
|
- Handling event-driven processes with external triggers
|
|
18
17
|
|
|
19
|
-
## Workflow
|
|
18
|
+
## Workflow status types
|
|
20
19
|
|
|
21
20
|
When running a workflow, its `status` can be one of the following:
|
|
22
21
|
|
|
@@ -25,11 +24,13 @@ When running a workflow, its `status` can be one of the following:
|
|
|
25
24
|
- `success` - The workflow has completed
|
|
26
25
|
- `failed` - The workflow has failed
|
|
27
26
|
|
|
28
|
-
##
|
|
27
|
+
## Suspending a workflow with `suspend()`
|
|
29
28
|
|
|
30
29
|
When the state is `suspended`, you can identify any and all steps that have been suspended by looking at the `suspended` array of the workflow result output.
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
```typescript {18} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
33
34
|
const step1 = createStep({
|
|
34
35
|
id: "step-1",
|
|
35
36
|
description: "Test suspend",
|
|
@@ -44,14 +45,14 @@ const step1 = createStep({
|
|
|
44
45
|
city: z.string()
|
|
45
46
|
}),
|
|
46
47
|
execute: async ({ resumeData, suspend }) => {
|
|
47
|
-
|
|
48
|
+
const { city } = resumeData ?? {};
|
|
49
|
+
|
|
50
|
+
if (!city) {
|
|
48
51
|
await suspend({});
|
|
49
52
|
return { output: "" };
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
return {
|
|
53
|
-
output: ""
|
|
54
|
-
};
|
|
55
|
+
return { output: "" };
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
|
|
@@ -62,11 +63,11 @@ export const testWorkflow = createWorkflow({})
|
|
|
62
63
|
|
|
63
64
|
> See [Define Suspendable workflow](/examples/workflows/human-in-the-loop#define-suspendable-workflow) for more information.
|
|
64
65
|
|
|
65
|
-
### Identifying
|
|
66
|
+
### Identifying suspended steps
|
|
66
67
|
|
|
67
68
|
To resume a suspended workflow, inspect the `suspended` array in the result to determine which step needs input:
|
|
68
69
|
|
|
69
|
-
```typescript {15} filename="src/test-workflow.ts" showLineNumbers copy
|
|
70
|
+
```typescript {15} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
70
71
|
import { mastra } from "./mastra";
|
|
71
72
|
|
|
72
73
|
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
|
|
@@ -112,11 +113,11 @@ In this case, the logic resumes the first step listed in the `suspended` array.
|
|
|
112
113
|
|
|
113
114
|
> See [Run Workflow Results](/workflows/overview#run-workflow-results) for more details.
|
|
114
115
|
|
|
115
|
-
##
|
|
116
|
+
## Resuming a workflow with `resume()`
|
|
116
117
|
|
|
117
118
|
A workflow can be resumed by calling `resume` and providing the required `resumeData`.
|
|
118
119
|
|
|
119
|
-
```typescript {16-18} filename="src/test-workflow.ts" showLineNumbers copy
|
|
120
|
+
```typescript {16-18} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
120
121
|
import { mastra } from "./mastra";
|
|
121
122
|
|
|
122
123
|
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
|
|
@@ -141,11 +142,11 @@ if (result.status === "suspended") {
|
|
|
141
142
|
}
|
|
142
143
|
```
|
|
143
144
|
|
|
144
|
-
###
|
|
145
|
+
### Resuming nested workflows
|
|
145
146
|
|
|
146
147
|
To resume a suspended nested workflow pass the workflow instance to the `step` parameter of the `resume` function.
|
|
147
148
|
|
|
148
|
-
```typescript {
|
|
149
|
+
```typescript {33-34} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
149
150
|
const dowhileWorkflow = createWorkflow({
|
|
150
151
|
id: 'dowhile-workflow',
|
|
151
152
|
inputSchema: z.object({ value: z.number() }),
|
|
@@ -186,12 +187,12 @@ if (result.status === "suspended") {
|
|
|
186
187
|
}
|
|
187
188
|
```
|
|
188
189
|
|
|
189
|
-
## RuntimeContext
|
|
190
|
+
## Using `RuntimeContext` with suspend/resume
|
|
190
191
|
|
|
191
192
|
When using suspend/resume with `RuntimeContext`, you can create the instance yourself, and pass it to the `start` and `resume` functions.
|
|
192
193
|
`RuntimeContext` is not automatically shared on a workflow run.
|
|
193
194
|
|
|
194
|
-
```typescript {1,4,9,16} filename="src/test-workflow.
|
|
195
|
+
```typescript {1,4,9,16} filename="src/mastra/workflows/test-workflow.tss" showLineNumbers copy
|
|
195
196
|
import { RuntimeContext } from "@mastra/core/di";
|
|
196
197
|
import { mastra } from "./mastra";
|
|
197
198
|
|
|
@@ -11,14 +11,13 @@ Workflow steps are composable and typically run logic directly within the `execu
|
|
|
11
11
|
- Abstracting complex or reusable logic into a dedicated tool.
|
|
12
12
|
- Interacting with third-party APIs in a structured or reusable way.
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
Workflows can use Mastra agents or tools directly as steps, for example: `createStep(testAgent)` or `createStep(testTool)`.
|
|
16
15
|
|
|
17
|
-
##
|
|
16
|
+
## Using agents in workflows
|
|
18
17
|
|
|
19
18
|
To include an agent in a workflow, define it in the usual way, then either add it directly to the workflow using `createStep(testAgent)` or, invoke it from within a step's `execute` function using `.generate()`.
|
|
20
19
|
|
|
21
|
-
### Example
|
|
20
|
+
### Example agent
|
|
22
21
|
|
|
23
22
|
This agent uses OpenAI to generate a fact about a city, country, and timezone.
|
|
24
23
|
|
|
@@ -34,7 +33,7 @@ export const testAgent = new Agent({
|
|
|
34
33
|
});
|
|
35
34
|
```
|
|
36
35
|
|
|
37
|
-
###
|
|
36
|
+
### Adding an agent as a step
|
|
38
37
|
|
|
39
38
|
In this example, `step1` uses the `testAgent` to generate an interesting fact about the country based on a given city.
|
|
40
39
|
|
|
@@ -43,6 +42,9 @@ The `.map` method transforms the workflow input into a `prompt` string compatibl
|
|
|
43
42
|
The step is composed into the workflow using `.then()`, allowing it to receive the mapped input and return the agent's structured output. The workflow is finalized with `.commit()`.
|
|
44
43
|
|
|
45
44
|
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
|
|
46
48
|
```typescript {3} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
47
49
|
import { testAgent } from "../agents/test-agent";
|
|
48
50
|
|
|
@@ -68,7 +70,7 @@ export const testWorkflow = createWorkflow({
|
|
|
68
70
|
.commit();
|
|
69
71
|
```
|
|
70
72
|
|
|
71
|
-
###
|
|
73
|
+
### Calling an agent with `.generate()`
|
|
72
74
|
|
|
73
75
|
In this example, the `step1` builds a prompt using the provided `input` and passes it to the `testAgent`, which returns a plain-text response containing facts about the city and its country.
|
|
74
76
|
|
|
@@ -107,11 +109,11 @@ export const testWorkflow = createWorkflow({...})
|
|
|
107
109
|
.commit();
|
|
108
110
|
```
|
|
109
111
|
|
|
110
|
-
##
|
|
112
|
+
## Using tools in workflows
|
|
111
113
|
|
|
112
114
|
To use a tool within a workflow, define it in the usual way, then either add it directly to the workflow using `createStep(testTool)` or, invoke it from within a step's `execute` function using `.execute()`.
|
|
113
115
|
|
|
114
|
-
### Example
|
|
116
|
+
### Example tool
|
|
115
117
|
|
|
116
118
|
The example below uses the Open Meteo API to retrieve geolocation details for a city, returning its name, country, and timezone.
|
|
117
119
|
|
|
@@ -142,13 +144,14 @@ export const testTool = createTool({
|
|
|
142
144
|
});
|
|
143
145
|
```
|
|
144
146
|
|
|
145
|
-
|
|
146
|
-
### Tools as Step
|
|
147
|
+
### Adding a tool as a step
|
|
147
148
|
|
|
148
149
|
In this example, `step1` uses the `testTool`, which performs a geocoding lookup using the provided `city` and returns the resolved `country`.
|
|
149
150
|
|
|
150
151
|
The step is added to the workflow using the sequential `.then()` method, allowing it to receive input from the workflow and return structured output. The workflow is finalized with `.commit()`.
|
|
151
152
|
|
|
153
|
+

|
|
154
|
+
|
|
152
155
|
```typescript {1,3,6} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
153
156
|
import { testTool } from "../tools/test-tool";
|
|
154
157
|
|
|
@@ -159,7 +162,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
159
162
|
.commit();
|
|
160
163
|
```
|
|
161
164
|
|
|
162
|
-
###
|
|
165
|
+
### Calling a tool with `.execute()`
|
|
163
166
|
|
|
164
167
|
In this example, `step1` directly invokes `testTool` using its `.execute()` method. The tool performs a geocoding lookup with the provided `city` and returns the corresponding `country`.
|
|
165
168
|
|
|
@@ -201,7 +204,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
201
204
|
.commit();
|
|
202
205
|
```
|
|
203
206
|
|
|
204
|
-
##
|
|
207
|
+
## Using workflows as tools
|
|
205
208
|
|
|
206
209
|
In this example the `cityStringWorkflow` workflow has been added to the main Mastra instance.
|
|
207
210
|
|
|
@@ -255,7 +258,7 @@ export const cityCoordinatesTool = createTool({
|
|
|
255
258
|
});
|
|
256
259
|
```
|
|
257
260
|
|
|
258
|
-
##
|
|
261
|
+
## Exposing workflows with `MCPServer`
|
|
259
262
|
|
|
260
263
|
You can convert your workflows into tools by passing them into an instance of a Mastra `MCPServer`. This allows any MCP-compatible client to access your workflow.
|
|
261
264
|
|
|
@@ -316,7 +319,7 @@ Run the client script to see your workflow tool.
|
|
|
316
319
|
npx tsx src/test-mcp-client.ts
|
|
317
320
|
```
|
|
318
321
|
|
|
319
|
-
## More
|
|
322
|
+
## More resources
|
|
320
323
|
|
|
321
324
|
- [MCPServer reference documentation](/reference/tools/mcp-server).
|
|
322
325
|
- [MCPClient reference documentation](/reference/tools/mcp-client).
|
|
@@ -5,6 +5,17 @@ description: "Workflows in Mastra help you orchestrate complex sequences of oper
|
|
|
5
5
|
|
|
6
6
|
# Handling Complex LLM Operations with Workflows (Legacy)
|
|
7
7
|
|
|
8
|
+
All the legacy workflow documentation is available on the links below.
|
|
9
|
+
|
|
10
|
+
- [Steps](/docs/workflows-legacy/steps/)
|
|
11
|
+
- [Control Flow](/docs/workflows-legacy/control-flow/)
|
|
12
|
+
- [Variables](/docs/workflows-legacy/variables/)
|
|
13
|
+
- [Suspend & Resume](/docs/workflows-legacy/suspend-and-resume/)
|
|
14
|
+
- [Dynamic Workflows](/docs/workflows-legacy/dynamic-workflows/)
|
|
15
|
+
- [Error Handling](/docs/workflows-legacy/error-handling/)
|
|
16
|
+
- [Nested Workflows](/docs/workflows-legacy/nested-workflows/)
|
|
17
|
+
- [Runtime/Dynamic Variables](/docs/workflows-legacy/runtime-variables/)
|
|
18
|
+
|
|
8
19
|
Workflows in Mastra help you orchestrate complex sequences of operations with features like branching, parallel execution, resource suspension, and more.
|
|
9
20
|
|
|
10
21
|
## When to use workflows
|
package/LICENSE.md
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
17
|
-
|
|
18
|
-
**Patents**
|
|
19
|
-
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
20
|
-
|
|
21
|
-
**Notices**
|
|
22
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
23
|
-
|
|
24
|
-
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
25
|
-
|
|
26
|
-
**No Other Rights**
|
|
27
|
-
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
28
|
-
|
|
29
|
-
**Termination**
|
|
30
|
-
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
31
|
-
|
|
32
|
-
**No Liability**
|
|
33
|
-
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
34
|
-
|
|
35
|
-
**Definitions**
|
|
36
|
-
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
37
|
-
|
|
38
|
-
_you_ refers to the individual or entity agreeing to these terms.
|
|
39
|
-
|
|
40
|
-
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
41
|
-
|
|
42
|
-
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
43
|
-
|
|
44
|
-
_use_ means anything you do with the software requiring one of your licenses.
|
|
45
|
-
|
|
46
|
-
_trademark_ means trademarks, service marks, and similar rights.
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|