@mastra/mcp-docs-server 0.13.22-alpha.3 → 0.13.22-alpha.4

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 (30) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +10 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +14 -14
  3. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
  4. package/.docs/organized/changelogs/%40mastra%2Fcore.md +17 -17
  5. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +11 -11
  6. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +10 -10
  7. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +10 -10
  8. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +9 -9
  9. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +13 -13
  10. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +12 -12
  11. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +9 -9
  12. package/.docs/organized/changelogs/%40mastra%2Fserver.md +10 -10
  13. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +11 -11
  14. package/.docs/organized/changelogs/create-mastra.md +3 -3
  15. package/.docs/organized/changelogs/mastra.md +11 -11
  16. package/.docs/organized/code-examples/agent-network.md +2 -1
  17. package/.docs/organized/code-examples/quick-start.md +2 -1
  18. package/.docs/organized/code-examples/workflow-ai-recruiter.md +2 -1
  19. package/.docs/raw/course/04-workflows/08-running-workflows-programmatically.md +2 -2
  20. package/.docs/raw/reference/agents/network.mdx +258 -0
  21. package/.docs/raw/reference/storage/dynamodb.mdx +0 -4
  22. package/.docs/raw/reference/{agents → streaming}/ChunkType.mdx +5 -5
  23. package/.docs/raw/reference/{agents → streaming}/MastraModelOutput.mdx +10 -10
  24. package/.docs/raw/reference/tools/mcp-server.mdx +1 -1
  25. package/.docs/raw/server-db/snapshots.mdx +155 -114
  26. package/.docs/raw/workflows/inngest-workflow.mdx +82 -0
  27. package/CHANGELOG.md +8 -0
  28. package/package.json +4 -4
  29. /package/.docs/raw/reference/{agents → streaming}/stream.mdx +0 -0
  30. /package/.docs/raw/reference/{agents → streaming}/streamVNext.mdx +0 -0
@@ -1,6 +1,6 @@
1
1
  ---
2
- title: "Reference: Snapshots | Workflow State Persistence | Mastra Docs"
3
- description: "Technical reference on snapshots in Mastra - the serialized workflow state that enables suspend and resume functionality"
2
+ title: "Snapshots | Mastra Docs"
3
+ description: "Learn how to save and resume workflow execution state with snapshots in Mastra"
4
4
  ---
5
5
 
6
6
  # Snapshots
@@ -16,7 +16,7 @@ In Mastra, a snapshot is a serializable representation of a workflow's complete
16
16
 
17
17
  Snapshots are automatically created and managed by Mastra whenever a workflow is suspended, and are persisted to the configured storage system.
18
18
 
19
- ## The Role of Snapshots in Suspend and Resume
19
+ ## The role of snapshots in suspend and resume
20
20
 
21
21
  Snapshots are the key mechanism enabling Mastra's suspend and resume capabilities. When a workflow step calls `await suspend()`:
22
22
 
@@ -29,59 +29,51 @@ Snapshots are the key mechanism enabling Mastra's suspend and resume capabilitie
29
29
 
30
30
  This mechanism provides a powerful way to implement human-in-the-loop workflows, handle rate limiting, wait for external resources, and implement complex branching workflows that may need to pause for extended periods.
31
31
 
32
- ## Snapshot Anatomy
33
-
34
- A Mastra workflow snapshot consists of several key components:
35
-
36
- ```typescript
37
- export interface WorkflowRunState {
38
- // Core state info
39
- value: Record<string, string>; // Current state machine value
40
- context: {
41
- // Workflow context
42
- [key: string]: Record<
43
- string,
44
- | {
45
- status: "success";
46
- output: any;
47
- }
48
- | {
49
- status: "failed";
50
- error: string;
51
- }
52
- | {
53
- status: "suspended";
54
- payload?: any;
55
- }
56
- >;
57
- input: Record<string, any>; // Initial input data
58
- };
59
-
60
- activePaths: Array<{
61
- // Currently active execution paths
62
- stepPath: string[];
63
- stepId: string;
64
- status: string;
65
- }>;
66
-
67
- // Paths to suspended steps
68
- suspendedPaths: Record<string, number[]>;
69
-
70
- // Metadata
71
- runId: string; // Unique run identifier
72
- timestamp: number; // Time snapshot was created
32
+ ## Snapshot anatomy
33
+
34
+ Each snapshot includes the `runId`, input, step status (`success`, `suspended`, etc.), any suspend and resume payloads, and the final output. This ensures full context is available when resuming execution.
35
+
36
+
37
+ ```json
38
+ {
39
+ "runId": "34904c14-e79e-4a12-9804-9655d4616c50",
40
+ "status": "success",
41
+ "value": {},
42
+ "context": {
43
+ "input": { "value": 100, "user": "Michael", "requiredApprovers": ["manager", "finance"] },
44
+ "approval-step": {
45
+ "payload": { "value": 100, "user": "Michael", "requiredApprovers": ["manager", "finance"] },
46
+ "startedAt": 1758027577955,
47
+ "status": "success",
48
+ "suspendPayload": { "message": "Workflow suspended", "requestedBy": "Michael", "approvers": ["manager", "finance"] },
49
+ "suspendedAt": 1758027578065,
50
+ "resumePayload": { "confirm": true, "approver": "manager" },
51
+ "resumedAt": 1758027578517,
52
+ "output": { "value": 100, "approved": true },
53
+ "endedAt": 1758027578634
54
+ }
55
+ },
56
+ "activePaths": [],
57
+ "serializedStepGraph": [{ "type": "step", "step": { "id": "approval-step", "description": "Accepts a value, waits for confirmation" } }],
58
+ "suspendedPaths": {},
59
+ "waitingPaths": {},
60
+ "result": { "value": 100, "approved": true },
61
+ "runtimeContext": {},
62
+ "timestamp": 1758027578740
73
63
  }
74
64
  ```
75
65
 
76
- ## How Snapshots Are Saved and Retrieved
66
+ ## How snapshots are saved and retrieved
67
+
68
+ Snapshots are saved to the configured storage system. By default, they use LibSQL, but you can configure Upstash or PostgreSQL instead. Each snapshot is saved in the `workflow_snapshots` table and identified by the workflow’s `runId`.
77
69
 
78
- Mastra persists snapshots to the configured storage system. By default, snapshots are saved to a LibSQL database, but can be configured to use other storage providers like Upstash.
79
- The snapshots are stored in the `workflow_snapshots` table and identified uniquely by the `run_id` for the associated run when using libsql.
80
- Utilizing a persistence layer allows for the snapshots to be persisted across workflow runs, allowing for advanced human-in-the-loop functionality.
70
+ Read more about:
71
+ - [LibSQL Storage](../../reference/storage/libsql.mdx)
72
+ - [Upstash Storage](../../reference/storage/upstash.mdx)
73
+ - [PostgreSQL Storage](../../reference/storage/postgresql.mdx)
81
74
 
82
- Read more about [libsql storage](../../reference/storage/libsql.mdx) and [upstash storage](../../reference/storage/upstash.mdx) here.
83
75
 
84
- ### Saving Snapshots
76
+ ### Saving snapshots
85
77
 
86
78
  When a workflow is suspended, Mastra automatically persists the workflow snapshot with these steps:
87
79
 
@@ -91,7 +83,7 @@ When a workflow is suspended, Mastra automatically persists the workflow snapsho
91
83
  4. The snapshot is serialized and stored in the configured database in the `workflow_snapshots` table
92
84
  5. The storage record includes the workflow name, run ID, and the serialized snapshot
93
85
 
94
- ### Retrieving Snapshots
86
+ ### Retrieving snapshots
95
87
 
96
88
  When a workflow is resumed, Mastra retrieves the persisted snapshot with these steps:
97
89
 
@@ -101,105 +93,154 @@ When a workflow is resumed, Mastra retrieves the persisted snapshot with these s
101
93
  4. The workflow execution is recreated with the snapshot state
102
94
  5. The suspended step is resumed, and execution continues
103
95
 
104
- ## Storage Options for Snapshots
105
96
 
106
- Mastra provides multiple storage options for persisting snapshots.
97
+ ```typescript
98
+ const storage = mastra.getStorage();
99
+
100
+ const snapshot = await storage!.loadWorkflowSnapshot({
101
+ runId: "<run-id>",
102
+ workflowName: "<workflow-id>"
103
+ });
107
104
 
108
- A `storage` instance is configured on the `Mastra` class, and is used to setup a snapshot persistence layer for all workflows registered on the `Mastra` instance.
109
- This means that storage is shared across all workflows registered with the same `Mastra` instance.
105
+ console.log(snapshot);
106
+ ```
110
107
 
111
- ### LibSQL (Default)
108
+ ## Storage options for snapshots
112
109
 
113
- The default storage option is LibSQL, a SQLite-compatible database:
110
+ Snapshots are persisted using a `storage` instance configured on the `Mastra` class. This storage layer is shared across all workflows registered to that instance. Mastra supports multiple storage options for flexibility in different environments.
114
111
 
115
- ```typescript
112
+ ### LibSQL `@mastra/libsql`
113
+
114
+ This example demonstrates how to use snapshots with LibSQL.
115
+
116
+ ```typescript filename="src/mastra/index.ts" showLineNumbers copy
116
117
  import { Mastra } from "@mastra/core/mastra";
117
- import { DefaultStorage } from "@mastra/core/storage/libsql";
118
-
119
- const mastra = new Mastra({
120
- storage: new DefaultStorage({
121
- config: {
122
- url: "file:storage.db", // Local file-based database
123
- // For production:
124
- // url: process.env.DATABASE_URL,
125
- // authToken: process.env.DATABASE_AUTH_TOKEN,
126
- },
127
- }),
128
- workflows: {
129
- weatherWorkflow,
130
- travelWorkflow,
131
- },
118
+ import { LibSQLStore } from "@mastra/libsql";
119
+
120
+ export const mastra = new Mastra({
121
+ // ...
122
+ storage: new LibSQLStore({
123
+ url: ":memory:"
124
+ })
132
125
  });
133
126
  ```
134
127
 
135
- ### Upstash (Redis-Compatible)
128
+ ### Upstash `@mastra/upstash`
136
129
 
137
- For serverless environments:
130
+ This example demonstrates how to use snapshots with Upstash.
138
131
 
139
- ```typescript
132
+ ```typescript filename="src/mastra/index.ts" showLineNumbers copy
140
133
  import { Mastra } from "@mastra/core/mastra";
141
134
  import { UpstashStore } from "@mastra/upstash";
142
135
 
143
- const mastra = new Mastra({
136
+ export const mastra = new Mastra({
137
+ // ...
144
138
  storage: new UpstashStore({
145
- url: process.env.UPSTASH_URL,
146
- token: process.env.UPSTASH_TOKEN,
147
- }),
148
- workflows: {
149
- weatherWorkflow,
150
- travelWorkflow,
151
- },
139
+ url: "<upstash-redis-rest-url>",
140
+ token: "<upstash-redis-rest-token>"
141
+ })
142
+ })
143
+ ```
144
+
145
+ ### Postgres `@mastra/pg`
146
+
147
+ This example demonstrates how to use snapshots with PostgreSQL.
148
+
149
+ ```typescript filename="src/mastra/index.ts" showLineNumbers copy
150
+ import { Mastra } from "@mastra/core/mastra";
151
+ import { PostgresStore } from "@mastra/pg";
152
+
153
+ export const mastra = new Mastra({
154
+ // ...
155
+ storage: new PostgresStore({
156
+ connectionString: "<database-url>"
157
+ })
152
158
  });
153
159
  ```
154
160
 
155
- ## Best Practices for Working with Snapshots
161
+ ## Best practices
156
162
 
157
163
  1. **Ensure Serializability**: Any data that needs to be included in the snapshot must be serializable (convertible to JSON).
158
-
159
164
  2. **Minimize Snapshot Size**: Avoid storing large data objects directly in the workflow context. Instead, store references to them (like IDs) and retrieve the data when needed.
160
-
161
165
  3. **Handle Resume Context Carefully**: When resuming a workflow, carefully consider what context to provide. This will be merged with the existing snapshot data.
162
-
163
166
  4. **Set Up Proper Monitoring**: Implement monitoring for suspended workflows, especially long-running ones, to ensure they are properly resumed.
164
-
165
167
  5. **Consider Storage Scaling**: For applications with many suspended workflows, ensure your storage solution is appropriately scaled.
166
168
 
167
- ## Advanced Snapshot Patterns
169
+ ## Custom snapshot metadata
168
170
 
169
- ### Custom Snapshot Metadata
171
+ You can attach custom metadata when suspending a workflow by defining a `suspendSchema`. This metadata is stored in the snapshot and made available when the workflow is resumed.
170
172
 
171
- When suspending a workflow, you can include custom metadata that can help when resuming:
173
+ ```typescript {30-34} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
174
+ import { createWorkflow, createStep } from "@mastra/core/workflows";
175
+ import { z } from "zod";
172
176
 
173
- ```typescript
174
- await suspend({
175
- reason: "Waiting for customer approval",
176
- requiredApprovers: ["manager", "finance"],
177
- requestedBy: currentUser,
178
- urgency: "high",
179
- expires: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
177
+ const approvalStep = createStep({
178
+ id: "approval-step",
179
+ description: "Accepts a value, waits for confirmation",
180
+ inputSchema: z.object({
181
+ value: z.number(),
182
+ user: z.string(),
183
+ requiredApprovers: z.array(z.string())
184
+ }),
185
+ suspendSchema: z.object({
186
+ message: z.string(),
187
+ requestedBy: z.string(),
188
+ approvers: z.array(z.string())
189
+ }),
190
+ resumeSchema: z.object({
191
+ confirm: z.boolean(),
192
+ approver: z.string()
193
+ }),
194
+ outputSchema: z.object({
195
+ value: z.number(),
196
+ approved: z.boolean()
197
+ }),
198
+ execute: async ({ inputData, resumeData, suspend }) => {
199
+ const { value, user, requiredApprovers } = inputData;
200
+ const { confirm } = resumeData ?? {};
201
+
202
+ if (!confirm) {
203
+ return await suspend({
204
+ message: "Workflow suspended",
205
+ requestedBy: user,
206
+ approvers: [...requiredApprovers]
207
+ });
208
+ }
209
+
210
+ return {
211
+ value,
212
+ approved: confirm
213
+ };
214
+ }
180
215
  });
181
216
  ```
182
217
 
183
- This metadata is stored with the snapshot and available when resuming.
218
+ ### Providing resume data
184
219
 
185
- ### Conditional Resumption
220
+ Use `resumeData` to pass structured input when resuming a suspended step. It must match the step’s `resumeSchema`.
186
221
 
187
- You can implement conditional logic based on the suspend payload when resuming:
222
+ ```typescript {14-20} showLineNumbers copy
223
+ const workflow = mastra.getWorkflow("approvalWorkflow");
188
224
 
189
- ```typescript
190
- run.watch(async ({ activePaths }) => {
191
- const isApprovalStepSuspended =
192
- activePaths.get("approval")?.status === "suspended";
193
- if (isApprovalStepSuspended) {
194
- const payload = activePaths.get("approval")?.suspendPayload;
195
- if (payload.urgency === "high" && currentUser.role === "manager") {
196
- await resume({
197
- stepId: "approval",
198
- context: { approved: true, approver: currentUser.id },
199
- });
200
- }
225
+ const run = await workflow.createRunAsync();
226
+
227
+ const result = await run.start({
228
+ inputData: {
229
+ value: 100,
230
+ user: "Michael",
231
+ requiredApprovers: ["manager", "finance"]
201
232
  }
202
233
  });
234
+
235
+ if (result.status === "suspended") {
236
+ const resumedResult = await run.resume({
237
+ step: "approval-step",
238
+ resumeData: {
239
+ confirm: true,
240
+ approver: "manager"
241
+ }
242
+ });
243
+ }
203
244
  ```
204
245
 
205
246
  ## Related
@@ -138,6 +138,13 @@ export const mastra = new Mastra({
138
138
  // - Handle workflow state persistence and real-time updates
139
139
  // 3. Establishing a publish-subscribe system for real-time monitoring
140
140
  // through the workflow:${workflowId}:${runId} channel
141
+ //
142
+ // Optional: You can also pass additional Inngest functions to serve alongside workflows:
143
+ // createHandler: async ({ mastra }) => inngestServe({
144
+ // mastra,
145
+ // inngest,
146
+ // functions: [customFunction1, customFunction2] // User-defined Inngest functions
147
+ // }),
141
148
  },
142
149
  ],
143
150
  },
@@ -275,3 +282,78 @@ vercel --prod
275
282
  - Go to the **Runs** tab.
276
283
  - Click the latest run to see step-by-step execution progress.
277
284
  ![Inngest Function Run](/inngest-runs-dashboard-prod.png)
285
+
286
+ ## Advanced Usage: Adding Custom Inngest Functions
287
+
288
+ You can serve additional Inngest functions alongside your Mastra workflows by using the optional `functions` parameter in `inngestServe`.
289
+
290
+ ### Creating Custom Functions
291
+
292
+ First, create your custom Inngest functions:
293
+
294
+ ```ts showLineNumbers copy filename="src/inngest/custom-functions.ts"
295
+ import { inngest } from "./inngest";
296
+
297
+ // Define custom Inngest functions
298
+ export const customEmailFunction = inngest.createFunction(
299
+ { id: 'send-welcome-email' },
300
+ { event: 'user/registered' },
301
+ async ({ event }) => {
302
+ // Custom email logic here
303
+ console.log(`Sending welcome email to ${event.data.email}`);
304
+ return { status: 'email_sent' };
305
+ }
306
+ );
307
+
308
+ export const customWebhookFunction = inngest.createFunction(
309
+ { id: 'process-webhook' },
310
+ { event: 'webhook/received' },
311
+ async ({ event }) => {
312
+ // Custom webhook processing
313
+ console.log(`Processing webhook: ${event.data.type}`);
314
+ return { processed: true };
315
+ }
316
+ );
317
+ ```
318
+
319
+ ### Serving Custom Functions with Workflows
320
+
321
+ Update your Mastra configuration to include the custom functions:
322
+
323
+ ```ts showLineNumbers copy filename="src/mastra/index.ts"
324
+ import { Mastra } from "@mastra/core/mastra";
325
+ import { serve as inngestServe } from "@mastra/inngest";
326
+ import { incrementWorkflow } from "./workflows";
327
+ import { inngest } from "./inngest";
328
+ import { customEmailFunction, customWebhookFunction } from "./inngest/custom-functions";
329
+
330
+ export const mastra = new Mastra({
331
+ workflows: {
332
+ incrementWorkflow,
333
+ },
334
+ server: {
335
+ host: "0.0.0.0",
336
+ apiRoutes: [
337
+ {
338
+ path: "/api/inngest",
339
+ method: "ALL",
340
+ createHandler: async ({ mastra }) => inngestServe({
341
+ mastra,
342
+ inngest,
343
+ functions: [customEmailFunction, customWebhookFunction] // Add your custom functions
344
+ }),
345
+ },
346
+ ],
347
+ },
348
+ });
349
+ ```
350
+
351
+ ### Function Registration
352
+
353
+ When you include custom functions:
354
+
355
+ 1. **Mastra workflows** are automatically converted to Inngest functions with IDs like `workflow.${workflowId}`
356
+ 2. **Custom functions** retain their specified IDs (e.g., `send-welcome-email`, `process-webhook`)
357
+ 3. **All functions** are served together on the same `/api/inngest` endpoint
358
+
359
+ This allows you to combine Mastra's workflow orchestration with your existing Inngest functions seamlessly.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 0.13.22-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`fb84c21`](https://github.com/mastra-ai/mastra/commit/fb84c21859d09bdc8f158bd5412bdc4b5835a61c), [`9d4fc09`](https://github.com/mastra-ai/mastra/commit/9d4fc09b2ad55caa7738c7ceb3a905e454f74cdd), [`d75ccf0`](https://github.com/mastra-ai/mastra/commit/d75ccf06dfd2582b916aa12624e3cd61b279edf1), [`0fed8f2`](https://github.com/mastra-ai/mastra/commit/0fed8f2aa84b167b3415ea6f8f70755775132c8d), [`87fd07f`](https://github.com/mastra-ai/mastra/commit/87fd07ff35387a38728967163460231b5d33ae3b)]:
8
+ - @mastra/core@0.17.0-alpha.4
9
+ - @mastra/mcp@0.13.0-alpha.1
10
+
3
11
  ## 0.13.22-alpha.3
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "0.13.22-alpha.3",
3
+ "version": "0.13.22-alpha.4",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,8 +33,8 @@
33
33
  "uuid": "^11.1.0",
34
34
  "zod": "^3.25.76",
35
35
  "zod-to-json-schema": "^3.24.6",
36
- "@mastra/core": "0.17.0-alpha.3",
37
- "@mastra/mcp": "^0.12.1-alpha.0"
36
+ "@mastra/core": "0.17.0-alpha.4",
37
+ "@mastra/mcp": "^0.13.0-alpha.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@hono/node-server": "^1.19.2",
@@ -50,7 +50,7 @@
50
50
  "typescript": "^5.8.3",
51
51
  "vitest": "^3.2.4",
52
52
  "@internal/lint": "0.0.39",
53
- "@mastra/core": "0.17.0-alpha.3"
53
+ "@mastra/core": "0.17.0-alpha.4"
54
54
  },
55
55
  "homepage": "https://mastra.ai",
56
56
  "repository": {