@mastra/mcp-docs-server 0.13.11-alpha.1 → 0.13.11-alpha.2

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 (72) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +15 -15
  2. package/.docs/organized/changelogs/%40mastra%2Fcore.md +14 -14
  3. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +22 -22
  4. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +21 -21
  5. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +13 -13
  6. package/.docs/organized/changelogs/%40mastra%2Flance.md +15 -12
  7. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +13 -13
  8. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +14 -14
  9. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +13 -13
  10. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +14 -14
  11. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +13 -13
  12. package/.docs/organized/changelogs/%40mastra%2Fpg.md +17 -17
  13. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +18 -18
  14. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +14 -14
  15. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fserver.md +15 -15
  17. package/.docs/organized/changelogs/create-mastra.md +11 -11
  18. package/.docs/organized/changelogs/mastra.md +24 -24
  19. package/.docs/organized/code-examples/a2a.md +52 -19
  20. package/.docs/organized/code-examples/weather-agent.md +14 -0
  21. package/.docs/raw/auth/jwt.mdx +3 -1
  22. package/.docs/raw/evals/overview.mdx +8 -0
  23. package/.docs/raw/getting-started/installation.mdx +45 -7
  24. package/.docs/raw/getting-started/mcp-docs-server.mdx +3 -3
  25. package/.docs/raw/memory/overview.mdx +11 -5
  26. package/.docs/raw/reference/agents/agent.mdx +6 -2
  27. package/.docs/raw/reference/agents/generate.mdx +48 -40
  28. package/.docs/raw/reference/agents/getAgent.mdx +10 -5
  29. package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +22 -17
  30. package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +22 -17
  31. package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +22 -17
  32. package/.docs/raw/reference/agents/getDescription.mdx +9 -5
  33. package/.docs/raw/reference/agents/getInstructions.mdx +22 -17
  34. package/.docs/raw/reference/agents/getLLM.mdx +23 -18
  35. package/.docs/raw/reference/agents/getMemory.mdx +22 -17
  36. package/.docs/raw/reference/agents/getModel.mdx +22 -17
  37. package/.docs/raw/reference/agents/getScorers.mdx +22 -17
  38. package/.docs/raw/reference/agents/getTools.mdx +22 -17
  39. package/.docs/raw/reference/agents/getVoice.mdx +22 -17
  40. package/.docs/raw/reference/agents/getWorkflows.mdx +22 -17
  41. package/.docs/raw/reference/agents/stream.mdx +24 -19
  42. package/.docs/raw/reference/agents/streamVNext.mdx +18 -19
  43. package/.docs/raw/reference/storage/upstash.mdx +5 -0
  44. package/.docs/raw/reference/tools/create-tool.mdx +22 -29
  45. package/.docs/raw/reference/tools/graph-rag-tool.mdx +2 -2
  46. package/.docs/raw/reference/tools/vector-query-tool.mdx +3 -3
  47. package/.docs/raw/reference/workflows/branch.mdx +6 -6
  48. package/.docs/raw/reference/workflows/commit.mdx +5 -5
  49. package/.docs/raw/reference/workflows/create-run.mdx +28 -29
  50. package/.docs/raw/reference/workflows/dountil.mdx +5 -5
  51. package/.docs/raw/reference/workflows/dowhile.mdx +5 -5
  52. package/.docs/raw/reference/workflows/execute.mdx +83 -91
  53. package/.docs/raw/reference/workflows/foreach.mdx +5 -5
  54. package/.docs/raw/reference/workflows/map.mdx +8 -93
  55. package/.docs/raw/reference/workflows/parallel.mdx +5 -5
  56. package/.docs/raw/reference/workflows/resume.mdx +45 -47
  57. package/.docs/raw/reference/workflows/sendEvent.mdx +5 -5
  58. package/.docs/raw/reference/workflows/sleep.mdx +5 -5
  59. package/.docs/raw/reference/workflows/sleepUntil.mdx +16 -8
  60. package/.docs/raw/reference/workflows/start.mdx +42 -27
  61. package/.docs/raw/reference/workflows/step.mdx +15 -29
  62. package/.docs/raw/reference/workflows/stream.mdx +55 -205
  63. package/.docs/raw/reference/workflows/streamVNext.mdx +55 -174
  64. package/.docs/raw/reference/workflows/then.mdx +5 -5
  65. package/.docs/raw/reference/workflows/waitForEvent.mdx +5 -5
  66. package/.docs/raw/reference/workflows/watch.mdx +31 -13
  67. package/.docs/raw/reference/workflows/workflow.mdx +27 -100
  68. package/.docs/raw/scorers/overview.mdx +8 -0
  69. package/.docs/raw/server-db/local-dev-playground.mdx +16 -1
  70. package/dist/tools/__tests__/test-setup.d.ts +1 -1
  71. package/dist/tools/__tests__/test-setup.d.ts.map +1 -1
  72. package/package.json +5 -5
@@ -1,234 +1,84 @@
1
1
  ---
2
- title: "Reference: Workflow.stream() | Building Workflows | Mastra Docs"
3
- description: Documentation for the `.stream()` method in workflows, which allows you to monitor the execution of a workflow run as a stream.
2
+ title: "Reference: WorkflowRun.stream() | Workflows | Mastra Docs"
3
+ description: Documentation for the `WorkflowRun.stream()` method in workflows, which allows you to monitor the execution of a workflow run as a stream.
4
4
  ---
5
5
 
6
- # Run.stream()
6
+ # WorkflowRun.stream()
7
7
 
8
8
  The `.stream()` method allows you to monitor the execution of a workflow run, providing real-time updates on the status of steps.
9
9
 
10
- ## Usage
10
+ ## Usage example
11
11
 
12
- ```typescript
13
- const run = await myWorkflow.createRunAsync();
12
+ ```typescript showLineNumbers copy
13
+ const run = await workflow.createRunAsync();
14
14
 
15
- // Add a stream to monitor execution
16
- const result = run.stream({ inputData: {...} });
17
-
18
-
19
- for (const chunk of stream) {
20
- // do something with the chunk
21
- }
15
+ const stream = await run.stream({
16
+ inputData: {
17
+ value: "initial data",
18
+ },
19
+ });
22
20
  ```
23
21
 
24
- ## Messages
22
+ ## Parameters
25
23
 
26
24
  <PropertiesTable
27
25
  content={[
28
26
  {
29
- name: "start",
30
- type: "object",
31
- description: "The workflow starts",
32
- isOptional: false,
33
- properties: [
34
- {
35
- type: "object",
36
- parameters: [
37
- {
38
- name: "example",
39
- type: "{ type: 'start', payload: { runId: '1' } }",
40
- description: "Example message structure",
41
- isOptional: false,
42
- },
43
- ],
44
- },
45
- ],
46
- },
47
- {
48
- name: "step-start",
49
- type: "object",
50
- description: "The start of a step",
51
- isOptional: false,
52
- properties: [
53
- {
54
- type: "object",
55
- parameters: [
56
- {
57
- name: "example",
58
- type: "{ type: 'step-start', payload: { id: 'fetch-weather' } }",
59
- description: "Example message structure",
60
- isOptional: false,
61
- },
62
- ],
63
- },
64
- ],
65
- },
66
- {
67
- name: "tool-call",
68
- type: "object",
69
- description: "A tool call has started",
70
- isOptional: false,
71
- properties: [
72
- {
73
- type: "object",
74
- parameters: [
75
- {
76
- name: "example",
77
- type: "{ type: 'tool-call', toolCallId: 'weatherAgent', toolName: 'Weather Agent', args: { prompt: 'Based on the following weather forecast for New York, suggest appropriate activities:...' } }",
78
- description: "Example message structure",
79
- isOptional: false,
80
- },
81
- ],
82
- },
83
- ],
84
- },
85
- {
86
- name: "tool-call-streaming-start",
87
- type: "object",
88
- description: "A tool call/agent has started",
89
- isOptional: false,
90
- properties: [
91
- {
92
- type: "object",
93
- parameters: [
94
- {
95
- name: "example",
96
- type: "{ type: 'tool-call-streaming-start', toolCallId: 'weatherAgent', toolName: 'Weather Agent', args: { prompt: 'Based on the following weather forecast for New York, suggest appropriate activities:...' } }",
97
- description: "Example message structure",
98
- isOptional: false,
99
- },
100
- ],
101
- },
102
- ],
27
+ name: "inputData",
28
+ type: "z.infer<TInput>",
29
+ description: "Input data that matches the workflow's input schema",
30
+ isOptional: true,
103
31
  },
104
32
  {
105
- name: "tool-call-delta",
106
- type: "object",
107
- description: "The delta of the tool output",
108
- isOptional: false,
109
- properties: [
110
- {
111
- type: "object",
112
- parameters: [
113
- {
114
- name: "example",
115
- type: "{ type: 'tool-call-delta', toolCallId: 'weatherAgent', toolName: 'Weather Agent', args: { prompt: 'Based on the following weather forecast for New York, suggest appropriate activities:\\n' + ' [\\n' + ' {\\n' + ' \"date\": \"2025-05-16\",\\n' + ' \"maxTemp\": 22.2,\\n' + ' \"minTemp\": 16,\\n' + ' \"precipitationChance\": 5,\\n' + ' \"condition\": \"Dense drizzle\",\\n' + ' \"location\": \"New York\"\\n' + ' },\\n' + ' ' }, argsTextDelta: '📅' }",
116
- description: "Example message structure",
117
- isOptional: false,
118
- },
119
- ],
120
- },
121
- ],
122
- },
123
- {
124
- name: "step-result",
125
- type: "object",
126
- description: "The result of a step",
127
- isOptional: false,
128
- properties: [
129
- {
130
- type: "object",
131
- parameters: [
132
- {
133
- name: "example",
134
- type: "{ type: 'step-result', payload: { id: 'Weather Agent', status: 'success', output: [Object] } }",
135
- description: "Example message structure",
136
- isOptional: false,
137
- },
138
- ],
139
- },
140
- ],
141
- },
142
- {
143
- name: "step-finish",
144
- type: "object",
145
- description: "The end of a step",
146
- isOptional: false,
147
- properties: [
148
- {
149
- type: "object",
150
- parameters: [
151
- {
152
- name: "example",
153
- type: "{ type: 'step-finish', payload: { id: 'Weather Agent', metadata: {} } }",
154
- description: "Example message structure",
155
- isOptional: false,
156
- },
157
- ],
158
- },
159
- ],
160
- },
161
- {
162
- name: "finish",
163
- type: "object",
164
- description: "The end of the workflow",
165
- isOptional: false,
166
- properties: [
167
- {
168
- type: "object",
169
- parameters: [
170
- {
171
- name: "example",
172
- type: "{ type: 'finish', payload: { runId: '1' } }",
173
- description: "Example message structure",
174
- isOptional: false,
175
- },
176
- ],
177
- },
178
- ],
33
+ name: "runtimeContext",
34
+ type: "RuntimeContext",
35
+ description: "Runtime context data to use during workflow execution",
36
+ isOptional: true,
179
37
  },
180
38
  ]}
181
39
  />
182
40
 
183
- ## Parameters
41
+ ## Returns
184
42
 
185
43
  <PropertiesTable
186
44
  content={[
187
45
  {
188
- name: "params",
189
- type: "object",
190
- description: "Configuration object for starting the workflow run",
191
- isOptional: false,
192
- properties: [
193
- {
194
- name: "inputData",
195
- type: "z.infer<TInput>",
196
- parameters: [
197
- {
198
- name: "z.infer<TInput>",
199
- type: "inputData",
200
- description:
201
- "Runtime context data to use when starting the workflow",
202
- isOptional: true,
203
- },
204
- ],
205
- },
206
- {
207
- name: "runtimeContext",
208
- type: "RuntimeContext",
209
- parameters: [
210
- {
211
- name: "runtimeContext",
212
- type: "RuntimeContext",
213
- description:
214
- "Runtime context data to use when starting the workflow",
215
- isOptional: true,
216
- },
217
- ],
218
- },
219
- ],
46
+ name: "stream",
47
+ type: "ReadableStream<StreamEvent>",
48
+ description: "A readable stream that emits workflow execution events in real-time",
220
49
  },
221
- ]}
222
- />
223
-
224
- ## Returns
225
-
226
- <PropertiesTable
227
- content={[
228
50
  {
229
- name: "result",
230
- type: "Promise<WorkflowResult<TOutput, TSteps>>",
231
- description: "A stream that pipes each step to the stream",
51
+ name: "getWorkflowState",
52
+ type: "() => Promise<WorkflowResult<TOutput, TSteps>>",
53
+ description: "A function that returns a promise resolving to the final workflow result",
232
54
  },
233
55
  ]}
234
56
  />
57
+
58
+ ## Extended usage example
59
+
60
+ ```typescript showLineNumbers copy
61
+ const { getWorkflowState } = await run.stream({
62
+ inputData: {
63
+ value: "initial data"
64
+ }
65
+ });
66
+
67
+ const result = await getWorkflowState();
68
+ ```
69
+
70
+ ## Stream Events
71
+
72
+ The stream emits various event types during workflow execution. Each event has a `type` field and a `payload` containing relevant data:
73
+
74
+ - **`start`**: Workflow execution begins
75
+ - **`step-start`**: A step begins execution
76
+ - **`tool-call`**: A tool call is initiated
77
+ - **`tool-call-streaming-start`**: Tool call streaming begins
78
+ - **`tool-call-delta`**: Incremental tool output updates
79
+ - **`step-result`**: A step completes with results
80
+ - **`step-finish`**: A step finishes execution
81
+ - **`finish`**: Workflow execution completes
82
+
83
+
84
+
@@ -1,215 +1,96 @@
1
1
  ---
2
- title: "Reference: Workflow.streamVNext() | Streaming | Workflows | Mastra Docs"
3
- description: Documentation for the `.streamVNext()` method in Mastra workflows, which enables real-time streaming of responses.
2
+ title: "Reference: WorkflowRun.streamVNext() | Workflows | Mastra Docs"
3
+ description: Documentation for the `WorkflowRun.streamVNext()` method in workflows, which enables real-time streaming of responses.
4
4
  ---
5
5
 
6
- # `streamVNext()`
6
+ # WorkflowRun.streamVNext()
7
7
 
8
- The `streamVNext()` method enables real-time streaming of responses from a workflow.
8
+ The `.streamVNext()` method enables real-time streaming of responses from a workflow.
9
9
 
10
- ## Usage
10
+ ## Usage example
11
11
 
12
- ```typescript
13
- const run = await myWorkflow.createRunAsync();
14
-
15
- // Add a stream to monitor execution
16
- const stream = run.streamVNext({ inputData: {...} });
17
-
18
-
19
- for (const chunk of stream) {
20
- // do something with the chunk
21
- }
12
+ ```typescript showLineNumbers copy
13
+ const run = await workflow.createRunAsync();
22
14
 
15
+ const stream = run.streamVNext({
16
+ inputData: {
17
+ value: "initial data",
18
+ },
19
+ });
23
20
  ```
24
21
 
25
- ## Protocol
22
+ ## Parameters
26
23
 
27
24
  <PropertiesTable
28
25
  content={[
29
26
  {
30
- name: "start",
31
- type: "object",
32
- description: "The workflow starts",
33
- isOptional: false,
34
- properties: [
35
- {
36
- type: "object",
37
- parameters: [
38
- {
39
- name: "example",
40
- type: "{ type: 'start', runId: '1', from: 'WORKFLOW', payload: { runId: '1' } }",
41
- description: "Example message structure",
42
- isOptional: false,
43
- },
44
- ],
45
- },
46
- ],
47
- },
48
- {
49
- name: "step-start",
50
- type: "object",
51
- description: "The start of a step",
52
- isOptional: false,
53
- properties: [
54
- {
55
- type: "object",
56
- parameters: [
57
- {
58
- name: "example",
59
- type: "{ type: 'step-start', runId: '1', from: 'WORKFLOW', payload: { id: 'fetch-weather' } }",
60
- description: "Example message structure",
61
- isOptional: false,
62
- },
63
- ],
64
- },
65
- ],
66
- },
67
- {
68
- name: "step-output",
69
- type: "object",
70
- description: "Custom output from a step",
71
- isOptional: false,
72
- properties: [
73
- {
74
- type: "object",
75
- parameters: [
76
- {
77
- name: "example",
78
- type: "{ type: 'step-output', runId: '1', from: 'WORKFLOW', payload: { stepName: 'my step', args: { ... }, stepCallId: 'uuid', startedAt: 1717000000000, status: 'running' } }",
79
- description: "Example message structure",
80
- isOptional: false,
81
- },
82
- ],
83
- },
84
- ],
85
- },
86
- {
87
- name: "step-result",
88
- type: "object",
89
- description: "The result of a step",
90
- isOptional: false,
91
- properties: [
92
- {
93
- type: "object",
94
- parameters: [
95
- {
96
- name: "example",
97
- type: "{ type: 'step-result', runId: '1', from: 'WORKFLOW', payload: { stepName: 'my step', result: { ... }, stepCallId: 'uuid', endedAt: 1717000000000, status: 'success', output: [Object] } }",
98
- description: "Example message structure",
99
- isOptional: false,
100
- },
101
- ],
102
- },
103
- ],
27
+ name: "inputData",
28
+ type: "z.infer<TInput>",
29
+ description: "Input data that matches the workflow's input schema",
30
+ isOptional: true,
104
31
  },
105
32
  {
106
- name: "finish",
107
- type: "object",
108
- description: "The end of the workflow",
109
- isOptional: false,
110
- properties: [
111
- {
112
- type: "object",
113
- parameters: [
114
- {
115
- name: "example",
116
- type: "{ type: 'finish', runId: '1', from: 'WORKFLOW', payload: { totalUsage: { promptTokens: 100, completionTokens: 100, totalTokens: 200 } } }",
117
- description: "Example message structure",
118
- isOptional: false,
119
- },
120
- ],
121
- },
122
- ],
33
+ name: "runtimeContext",
34
+ type: "RuntimeContext",
35
+ description: "Runtime context data to use during workflow execution",
36
+ isOptional: true,
123
37
  },
124
38
  ]}
125
39
  />
126
40
 
127
41
  ## Returns
128
42
 
129
- ### PropertiesTable for Return Values
130
-
131
43
  <PropertiesTable
132
44
  content={[
133
45
  {
134
- name: "usage",
135
- type: "Promise<object>",
136
- isOptional: true,
137
- description:
138
- "Total usage of the workflow, including sub agents/workflows as a step.",
139
- properties: [
140
- {
141
- type: "number",
142
- parameters: [
143
- {
144
- name: "promptTokens",
145
- type: "number",
146
- isOptional: true,
147
- description: "The number of prompt tokens used by the agent.",
148
- },
149
- ],
150
- },
151
- {
152
- type: "number",
153
- parameters: [
154
- {
155
- name: "completionTokens",
156
- type: "number",
157
- isOptional: true,
158
- description: "The number of completion tokens used by the agent.",
159
- },
160
- ],
161
- },
162
- {
163
- type: "number",
164
- parameters: [
165
- {
166
- name: "totalTokens",
167
- type: "number",
168
- isOptional: true,
169
- description: "The total number of tokens used by the agent.",
170
- },
171
- ],
172
- },
173
- ],
46
+ name: "stream",
47
+ type: "MastraWorkflowStream<ChunkType>",
48
+ description: "A custom stream that extends ReadableStream<ChunkType> with additional workflow-specific properties",
174
49
  },
175
50
  {
176
- name: "status",
177
- type: "Promise<string>",
178
- isOptional: true,
179
- description:
180
- "The status of the workflow run.",
51
+ name: "stream.status",
52
+ type: "Promise<WorkflowRunStatus>",
53
+ description: "A promise that resolves to the current workflow run status",
181
54
  },
182
55
  {
183
- name: "result",
184
- type: "Promise<object>",
185
- isOptional: true,
186
- description:
187
- "The result of the workflow run.",
56
+ name: "stream.result",
57
+ type: "Promise<WorkflowResult<TOutput, TSteps>>",
58
+ description: "A promise that resolves to the final workflow result",
59
+ },
60
+ {
61
+ name: "stream.usage",
62
+ type: "Promise<{ promptTokens: number; completionTokens: number; totalTokens: number }>",
63
+ description: "A promise that resolves to token usage statistics",
188
64
  },
189
65
  ]}
190
66
  />
191
67
 
192
- ## Examples
68
+ ## Extended usage example
193
69
 
194
- ### Basic Streaming
70
+ ```typescript showLineNumbers copy
71
+ const run = await workflow.createRunAsync();
195
72
 
196
- ```typescript
197
- const run = await myWorkflow.createRunAsync();
198
- const stream = run.streamVNext({ inputData: {...} });
73
+ const stream = run.streamVNext({
74
+ inputData: {
75
+ value: "initial data",
76
+ },
77
+ });
199
78
 
200
- for await (const chunk of stream) {
201
- process.stdout.write(chunk);
202
- }
79
+ const result = await stream.result;
203
80
  ```
204
81
 
205
- ### Structured Output Streaming
82
+ ## Stream Events
83
+
84
+ The stream emits various event types during workflow execution. Each event has a `type` field and a `payload` containing relevant data:
85
+
86
+ - **`start`**: Workflow execution begins
87
+ - **`step-start`**: A step begins execution
88
+ - **`step-output`**: Custom output from a step
89
+ - **`step-result`**: A step completes with results
90
+ - **`finish`**: Workflow execution completes with usage statistics
91
+
92
+
206
93
 
207
- ```typescript
208
- const run = await myWorkflow.createRunAsync();
209
- const stream = run.streamVNext({ inputData: {...} });
210
94
 
211
95
 
212
- const result = await stream.result;
213
- console.log("Final structured result:", result);
214
- ```
215
96
 
@@ -1,16 +1,16 @@
1
1
  ---
2
- title: "Reference: Workflow.then() | Building Workflows | Mastra Docs"
3
- description: Documentation for the `.then()` method in workflows, which creates sequential dependencies between steps.
2
+ title: "Reference: Workflow.then() | Workflows | Mastra Docs"
3
+ description: Documentation for the `Workflow.then()` method in workflows, which creates sequential dependencies between steps.
4
4
  ---
5
5
 
6
6
  # Workflow.then()
7
7
 
8
8
  The `.then()` method creates a sequential dependency between workflow steps, ensuring steps execute in a specific order.
9
9
 
10
- ## Usage
10
+ ## Usage example
11
11
 
12
- ```typescript
13
- workflow.then(stepOne).then(stepTwo);
12
+ ```typescript copy
13
+ workflow.then(step1).then(step2);
14
14
  ```
15
15
 
16
16
  ## Parameters
@@ -1,16 +1,16 @@
1
1
  ---
2
- title: "Reference: Workflow.waitForEvent() | Building Workflows | Mastra Docs"
3
- description: Documentation for the `.waitForEvent()` method in workflows, which pauses execution until an event is received.
2
+ title: "Reference: Workflow.waitForEvent() | Workflows | Mastra Docs"
3
+ description: Documentation for the `Workflow.waitForEvent()` method in workflows, which pauses execution until an event is received.
4
4
  ---
5
5
 
6
6
  # Workflow.waitForEvent()
7
7
 
8
8
  The `.waitForEvent()` method pauses execution until an event is received.
9
9
 
10
- ## Usage
10
+ ## Usage example
11
11
 
12
- ```typescript
13
- workflow.waitForEvent('my-event-name', step1);
12
+ ```typescript copy
13
+ workflow.waitForEvent('event-name', step1);
14
14
  ```
15
15
 
16
16
  ## Parameters
@@ -1,24 +1,22 @@
1
1
  ---
2
- title: "Reference: Workflow.watch() | Building Workflows | Mastra Docs"
3
- description: Documentation for the `.watch()` method in workflows, which allows you to monitor the execution of a workflow run.
2
+ title: "Reference: WorkflowRun.watch() | Workflows | Mastra Docs"
3
+ description: Documentation for the `WorkflowRun.watch()` method in workflows, which allows you to monitor the execution of a workflow run.
4
4
  ---
5
5
 
6
- # Workflow.watch()
6
+ # WorkflowRun.watch()
7
7
 
8
8
  The `.watch()` method allows you to monitor the execution of a workflow run, providing real-time updates on the status of steps.
9
9
 
10
- ## Usage
10
+ ## Usage example
11
11
 
12
- ```typescript
13
- const run = await myWorkflow.createRunAsync();
12
+ ```typescript showLineNumbers copy
13
+ const run = await workflow.createRunAsync();
14
14
 
15
- // Add a watcher to monitor execution
16
15
  run.watch(event => {
17
- console.log('Step completed:', event.payload.currentStep.id);
16
+ console.log('Step completed:', event?.payload?.currentStep?.id);
18
17
  });
19
18
 
20
- // Start the workflow
21
- const result = await run.start({ inputData: {...} });
19
+ const result = await run.start({ inputData: { value: "initial data" } });
22
20
  ```
23
21
 
24
22
  ## Parameters
@@ -26,15 +24,22 @@ const result = await run.start({ inputData: {...} });
26
24
  <PropertiesTable
27
25
  content={[
28
26
  {
29
- name: "cb",
27
+ name: "callback",
30
28
  type: "(event: WatchEvent) => void",
31
- description:
32
- "A callback function that is called whenever a step is completed or the workflow state changes",
29
+ description: "A callback function that is called whenever a step is completed or the workflow state changes. The event parameter contains: type ('watch'), payload (currentStep and workflowState), and eventTimestamp",
33
30
  isOptional: false,
34
31
  },
32
+ {
33
+ name: "type",
34
+ type: "'watch' | 'watch-v2'",
35
+ description: "The type of watch events to listen for. 'watch' for step completion events, 'watch-v2' for data stream events",
36
+ isOptional: true,
37
+ defaultValue: "'watch'",
38
+ },
35
39
  ]}
36
40
  />
37
41
 
42
+
38
43
  ## Returns
39
44
 
40
45
  <PropertiesTable
@@ -48,6 +53,19 @@ const result = await run.start({ inputData: {...} });
48
53
  ]}
49
54
  />
50
55
 
56
+ ## Extended usage example
57
+
58
+ ```typescript showLineNumbers copy
59
+ const run = await workflow.createRunAsync();
60
+
61
+ run.watch((event) => {
62
+ console.log("Step completed:", event?.payload?.currentStep?.id);
63
+ }, 'watch');
64
+
65
+
66
+ const result = await run.start({ inputData: { value: "initial data" } });
67
+ ```
68
+
51
69
  ## Related
52
70
 
53
71
  - [Suspend and resume](../../docs/workflows/suspend-and-resume.mdx)