@mastra/mcp-docs-server 0.13.46-alpha.0 → 0.13.46-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.
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +92 -92
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +52 -52
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Freact.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +12 -12
- package/.docs/organized/changelogs/create-mastra.md +11 -11
- package/.docs/organized/changelogs/mastra.md +18 -18
- package/.docs/raw/agents/overview.mdx +17 -2
- package/.docs/raw/mcp/overview.mdx +6 -0
- package/.docs/raw/observability/otel-tracing.mdx +17 -2
- package/.docs/raw/observability/overview.mdx +12 -2
- package/.docs/raw/rag/vector-databases.mdx +58 -0
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
- package/.docs/raw/reference/tools/mcp-server.mdx +72 -1
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +98 -0
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
- package/.docs/raw/reference/workflows/run.mdx +21 -0
- package/.docs/raw/reference/workflows/step.mdx +7 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/mastra-server.mdx +1 -1
- package/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +2 -0
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +15 -0
- package/package.json +4 -4
|
@@ -387,7 +387,7 @@ const httpServer = http.createServer(async (req, res) => {
|
|
|
387
387
|
req,
|
|
388
388
|
res,
|
|
389
389
|
options: {
|
|
390
|
-
sessionIdGenerator:
|
|
390
|
+
sessionIdGenerator: () => randomUUID(),
|
|
391
391
|
},
|
|
392
392
|
});
|
|
393
393
|
});
|
|
@@ -397,6 +397,70 @@ httpServer.listen(PORT, () => {
|
|
|
397
397
|
});
|
|
398
398
|
```
|
|
399
399
|
|
|
400
|
+
For **serverless environments** (Supabase Edge Functions, Cloudflare Workers, Vercel Edge, etc.), use `serverless: true` to enable stateless operation:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
// Supabase Edge Function example
|
|
404
|
+
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
|
405
|
+
import { MCPServer } from "@mastra/mcp";
|
|
406
|
+
// Note: You will need to convert req/res format from Deno to Node
|
|
407
|
+
import { toReqRes, toFetchResponse } from "fetch-to-node";
|
|
408
|
+
|
|
409
|
+
const server = new MCPServer({
|
|
410
|
+
name: "my-serverless-mcp",
|
|
411
|
+
version: "1.0.0",
|
|
412
|
+
tools: { /* your tools */ },
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
serve(async (req) => {
|
|
416
|
+
const url = new URL(req.url);
|
|
417
|
+
|
|
418
|
+
if (url.pathname === "/mcp") {
|
|
419
|
+
// Convert Deno Request to Node.js-compatible format
|
|
420
|
+
const { req: nodeReq, res: nodeRes } = toReqRes(req);
|
|
421
|
+
|
|
422
|
+
await server.startHTTP({
|
|
423
|
+
url,
|
|
424
|
+
httpPath: "/mcp",
|
|
425
|
+
req: nodeReq,
|
|
426
|
+
res: nodeRes,
|
|
427
|
+
options: {
|
|
428
|
+
serverless: true, // ← Enable stateless mode for serverless
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
return toFetchResponse(nodeRes);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return new Response("Not found", { status: 404 });
|
|
436
|
+
});
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
> **When to use `serverless: true`**
|
|
440
|
+
>
|
|
441
|
+
> Use `serverless: true` when deploying to environments where each request runs in a fresh, stateless execution context:
|
|
442
|
+
> - Supabase Edge Functions
|
|
443
|
+
> - Cloudflare Workers
|
|
444
|
+
> - Vercel Edge Functions
|
|
445
|
+
> - Netlify Edge Functions
|
|
446
|
+
> - AWS Lambda
|
|
447
|
+
> - Deno Deploy
|
|
448
|
+
>
|
|
449
|
+
> Use the default session-based mode (without `serverless: true`) for:
|
|
450
|
+
> - Long-lived Node.js servers
|
|
451
|
+
> - Docker containers
|
|
452
|
+
> - Traditional hosting (VPS, dedicated servers)
|
|
453
|
+
>
|
|
454
|
+
> The serverless mode disables session management and creates fresh server instances per request, which is necessary for stateless environments where memory doesn't persist between invocations.
|
|
455
|
+
>
|
|
456
|
+
> **Note:** The following MCP features require session state or persistent connections and will **not work** in serverless mode:
|
|
457
|
+
> - **Elicitation** - Interactive user input requests during tool execution require session management to route responses back to the correct client
|
|
458
|
+
> - **Resource subscriptions** - `resources/subscribe` and `resources/unsubscribe` need persistent connections to maintain subscription state
|
|
459
|
+
> - **Resource update notifications** - `resources.notifyUpdated()` requires active subscriptions and persistent connections to notify clients
|
|
460
|
+
> - **Prompt list change notifications** - `prompts.notifyListChanged()` requires persistent connections to push updates to clients
|
|
461
|
+
>
|
|
462
|
+
> These features work normally in long-lived server environments (Node.js servers, Docker containers, etc.).
|
|
463
|
+
|
|
400
464
|
Here are the details for the values needed by the `startHTTP` method:
|
|
401
465
|
|
|
402
466
|
<PropertiesTable
|
|
@@ -437,6 +501,13 @@ The `StreamableHTTPServerTransportOptions` object allows you to customize the be
|
|
|
437
501
|
|
|
438
502
|
<PropertiesTable
|
|
439
503
|
content={[
|
|
504
|
+
{
|
|
505
|
+
name: "serverless",
|
|
506
|
+
type: "boolean",
|
|
507
|
+
description:
|
|
508
|
+
"If `true`, runs in stateless mode without session management. Each request is handled independently with a fresh server instance. Essential for serverless environments (Cloudflare Workers, Supabase Edge Functions, Vercel Edge, etc.) where sessions cannot persist between invocations. Defaults to `false`.",
|
|
509
|
+
optional: true,
|
|
510
|
+
},
|
|
440
511
|
{
|
|
441
512
|
name: "sessionIdGenerator",
|
|
442
513
|
type: "(() => string) | undefined",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Run.restart() | Workflows"
|
|
3
|
+
description: Documentation for the `Run.restart()` method in workflows, which restarts an active workflow run that lost connection to the server.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Run.restart()
|
|
7
|
+
|
|
8
|
+
The `.restart()` method restarts an active workflow run that lost connection to the server, allowing you to continue execution from the moment it lost connection (the last active step).
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const run = await workflow.createRun();
|
|
14
|
+
|
|
15
|
+
const result = await run.start({ inputData: { value: "initial data" } });
|
|
16
|
+
|
|
17
|
+
//.. server connection lost,
|
|
18
|
+
|
|
19
|
+
const restartedResult = await run.restart();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Parameters
|
|
23
|
+
|
|
24
|
+
<PropertiesTable
|
|
25
|
+
content={[
|
|
26
|
+
{
|
|
27
|
+
name: "requestContext",
|
|
28
|
+
type: "RequestContext",
|
|
29
|
+
description: "Request Context data to use when resuming",
|
|
30
|
+
isOptional: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "tracingContext",
|
|
34
|
+
type: "TracingContext",
|
|
35
|
+
isOptional: true,
|
|
36
|
+
description:
|
|
37
|
+
"Tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.",
|
|
38
|
+
properties: [
|
|
39
|
+
{
|
|
40
|
+
parameters: [
|
|
41
|
+
{
|
|
42
|
+
name: "currentSpan",
|
|
43
|
+
type: "Span",
|
|
44
|
+
isOptional: true,
|
|
45
|
+
description:
|
|
46
|
+
"Current span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution.",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "tracingOptions",
|
|
54
|
+
type: "TracingOptions",
|
|
55
|
+
isOptional: true,
|
|
56
|
+
description: "Options for Tracing configuration.",
|
|
57
|
+
properties: [
|
|
58
|
+
{
|
|
59
|
+
parameters: [
|
|
60
|
+
{
|
|
61
|
+
name: "metadata",
|
|
62
|
+
type: "Record<string, any>",
|
|
63
|
+
isOptional: true,
|
|
64
|
+
description:
|
|
65
|
+
"Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags.",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
]}
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
## Returns
|
|
75
|
+
|
|
76
|
+
<PropertiesTable
|
|
77
|
+
content={[
|
|
78
|
+
{
|
|
79
|
+
name: "result",
|
|
80
|
+
type: "Promise<WorkflowResult<TState, TOutput, TSteps>>",
|
|
81
|
+
description:
|
|
82
|
+
"A promise that resolves to the workflow execution result containing step outputs and status",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "traceId",
|
|
86
|
+
type: "string",
|
|
87
|
+
isOptional: true,
|
|
88
|
+
description:
|
|
89
|
+
"The trace ID associated with this execution when Tracing is enabled. Use this to correlate logs and debug execution flow.",
|
|
90
|
+
},
|
|
91
|
+
]}
|
|
92
|
+
/>
|
|
93
|
+
|
|
94
|
+
## Related
|
|
95
|
+
|
|
96
|
+
- [Workflows overview](/docs/workflows/overview#running-workflows)
|
|
97
|
+
- [Restart workflows](/docs/workflows/overview#restarting-active-workflow-runs)
|
|
98
|
+
- [Workflow.createRun()](../workflow-methods/create-run)
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Run.timeTravel() | Workflows"
|
|
3
|
+
description: Documentation for the `Run.timeTravel()` method in workflows, which re-executes a workflow from a specific step.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Run.timeTravel()
|
|
7
|
+
|
|
8
|
+
The `.timeTravel()` method re-executes 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
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const run = await workflow.createRunAsync();
|
|
14
|
+
|
|
15
|
+
const result = await run.timeTravel({
|
|
16
|
+
step: "step2",
|
|
17
|
+
inputData: { value: 10 },
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
<PropertiesTable
|
|
24
|
+
content={[
|
|
25
|
+
{
|
|
26
|
+
name: "step",
|
|
27
|
+
type: "Step<string, any, TInputSchema, any, any, any, TEngineType> | [...Step<string, any, any, any, any, any, TEngineType>[], Step<string, any, TInputSchema, any, any, any, TEngineType>] | string | string[]",
|
|
28
|
+
description:
|
|
29
|
+
"The target step to start execution from. It can be a Step instance, array of Steps (for nested workflows), step ID string, or array of step ID strings. Use dot notation or arrays for nested workflow steps (e.g., 'nestedWorkflow.step3' or ['nestedWorkflow', 'step3'])",
|
|
30
|
+
isOptional: false,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "inputData",
|
|
34
|
+
type: "z.infer<TInputSchema>",
|
|
35
|
+
description: "Input data for the target step. Must match the step's input schema. If not provided, uses data from the workflow snapshot",
|
|
36
|
+
isOptional: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "resumeData",
|
|
40
|
+
type: "any",
|
|
41
|
+
description: "Resume data to provide if the workflow was previously suspended",
|
|
42
|
+
isOptional: true,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "initialState",
|
|
46
|
+
type: "z.infer<TState>",
|
|
47
|
+
description: "Initial state to set for the workflow run. Used to set workflow-level state before execution",
|
|
48
|
+
isOptional: true,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "context",
|
|
52
|
+
type: "TimeTravelContext<any, any, any, any>",
|
|
53
|
+
description:
|
|
54
|
+
"Execution context containing step results for steps before the target step. Each key is a step ID with a StepResult object containing status, payload, output, startedAt, endedAt, suspendPayload, and resumePayload",
|
|
55
|
+
isOptional: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "nestedStepsContext",
|
|
59
|
+
type: "Record<string, TimeTravelContext<any, any, any, any>>",
|
|
60
|
+
description:
|
|
61
|
+
"Context for nested workflow steps. Keyed by nested workflow ID, each containing step results for that nested workflow",
|
|
62
|
+
isOptional: true,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "requestContext",
|
|
66
|
+
type: "RequestContext",
|
|
67
|
+
description: "Request Context data to use during time travel execution",
|
|
68
|
+
isOptional: true,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "writableStream",
|
|
72
|
+
type: "WritableStream<ChunkType>",
|
|
73
|
+
description: "Optional writable stream for streaming workflow output during time travel",
|
|
74
|
+
isOptional: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "tracingContext",
|
|
78
|
+
type: "TracingContext",
|
|
79
|
+
isOptional: true,
|
|
80
|
+
description:
|
|
81
|
+
"Tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.",
|
|
82
|
+
properties: [
|
|
83
|
+
{
|
|
84
|
+
parameters: [
|
|
85
|
+
{
|
|
86
|
+
name: "currentSpan",
|
|
87
|
+
type: "Span",
|
|
88
|
+
isOptional: true,
|
|
89
|
+
description:
|
|
90
|
+
"Current span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution.",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "tracingOptions",
|
|
98
|
+
type: "TracingOptions",
|
|
99
|
+
isOptional: true,
|
|
100
|
+
description: "Options for Tracing configuration.",
|
|
101
|
+
properties: [
|
|
102
|
+
{
|
|
103
|
+
parameters: [
|
|
104
|
+
{
|
|
105
|
+
name: "metadata",
|
|
106
|
+
type: "Record<string, any>",
|
|
107
|
+
isOptional: true,
|
|
108
|
+
description:
|
|
109
|
+
"Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags.",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
parameters: [
|
|
115
|
+
{
|
|
116
|
+
name: "requestContextKeys",
|
|
117
|
+
type: "string[]",
|
|
118
|
+
isOptional: true,
|
|
119
|
+
description:
|
|
120
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
parameters: [
|
|
126
|
+
{
|
|
127
|
+
name: "traceId",
|
|
128
|
+
type: "string",
|
|
129
|
+
isOptional: true,
|
|
130
|
+
description:
|
|
131
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
parameters: [
|
|
137
|
+
{
|
|
138
|
+
name: "parentSpanId",
|
|
139
|
+
type: "string",
|
|
140
|
+
isOptional: true,
|
|
141
|
+
description:
|
|
142
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
parameters: [
|
|
148
|
+
{
|
|
149
|
+
name: "tags",
|
|
150
|
+
type: "string[]",
|
|
151
|
+
isOptional: true,
|
|
152
|
+
description:
|
|
153
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "outputOptions",
|
|
161
|
+
type: "OutputOptions",
|
|
162
|
+
isOptional: true,
|
|
163
|
+
description: "Options for output configuration.",
|
|
164
|
+
properties: [
|
|
165
|
+
{
|
|
166
|
+
parameters: [
|
|
167
|
+
{
|
|
168
|
+
name: "includeState",
|
|
169
|
+
type: "boolean",
|
|
170
|
+
isOptional: true,
|
|
171
|
+
description:
|
|
172
|
+
"Whether to include the workflow run state in the result.",
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
parameters: [
|
|
178
|
+
{
|
|
179
|
+
name: "includeResumeLabels",
|
|
180
|
+
type: "boolean",
|
|
181
|
+
isOptional: true,
|
|
182
|
+
description:
|
|
183
|
+
"Whether to include resume labels in the result.",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
]}
|
|
190
|
+
/>
|
|
191
|
+
|
|
192
|
+
## Returns
|
|
193
|
+
|
|
194
|
+
<PropertiesTable
|
|
195
|
+
content={[
|
|
196
|
+
{
|
|
197
|
+
name: "result",
|
|
198
|
+
type: "Promise<WorkflowResult<TState, TInput, TOutput, TSteps>>",
|
|
199
|
+
description:
|
|
200
|
+
"A promise that resolves to the workflow execution result containing step outputs and status",
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "traceId",
|
|
204
|
+
type: "string",
|
|
205
|
+
isOptional: true,
|
|
206
|
+
description:
|
|
207
|
+
"The trace ID associated with this execution when Tracing is enabled. Use this to correlate logs and debug execution flow.",
|
|
208
|
+
},
|
|
209
|
+
]}
|
|
210
|
+
/>
|
|
211
|
+
|
|
212
|
+
## Extended usage examples
|
|
213
|
+
|
|
214
|
+
### Time travel with custom context
|
|
215
|
+
|
|
216
|
+
```typescript showLineNumbers copy
|
|
217
|
+
const result = await run.timeTravel({
|
|
218
|
+
step: "step2",
|
|
219
|
+
context: {
|
|
220
|
+
step1: {
|
|
221
|
+
status: "success",
|
|
222
|
+
payload: { value: 0 },
|
|
223
|
+
output: { step1Result: 2 },
|
|
224
|
+
startedAt: Date.now(),
|
|
225
|
+
endedAt: Date.now(),
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Time travel to nested workflow step
|
|
232
|
+
|
|
233
|
+
```typescript showLineNumbers copy
|
|
234
|
+
// Using dot notation
|
|
235
|
+
const result = await run.timeTravel({
|
|
236
|
+
step: "nestedWorkflow.step3",
|
|
237
|
+
inputData: { value: 10 },
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Using array of step IDs
|
|
241
|
+
const result = await run.timeTravel({
|
|
242
|
+
step: ["nestedWorkflow", "step3"],
|
|
243
|
+
inputData: { value: 10 },
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Time travel with initial state
|
|
248
|
+
|
|
249
|
+
```typescript showLineNumbers copy
|
|
250
|
+
const result = await run.timeTravel({
|
|
251
|
+
step: "step2",
|
|
252
|
+
inputData: { value: 10 },
|
|
253
|
+
initialState: {
|
|
254
|
+
counter: 5,
|
|
255
|
+
metadata: { source: "time-travel" },
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Time travel with nested workflows context
|
|
261
|
+
|
|
262
|
+
```typescript showLineNumbers copy
|
|
263
|
+
const result = await run.timeTravel({
|
|
264
|
+
step: "nestedWorkflow.step3",
|
|
265
|
+
context: {
|
|
266
|
+
step1: {
|
|
267
|
+
status: "success",
|
|
268
|
+
payload: { value: 0 },
|
|
269
|
+
output: { step1Result: 2 },
|
|
270
|
+
startedAt: Date.now(),
|
|
271
|
+
endedAt: Date.now(),
|
|
272
|
+
},
|
|
273
|
+
nestedWorkflow: {
|
|
274
|
+
status: "running",
|
|
275
|
+
payload: { step1Result: 2 },
|
|
276
|
+
startedAt: Date.now(),
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
nestedStepsContext: {
|
|
280
|
+
nestedWorkflow: {
|
|
281
|
+
step2: {
|
|
282
|
+
status: "success",
|
|
283
|
+
payload: { step1Result: 2 },
|
|
284
|
+
output: { step2Result: 3 },
|
|
285
|
+
startedAt: Date.now(),
|
|
286
|
+
endedAt: Date.now(),
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Notes
|
|
294
|
+
|
|
295
|
+
- Time travel requires storage to be configured since it relies on persisted workflow snapshots
|
|
296
|
+
- When re-executing a workflow, the workflow loads the existing snapshot from storage (if available)
|
|
297
|
+
- Step results before the target step are reconstructed from the snapshot or provided context
|
|
298
|
+
- Execution begins from the specified step with the provided or reconstructed input data
|
|
299
|
+
- The workflow continues to completion from that point forward
|
|
300
|
+
- Time travel can be used on workflows that have not been run yet by providing custom context or input data for the step to start from.
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
## Related
|
|
304
|
+
|
|
305
|
+
- [Time Travel](/docs/workflows/time-travel)
|
|
306
|
+
- [Workflows overview](/docs/workflows/overview#running-workflows)
|
|
307
|
+
- [Workflow.createRun()](../workflow-methods/create-run)
|
|
308
|
+
- [Snapshots](/docs/workflows/snapshots)
|
|
309
|
+
- [Suspend & Resume](/docs/workflows/suspend-and-resume)
|
|
310
|
+
|
|
@@ -63,6 +63,24 @@ if (result.status === "suspended") {
|
|
|
63
63
|
description: "Cancels the workflow execution",
|
|
64
64
|
required: true,
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
name: "restart",
|
|
68
|
+
type: "(options?: RestartOptions) => Promise<WorkflowResult>",
|
|
69
|
+
description: "Restarts the workflow execution from last active step",
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "timeTravel",
|
|
74
|
+
type: "(options?: TimeTravelOptions) => Promise<WorkflowResult>",
|
|
75
|
+
description: "Re-executes a workflow starting from any specific step, using either stored snapshot data or custom context you provide.",
|
|
76
|
+
required: true,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "timeTravelStream",
|
|
80
|
+
type: "(options?: TimeTravelOptions) => MastraWorkflowStream",
|
|
81
|
+
description: "Time travels a workflow execution with streaming support",
|
|
82
|
+
required: true,
|
|
83
|
+
},
|
|
66
84
|
]}
|
|
67
85
|
/>
|
|
68
86
|
|
|
@@ -99,3 +117,6 @@ A workflow run's `status` indicates its current execution state. The possible va
|
|
|
99
117
|
- [Run.resume()](./run-methods/resume)
|
|
100
118
|
- [Run.watch()](./run-methods/watch)
|
|
101
119
|
- [Run.cancel()](./run-methods/cancel)
|
|
120
|
+
- [Run.restart()](./run-methods/restart)
|
|
121
|
+
- [Run.timeTravel()](./run-methods/timeTravel)
|
|
122
|
+
- [Run.timeTravelStream()](../streaming/workflows/timeTravelStream)
|
|
@@ -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)
|
|
@@ -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)
|