@mastra/mcp-docs-server 0.13.46-alpha.0 → 0.13.46-alpha.1

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 (42) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
  2. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +11 -11
  3. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +79 -79
  4. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +52 -52
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +11 -11
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +49 -49
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +18 -18
  10. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +12 -12
  11. package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
  12. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +11 -11
  13. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +8 -8
  14. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +9 -9
  15. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +11 -11
  16. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +12 -12
  17. package/.docs/organized/changelogs/%40mastra%2Fpg.md +11 -11
  18. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +17 -17
  19. package/.docs/organized/changelogs/%40mastra%2Freact.md +8 -8
  20. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fserver.md +54 -54
  22. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +12 -12
  23. package/.docs/organized/changelogs/create-mastra.md +11 -11
  24. package/.docs/organized/changelogs/mastra.md +18 -18
  25. package/.docs/raw/observability/otel-tracing.mdx +17 -2
  26. package/.docs/raw/observability/overview.mdx +12 -2
  27. package/.docs/raw/rag/vector-databases.mdx +58 -0
  28. package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
  29. package/.docs/raw/reference/workflows/run-methods/restart.mdx +98 -0
  30. package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
  31. package/.docs/raw/reference/workflows/run.mdx +21 -0
  32. package/.docs/raw/reference/workflows/step.mdx +7 -0
  33. package/.docs/raw/reference/workflows/workflow.mdx +19 -0
  34. package/.docs/raw/server-db/mastra-server.mdx +1 -1
  35. package/.docs/raw/workflows/error-handling.mdx +1 -0
  36. package/.docs/raw/workflows/overview.mdx +56 -44
  37. package/.docs/raw/workflows/snapshots.mdx +1 -0
  38. package/.docs/raw/workflows/suspend-and-resume.mdx +2 -0
  39. package/.docs/raw/workflows/time-travel.mdx +313 -0
  40. package/.docs/raw/workflows/workflow-state.mdx +191 -0
  41. package/CHANGELOG.md +7 -0
  42. package/package.json +4 -4
@@ -124,6 +124,12 @@ const step1 = createStep({
124
124
  type: "(suspendPayload: any, suspendOptions?: { resumeLabel?: string }) => Promise<void>",
125
125
  description: "Function to pause workflow execution",
126
126
  },
127
+ {
128
+ name: "state",
129
+ type: "z.infer<TState>",
130
+ description:
131
+ "The current workflow state. Contains shared values that persist across all steps and suspend/resume cycles. The structure is defined by the step's stateSchema.",
132
+ },
127
133
  {
128
134
  name: "setState",
129
135
  type: "(state: z.infer<TState>) => void",
@@ -154,5 +160,6 @@ const step1 = createStep({
154
160
 
155
161
  ## Related
156
162
 
163
+ - [Workflow state](/docs/workflows/workflow-state)
157
164
  - [Control flow](/docs/workflows/control-flow)
158
165
  - [Using agents and tools](/docs/workflows/agents-and-tools)
@@ -88,6 +88,24 @@ export const workflow = createWorkflow({
88
88
  ]}
89
89
  />
90
90
 
91
+ ## Running with initial state
92
+
93
+ When starting a workflow run, you can pass `initialState` to set the starting values for the workflow's state:
94
+
95
+ ```typescript showLineNumbers copy
96
+ const run = await workflow.createRunAsync();
97
+
98
+ const result = await run.start({
99
+ inputData: { value: "hello" },
100
+ initialState: {
101
+ counter: 0,
102
+ items: [],
103
+ },
104
+ });
105
+ ```
106
+
107
+ The `initialState` object should match the structure defined in the workflow's `stateSchema`. See [Workflow State](/docs/workflows/workflow-state) for more details.
108
+
91
109
  ## Workflow status
92
110
 
93
111
  A workflow's `status` indicates its current execution state. The possible values are:
@@ -118,4 +136,5 @@ A workflow's `status` indicates its current execution state. The possible values
118
136
  ## Related
119
137
 
120
138
  - [Step Class](./step)
139
+ - [Workflow State](/docs/workflows/workflow-state)
121
140
  - [Control flow](/docs/workflows/control-flow)
@@ -36,7 +36,7 @@ export const mastra = new Mastra({
36
36
  // ...
37
37
  server: {
38
38
  port: 3000, // Defaults to 4111
39
- timeout: 10000, // Defaults to 30000 (30s)
39
+ timeout: 10000, // Defaults to 3 * 60 * 1000 (3 minutes)
40
40
  },
41
41
  });
42
42
  ```
@@ -208,4 +208,5 @@ for await (const chunk of stream.stream) {
208
208
 
209
209
  - [Control Flow](/docs/workflows/control-flow)
210
210
  - [Suspend & Resume](/docs/workflows/suspend-and-resume)
211
+ - [Time Travel](/docs/workflows/time-travel)
211
212
  - [Human-in-the-loop](/docs/workflows/human-in-the-loop)
@@ -90,60 +90,28 @@ Workflows can be composed using a number of different methods. The method you ch
90
90
 
91
91
  ## Workflow state
92
92
 
93
- Workflow state lets you share values across steps without passing them through every steps inputSchema and outputSchema. All state values are defined in the workflow’s stateSchema, but each step only declares the values it needs. To set initial values, use initialState when running the workflow.
93
+ Workflow state lets you share values across steps without passing them through every step's inputSchema and outputSchema. Use state for tracking progress, accumulating results, or sharing configuration across the entire workflow.
94
94
 
95
95
  ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
96
96
  const step1 = createStep({
97
- // ...
98
- stateSchema: z.object({
99
- processedItems: z.array(z.string()),
100
- }),
97
+ id: "step-1",
98
+ inputSchema: z.object({ message: z.string() }),
99
+ outputSchema: z.object({ formatted: z.string() }),
100
+ stateSchema: z.object({ counter: z.number() }),
101
101
  execute: async ({ inputData, state, setState }) => {
102
- const { message } = inputData;
103
- const { processedItems } = state;
104
-
105
- setState({
106
- ...state,
107
- processedItems: [...processedItems, "item-1", "item-2"],
108
- });
109
-
110
- return {
111
- formatted: message.toUpperCase(),
112
- };
113
- },
114
- });
102
+ // Read from state
103
+ console.log(state.counter);
115
104
 
116
- const step2 = createStep({
117
- // ...
118
- stateSchema: z.object({
119
- metadata: z.object({
120
- processedBy: z.string(),
121
- }),
122
- }),
123
- execute: async ({ inputData, state }) => {
124
- const { formatted } = inputData;
125
- const { metadata } = state;
105
+ // Update state for subsequent steps
106
+ setState({ ...state, counter: state.counter + 1 });
126
107
 
127
- return {
128
- emphasized: `${formatted}!! ${metadata.processedBy}`,
129
- };
108
+ return { formatted: inputData.message.toUpperCase() };
130
109
  },
131
110
  });
132
-
133
- export const testWorkflow = createWorkflow({
134
- // ...
135
- stateSchema: z.object({
136
- processedItems: z.array(z.string()),
137
- metadata: z.object({
138
- processedBy: z.string(),
139
- }),
140
- }),
141
- })
142
- .then(step1)
143
- .then(step2)
144
- .commit();
145
111
  ```
146
112
 
113
+ > See [Workflow State](/docs/workflows/workflow-state) for complete documentation on state schemas, initial state, persistence across suspend/resume, and nested workflows.
114
+
147
115
  ## Workflows as steps
148
116
 
149
117
  Use a workflow as a step to reuse its logic within a larger composition. Input and output follow the same schema rules described in [Core principles](/docs/workflows/control-flow).
@@ -302,6 +270,49 @@ The workflow output includes the full execution lifecycle, showing the input and
302
270
  }
303
271
  ```
304
272
 
273
+ ## Restarting active workflow runs
274
+
275
+ When a workflow run loses connection to the server, it can be restarted from the last active step. This is useful for long-running workflows that might still be running when the server loses connection. Restarting a workflow run will resume execution from the last active step, and the workflow will continue from there.
276
+
277
+ ### Restarting all active workflow runs of a workflow with `restartAllActiveWorkflowRuns()`
278
+
279
+ Use `restartAllActiveWorkflowRuns()` to restart all active workflow runs of a workflow. This helps restart all active workflow runs of a workflow, without having to manually loop through each run and restart.
280
+
281
+ ```typescript showLineNumbers copy
282
+ workflow.restartAllActiveWorkflowRuns();
283
+ ```
284
+
285
+ ### Restarting an active workflow run with `restart()`
286
+
287
+ Use `restart()` to restart an active workflow run from the last active step. This will resume execution from the last active step, and the workflow will continue from there.
288
+
289
+ ```typescript showLineNumbers copy
290
+ const run = await workflow.createRun();
291
+
292
+ const result = await run.start({ inputData: { value: "initial data" } });
293
+
294
+ //.. server connection lost,
295
+
296
+ const restartedResult = await run.restart();
297
+ ```
298
+
299
+ ### Identifying active workflow runs
300
+
301
+ When a workflow run is active, it will have a `status` of `running` or `waiting`. You can check the workflow's `status` to confirm it's active, and use `active` to identify the active workflow run.
302
+
303
+ ```typescript showLineNumbers copy
304
+ const activeRuns = await workflow.getActiveWorkflowRuns();
305
+ if (activeRuns.runs.length > 0) {
306
+ console.log(activeRuns.runs);
307
+ }
308
+ ```
309
+
310
+ :::Note
311
+
312
+ When running the local mastra server, all active workflow runs will be restarted automatically when the server starts.
313
+
314
+ :::
315
+
305
316
  ## Using `RuntimeContext`
306
317
 
307
318
  Use [RuntimeContext](/docs/server-db/runtime-context) to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
@@ -335,6 +346,7 @@ Use [Studio](/docs/getting-started/studio) to easily run workflows with differen
335
346
 
336
347
  For a closer look at workflows, see our [Workflow Guide](/guides/guide/ai-recruiter), which walks through the core concepts with a practical example.
337
348
 
349
+ - [Workflow State](/docs/workflows/workflow-state)
338
350
  - [Control Flow](/docs/workflows/control-flow)
339
351
  - [Suspend & Resume](/docs/workflows/suspend-and-resume)
340
352
  - [Error Handling](/docs/workflows/error-handling)
@@ -265,4 +265,5 @@ if (result.status === "suspended") {
265
265
 
266
266
  - [Control Flow](/docs/workflows/control-flow)
267
267
  - [Suspend & Resume](/docs/workflows/suspend-and-resume)
268
+ - [Time Travel](/docs/workflows/time-travel)
268
269
  - [Human-in-the-loop](/docs/workflows/human-in-the-loop)
@@ -140,3 +140,5 @@ Sleep and event methods can be used to pause execution at the workflow level, wh
140
140
 
141
141
  - [Control Flow](/docs/workflows/control-flow)
142
142
  - [Human-in-the-loop](/docs/workflows/human-in-the-loop)
143
+ - [Snapshots](/docs/workflows/snapshots)
144
+ - [Time Travel](/docs/workflows/time-travel)
@@ -0,0 +1,313 @@
1
+ ---
2
+ title: "Time Travel | Workflows"
3
+ description: "Re-execute workflow steps from a specific point using time travel debugging in Mastra"
4
+ ---
5
+
6
+ # Time Travel
7
+
8
+ Time travel allows you to re-execute a workflow starting from any specific step, using either stored snapshot data or custom context you provide. This is useful for debugging failed workflows, testing individual steps with different inputs, or recovering from errors without re-running the entire workflow.
9
+ You can also use time travel to execute a workflow that has not been run yet, starting from any specific step.
10
+
11
+ ## How time travel works
12
+
13
+ When you call `timeTravel()` on a workflow run:
14
+
15
+ 1. The workflow loads the existing snapshot from storage (if available)
16
+ 2. Step results before the target step are reconstructed from the snapshot or provided context
17
+ 3. Execution begins from the specified step with the provided or reconstructed input data
18
+ 4. The workflow continues to completion from that point forward
19
+
20
+ Time travel requires storage to be configured since it relies on persisted workflow snapshots.
21
+
22
+ ## Basic usage
23
+
24
+ Use `run.timeTravel()` to re-execute a workflow from a specific step:
25
+
26
+ ```typescript showLineNumbers copy
27
+ import { mastra } from "./mastra";
28
+
29
+ const workflow = mastra.getWorkflow("myWorkflow");
30
+ const run = await workflow.createRunAsync();
31
+
32
+ const result = await run.timeTravel({
33
+ step: "step2",
34
+ inputData: { previousStepResult: "custom value" },
35
+ });
36
+ ```
37
+
38
+ ## Specifying the target step
39
+
40
+ You can specify the target step using either a step reference or a step ID:
41
+
42
+ ### Using step reference
43
+
44
+ ```typescript showLineNumbers copy
45
+ const result = await run.timeTravel({
46
+ step: step2,
47
+ inputData: { value: 10 },
48
+ });
49
+ ```
50
+
51
+ ### Using step ID
52
+
53
+ ```typescript showLineNumbers copy
54
+ const result = await run.timeTravel({
55
+ step: "step2",
56
+ inputData: { value: 10 },
57
+ });
58
+ ```
59
+
60
+ ### Nested workflow steps
61
+
62
+ For steps inside nested workflows, use dot notation, an array of step IDS or an array of step references:
63
+
64
+ ```typescript showLineNumbers copy
65
+ // Using dot notation
66
+ const result = await run.timeTravel({
67
+ step: "nestedWorkflow.step3",
68
+ inputData: { value: 10 },
69
+ });
70
+
71
+ // Using array of step IDs
72
+ const result = await run.timeTravel({
73
+ step: ["nestedWorkflow", "step3"],
74
+ inputData: { value: 10 },
75
+ });
76
+
77
+ // Using array of step references
78
+ const result = await run.timeTravel({
79
+ step: [nestedWorkflow, step3],
80
+ inputData: { value: 10 },
81
+ });
82
+ ```
83
+
84
+ ## Providing execution context
85
+
86
+ You can provide context to specify the state of previous steps when time traveling:
87
+
88
+ ```typescript {3-13} showLineNumbers copy
89
+ const result = await run.timeTravel({
90
+ step: "step2",
91
+ context: {
92
+ step1: {
93
+ status: "success",
94
+ payload: { value: 0 },
95
+ output: { step1Result: 2 },
96
+ startedAt: Date.now(),
97
+ endedAt: Date.now(),
98
+ },
99
+ },
100
+ });
101
+ ```
102
+
103
+ The context object contains step results keyed by step ID. Each step result includes:
104
+
105
+ - `status`: The step's execution status (`success`, `failed`, `suspended`)
106
+ - `payload`: The input data passed to the step
107
+ - `output`: The step's output data (for successful steps)
108
+ - `startedAt`: Timestamp when the step started
109
+ - `endedAt`: Timestamp when the step ended (for completed steps)
110
+ - `suspendPayload`: Data passed to `suspend()` (for suspended steps)
111
+ - `resumePayload`: Data passed to `resume()` (for resumed steps)
112
+
113
+ ## Re-running failed workflows
114
+
115
+ Time travel is particularly useful for debugging and recovering from failed workflow executions:
116
+
117
+ ```typescript showLineNumbers copy
118
+ const workflow = mastra.getWorkflow("myWorkflow");
119
+ const run = await workflow.createRunAsync();
120
+
121
+ // Initial run fails at step2
122
+ const failedResult = await run.start({
123
+ inputData: { value: 1 },
124
+ });
125
+
126
+ if (failedResult.status === "failed") {
127
+ // Re-run from step2 with corrected input
128
+ const recoveredResult = await run.timeTravel({
129
+ step: "step2",
130
+ inputData: { step1Result: 5 }, // Provide corrected input
131
+ });
132
+ }
133
+ ```
134
+
135
+ ## Time travel with suspended workflows
136
+
137
+ You can time travel to resume a suspended workflow from an earlier step:
138
+
139
+ ```typescript showLineNumbers copy
140
+ const run = await workflow.createRunAsync();
141
+
142
+ // Start workflow - suspends at promptAgent step
143
+ const initialResult = await run.start({
144
+ inputData: { input: "test" },
145
+ });
146
+
147
+ if (initialResult.status === "suspended") {
148
+ // Time travel back to an earlier step with resume data
149
+ const result = await run.timeTravel({
150
+ step: "getUserInput",
151
+ resumeData: {
152
+ userInput: "corrected input",
153
+ },
154
+ });
155
+ }
156
+ ```
157
+
158
+ ## Streaming time travel results
159
+
160
+ Use `timeTravelStream()` to receive streaming events during time travel execution:
161
+
162
+ ```typescript showLineNumbers copy
163
+ const run = await workflow.createRunAsync();
164
+
165
+ const output = run.timeTravelStream({
166
+ step: "step2",
167
+ inputData: { value: 10 },
168
+ });
169
+
170
+ // Access the stream
171
+ for await (const event of output.fullStream) {
172
+ console.log(event.type, event.payload);
173
+ }
174
+
175
+ // Get final result
176
+ const result = await output.result;
177
+ ```
178
+
179
+ ## Time travel with initial state
180
+
181
+ You can provide initial state when time traveling to set workflow-level state:
182
+
183
+ ```typescript showLineNumbers copy
184
+ const result = await run.timeTravel({
185
+ step: "step2",
186
+ inputData: { value: 10 },
187
+ initialState: {
188
+ counter: 5,
189
+ metadata: { source: "time-travel" },
190
+ },
191
+ });
192
+ ```
193
+
194
+ ## Error handling
195
+
196
+ Time travel throws errors in specific situations:
197
+
198
+ ### Running workflow
199
+
200
+ You cannot time travel to a workflow that is currently running:
201
+
202
+ ```typescript showLineNumbers copy
203
+ try {
204
+ await run.timeTravel({ step: "step2" });
205
+ } catch (error) {
206
+ // "This workflow run is still running, cannot time travel"
207
+ }
208
+ ```
209
+
210
+ ### Invalid step ID
211
+
212
+ Time travel throws if the target step doesn't exist in the workflow:
213
+
214
+ ```typescript showLineNumbers copy
215
+ try {
216
+ await run.timeTravel({ step: "nonExistentStep" });
217
+ } catch (error) {
218
+ // "Time travel target step not found in execution graph: 'nonExistentStep'. Verify the step id/path."
219
+ }
220
+ ```
221
+
222
+ ### Invalid input data
223
+
224
+ When `validateInputs` is enabled, time travel validates the input data against the step's schema:
225
+
226
+ ```typescript showLineNumbers copy
227
+ try {
228
+ await run.timeTravel({
229
+ step: "step2",
230
+ inputData: { invalidField: "value" },
231
+ });
232
+ } catch (error) {
233
+ // "Invalid inputData: \n- step1Result: Required"
234
+ }
235
+ ```
236
+
237
+ ## Nested workflows context
238
+
239
+ When time traveling into a nested workflow, you can provide context for both the parent and nested workflow steps:
240
+
241
+ ```typescript showLineNumbers copy
242
+ const result = await run.timeTravel({
243
+ step: "nestedWorkflow.step3",
244
+ context: {
245
+ step1: {
246
+ status: "success",
247
+ payload: { value: 0 },
248
+ output: { step1Result: 2 },
249
+ startedAt: Date.now(),
250
+ endedAt: Date.now(),
251
+ },
252
+ nestedWorkflow: {
253
+ status: "running",
254
+ payload: { step1Result: 2 },
255
+ startedAt: Date.now(),
256
+ },
257
+ },
258
+ nestedStepsContext: {
259
+ nestedWorkflow: {
260
+ step2: {
261
+ status: "success",
262
+ payload: { step1Result: 2 },
263
+ output: { step2Result: 3 },
264
+ startedAt: Date.now(),
265
+ endedAt: Date.now(),
266
+ },
267
+ },
268
+ },
269
+ });
270
+ ```
271
+
272
+ ## Use cases
273
+
274
+ ### Debugging failed steps
275
+
276
+ Re-run a failed step with the same or modified input to diagnose issues:
277
+
278
+ ```typescript showLineNumbers copy
279
+ const result = await run.timeTravel({
280
+ step: failedStepId,
281
+ context: originalContext, // Use context from the failed run
282
+ });
283
+ ```
284
+
285
+ ### Testing step logic on new workflow run
286
+
287
+ Test individual steps with specific inputs on a new workflow run, useful for testing a step logic without starting workflow execution from the beginning.
288
+
289
+ ```typescript showLineNumbers copy
290
+ const result = await run.timeTravel({
291
+ step: "processData",
292
+ inputData: { testData: "specific test case" },
293
+ });
294
+ ```
295
+
296
+ ### Recovering from transient failures
297
+
298
+ Re-run steps that failed due to temporary issues (network errors, rate limits):
299
+
300
+ ```typescript showLineNumbers copy
301
+ // After fixing the external service issue
302
+ const result = await run.timeTravel({
303
+ step: "callExternalApi",
304
+ inputData: savedInputData,
305
+ });
306
+ ```
307
+
308
+ ## Related
309
+
310
+ - [Snapshots](/docs/workflows/snapshots)
311
+ - [Suspend & Resume](/docs/workflows/suspend-and-resume)
312
+ - [Error Handling](/docs/workflows/error-handling)
313
+ - [Control Flow](/docs/workflows/control-flow)