@mastra/mcp-docs-server 0.0.0-a2a-20250421213654

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 (274) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +253 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +16 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +202 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  15. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +113 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +281 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +302 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  52. package/.docs/organized/changelogs/create-mastra.md +302 -0
  53. package/.docs/organized/changelogs/mastra.md +302 -0
  54. package/.docs/organized/code-examples/agent-network.md +282 -0
  55. package/.docs/organized/code-examples/agent.md +426 -0
  56. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  57. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  58. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  59. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  60. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  61. package/.docs/organized/code-examples/client-side-tools.md +69 -0
  62. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  63. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  64. package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
  65. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  66. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  67. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  68. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  69. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  70. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  71. package/.docs/organized/code-examples/quick-start.md +129 -0
  72. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  73. package/.docs/organized/code-examples/weather-agent.md +331 -0
  74. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  75. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  76. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  77. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  78. package/.docs/raw/agents/adding-tools.mdx +288 -0
  79. package/.docs/raw/agents/adding-voice.mdx +200 -0
  80. package/.docs/raw/agents/agent-memory.mdx +62 -0
  81. package/.docs/raw/agents/mcp-guide.mdx +215 -0
  82. package/.docs/raw/agents/overview.mdx +303 -0
  83. package/.docs/raw/agents/runtime-variables.mdx +137 -0
  84. package/.docs/raw/community/discord.mdx +12 -0
  85. package/.docs/raw/community/licensing.mdx +63 -0
  86. package/.docs/raw/deployment/client.mdx +120 -0
  87. package/.docs/raw/deployment/deployment.mdx +127 -0
  88. package/.docs/raw/deployment/overview.mdx +63 -0
  89. package/.docs/raw/deployment/server.mdx +282 -0
  90. package/.docs/raw/evals/custom-eval.mdx +22 -0
  91. package/.docs/raw/evals/overview.mdx +95 -0
  92. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  93. package/.docs/raw/evals/textual-evals.mdx +54 -0
  94. package/.docs/raw/faq/index.mdx +63 -0
  95. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  96. package/.docs/raw/frameworks/next-js.mdx +238 -0
  97. package/.docs/raw/getting-started/installation.mdx +442 -0
  98. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  99. package/.docs/raw/getting-started/model-capability.mdx +11 -0
  100. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  101. package/.docs/raw/index.mdx +22 -0
  102. package/.docs/raw/integrations/index.mdx +213 -0
  103. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  104. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  105. package/.docs/raw/local-dev/mastra-dev.mdx +124 -0
  106. package/.docs/raw/mastra-cloud/deploying.mdx +136 -0
  107. package/.docs/raw/mastra-cloud/observability.mdx +163 -0
  108. package/.docs/raw/mastra-cloud/overview.mdx +57 -0
  109. package/.docs/raw/mastra-cloud/setting-up.mdx +122 -0
  110. package/.docs/raw/memory/memory-processors.mdx +131 -0
  111. package/.docs/raw/memory/overview.mdx +119 -0
  112. package/.docs/raw/memory/semantic-recall.mdx +126 -0
  113. package/.docs/raw/memory/working-memory.mdx +87 -0
  114. package/.docs/raw/observability/logging.mdx +38 -0
  115. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  116. package/.docs/raw/observability/tracing.mdx +115 -0
  117. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  118. package/.docs/raw/rag/overview.mdx +85 -0
  119. package/.docs/raw/rag/retrieval.mdx +365 -0
  120. package/.docs/raw/rag/vector-databases.mdx +340 -0
  121. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  122. package/.docs/raw/reference/agents/generate.mdx +334 -0
  123. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  124. package/.docs/raw/reference/agents/stream.mdx +369 -0
  125. package/.docs/raw/reference/cli/build.mdx +55 -0
  126. package/.docs/raw/reference/cli/dev.mdx +134 -0
  127. package/.docs/raw/reference/cli/init.mdx +43 -0
  128. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  129. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  130. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  131. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  132. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  133. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  134. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  135. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  136. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  137. package/.docs/raw/reference/deployer/cloudflare.mdx +212 -0
  138. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  139. package/.docs/raw/reference/deployer/netlify.mdx +116 -0
  140. package/.docs/raw/reference/deployer/vercel.mdx +122 -0
  141. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  142. package/.docs/raw/reference/evals/bias.mdx +186 -0
  143. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  144. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  145. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  146. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  147. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  148. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  149. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  150. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  151. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  152. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  153. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  154. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  155. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  156. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  157. package/.docs/raw/reference/index.mdx +12 -0
  158. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  159. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  160. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  161. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  162. package/.docs/raw/reference/memory/query.mdx +167 -0
  163. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  164. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  165. package/.docs/raw/reference/observability/logger.mdx +55 -0
  166. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  167. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  168. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  169. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  170. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  171. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  172. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  173. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  174. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  175. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  176. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  177. package/.docs/raw/reference/rag/astra.mdx +258 -0
  178. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  179. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  180. package/.docs/raw/reference/rag/document.mdx +127 -0
  181. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  182. package/.docs/raw/reference/rag/extract-params.mdx +249 -0
  183. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  184. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  185. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  186. package/.docs/raw/reference/rag/pg.mdx +501 -0
  187. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  188. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  189. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  190. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  191. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  192. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  193. package/.docs/raw/reference/storage/cloudflare-d1.mdx +89 -0
  194. package/.docs/raw/reference/storage/cloudflare.mdx +93 -0
  195. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  196. package/.docs/raw/reference/storage/postgresql.mdx +93 -0
  197. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  198. package/.docs/raw/reference/tools/client.mdx +321 -0
  199. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  200. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  201. package/.docs/raw/reference/tools/mcp-configuration.mdx +222 -0
  202. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  203. package/.docs/raw/reference/voice/azure.mdx +215 -0
  204. package/.docs/raw/reference/voice/cloudflare.mdx +152 -0
  205. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  206. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  207. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  208. package/.docs/raw/reference/voice/google.mdx +198 -0
  209. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  210. package/.docs/raw/reference/voice/murf.mdx +251 -0
  211. package/.docs/raw/reference/voice/openai-realtime.mdx +432 -0
  212. package/.docs/raw/reference/voice/openai.mdx +168 -0
  213. package/.docs/raw/reference/voice/playai.mdx +159 -0
  214. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  215. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  216. package/.docs/raw/reference/voice/voice.addInstructions.mdx +70 -0
  217. package/.docs/raw/reference/voice/voice.addTools.mdx +77 -0
  218. package/.docs/raw/reference/voice/voice.answer.mdx +69 -0
  219. package/.docs/raw/reference/voice/voice.close.mdx +56 -0
  220. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  221. package/.docs/raw/reference/voice/voice.events.mdx +80 -0
  222. package/.docs/raw/reference/voice/voice.getSpeakers.mdx +283 -0
  223. package/.docs/raw/reference/voice/voice.listen.mdx +198 -0
  224. package/.docs/raw/reference/voice/voice.off.mdx +72 -0
  225. package/.docs/raw/reference/voice/voice.on.mdx +129 -0
  226. package/.docs/raw/reference/voice/voice.send.mdx +81 -0
  227. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  228. package/.docs/raw/reference/voice/voice.updateConfig.mdx +87 -0
  229. package/.docs/raw/reference/workflows/after.mdx +88 -0
  230. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  231. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  232. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  233. package/.docs/raw/reference/workflows/else.mdx +72 -0
  234. package/.docs/raw/reference/workflows/events.mdx +305 -0
  235. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  236. package/.docs/raw/reference/workflows/if.mdx +107 -0
  237. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  238. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  239. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  240. package/.docs/raw/reference/workflows/start.mdx +84 -0
  241. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  242. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  243. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  244. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  245. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  246. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  247. package/.docs/raw/reference/workflows/then.mdx +74 -0
  248. package/.docs/raw/reference/workflows/until.mdx +165 -0
  249. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  250. package/.docs/raw/reference/workflows/while.mdx +168 -0
  251. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  252. package/.docs/raw/storage/overview.mdx +378 -0
  253. package/.docs/raw/voice/overview.mdx +816 -0
  254. package/.docs/raw/voice/speech-to-speech.mdx +73 -0
  255. package/.docs/raw/voice/speech-to-text.mdx +84 -0
  256. package/.docs/raw/voice/text-to-speech.mdx +89 -0
  257. package/.docs/raw/workflows/control-flow.mdx +778 -0
  258. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  259. package/.docs/raw/workflows/error-handling.mdx +183 -0
  260. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  261. package/.docs/raw/workflows/overview.mdx +170 -0
  262. package/.docs/raw/workflows/runtime-variables.mdx +153 -0
  263. package/.docs/raw/workflows/steps.mdx +108 -0
  264. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  265. package/.docs/raw/workflows/variables.mdx +313 -0
  266. package/LICENSE.md +46 -0
  267. package/README.md +129 -0
  268. package/dist/_tsup-dts-rollup.d.ts +140 -0
  269. package/dist/chunk-HYPVNJL7.js +194 -0
  270. package/dist/prepare-docs/prepare.d.ts +1 -0
  271. package/dist/prepare-docs/prepare.js +1 -0
  272. package/dist/stdio.d.ts +1 -0
  273. package/dist/stdio.js +650 -0
  274. package/package.json +60 -0
@@ -0,0 +1,108 @@
1
+ ---
2
+ title: "Creating Steps and Adding to Workflows | Mastra Docs"
3
+ description: "Steps in Mastra workflows provide a structured way to manage operations by defining inputs, outputs, and execution logic."
4
+ ---
5
+
6
+ # Defining Steps in a Workflow
7
+
8
+ When you build a workflow, you typically break down operations into smaller tasks that can be linked and reused. Steps provide a structured way to manage these tasks by defining inputs, outputs, and execution logic.
9
+
10
+ The code below shows how to define these steps inline or separately.
11
+
12
+ ## Inline Step Creation
13
+
14
+ You can create steps directly within your workflow using `.step()` and `.then()`. This code shows how to define, link, and execute two steps in sequence.
15
+
16
+ ```typescript showLineNumbers filename="src/mastra/workflows/index.ts" copy
17
+ import { Step, Workflow, Mastra } from "@mastra/core";
18
+ import { z } from "zod";
19
+
20
+ export const myWorkflow = new Workflow({
21
+ name: "my-workflow",
22
+ triggerSchema: z.object({
23
+ inputValue: z.number(),
24
+ }),
25
+ });
26
+
27
+ myWorkflow
28
+ .step(
29
+ new Step({
30
+ id: "stepOne",
31
+ outputSchema: z.object({
32
+ doubledValue: z.number(),
33
+ }),
34
+ execute: async ({ context }) => ({
35
+ doubledValue: context.triggerData.inputValue * 2,
36
+ }),
37
+ }),
38
+ )
39
+ .then(
40
+ new Step({
41
+ id: "stepTwo",
42
+ outputSchema: z.object({
43
+ incrementedValue: z.number(),
44
+ }),
45
+ execute: async ({ context }) => {
46
+ if (context.steps.stepOne.status !== "success") {
47
+ return { incrementedValue: 0 };
48
+ }
49
+
50
+ return { incrementedValue: context.steps.stepOne.output.doubledValue + 1 };
51
+ },
52
+ }),
53
+ ).commit();
54
+
55
+ // Register the workflow with Mastra
56
+ export const mastra = new Mastra({
57
+ workflows: { myWorkflow },
58
+ });
59
+ ```
60
+
61
+ ## Creating Steps Separately
62
+
63
+ If you prefer to manage your step logic in separate entities, you can define steps outside and then add them to your workflow. This code shows how to define steps independently and link them afterward.
64
+
65
+ ```typescript showLineNumbers filename="src/mastra/workflows/index.ts" copy
66
+ import { Step, Workflow, Mastra } from "@mastra/core";
67
+ import { z } from "zod";
68
+
69
+ // Define steps separately
70
+ const stepOne = new Step({
71
+ id: "stepOne",
72
+ outputSchema: z.object({
73
+ doubledValue: z.number(),
74
+ }),
75
+ execute: async ({ context }) => ({
76
+ doubledValue: context.triggerData.inputValue * 2,
77
+ }),
78
+ });
79
+
80
+ const stepTwo = new Step({
81
+ id: "stepTwo",
82
+ outputSchema: z.object({
83
+ incrementedValue: z.number(),
84
+ }),
85
+ execute: async ({ context }) => {
86
+ if (context.steps.stepOne.status !== "success") {
87
+ return { incrementedValue: 0 };
88
+ }
89
+ return { incrementedValue: context.steps.stepOne.output.doubledValue + 1 };
90
+ },
91
+ });
92
+
93
+ // Build the workflow
94
+ const myWorkflow = new Workflow({
95
+ name: "my-workflow",
96
+ triggerSchema: z.object({
97
+ inputValue: z.number(),
98
+ }),
99
+ });
100
+
101
+ myWorkflow.step(stepOne).then(stepTwo);
102
+ myWorkflow.commit();
103
+
104
+ // Register the workflow with Mastra
105
+ export const mastra = new Mastra({
106
+ workflows: { myWorkflow },
107
+ });
108
+ ```
@@ -0,0 +1,404 @@
1
+ ---
2
+ title: "Suspend & Resume Workflows | Human-in-the-Loop | Mastra Docs"
3
+ description: "Suspend and resume in Mastra workflows allows you to pause execution while waiting for external input or resources."
4
+ ---
5
+
6
+ # Suspend and Resume in Workflows
7
+
8
+ Complex workflows often need to pause execution while waiting for external input or resources.
9
+
10
+ Mastra's suspend and resume features let you pause workflow execution at any step, persist the workflow snapshot to storage, and resume execution from the saved snapshot when ready.
11
+ This entire process is automatically managed by Mastra. No config needed, or manual step required from the user.
12
+
13
+ Storing the workflow snapshot to storage (LibSQL by default) means that the workflow state is permanently preserved across sessions, deployments, and server restarts. This persistence is crucial for workflows that might remain suspended for minutes, hours, or even days while waiting for external input or resources.
14
+
15
+ ## When to Use Suspend/Resume
16
+
17
+ Common scenarios for suspending workflows include:
18
+
19
+ - Waiting for human approval or input
20
+ - Pausing until external API resources become available
21
+ - Collecting additional data needed for later steps
22
+ - Rate limiting or throttling expensive operations
23
+ - Handling event-driven processes with external triggers
24
+
25
+ ## Basic Suspend Example
26
+
27
+ Here's a simple workflow that suspends when a value is too low and resumes when given a higher value:
28
+
29
+ ```typescript
30
+ const stepTwo = new Step({
31
+ id: "stepTwo",
32
+ outputSchema: z.object({
33
+ incrementedValue: z.number(),
34
+ }),
35
+ execute: async ({ context, suspend }) => {
36
+ if (context.steps.stepOne.status !== "success") {
37
+ return { incrementedValue: 0 };
38
+ }
39
+
40
+ const currentValue = context.steps.stepOne.output.doubledValue;
41
+
42
+ if (currentValue < 100) {
43
+ await suspend();
44
+ return { incrementedValue: 0 };
45
+ }
46
+ return { incrementedValue: currentValue + 1 };
47
+ },
48
+ });
49
+ ```
50
+
51
+ ## Async/Await Based Flow
52
+
53
+ The suspend and resume mechanism in Mastra uses an async/await pattern that makes it intuitive to implement complex workflows with suspension points. The code structure naturally reflects the execution flow.
54
+
55
+ ### How It Works
56
+
57
+ 1. A step's execution function receives a `suspend` function in its parameters
58
+ 2. When called with `await suspend()`, the workflow pauses at that point
59
+ 3. The workflow state is persisted
60
+ 4. Later, the workflow can be resumed by calling `workflow.resume()` with the appropriate parameters
61
+ 5. Execution continues from the point after the `suspend()` call
62
+
63
+ ### Example with Multiple Suspension Points
64
+
65
+ Here's an example of a workflow with multiple steps that can suspend:
66
+
67
+ ```typescript
68
+ // Define steps with suspend capability
69
+ const promptAgentStep = new Step({
70
+ id: "promptAgent",
71
+ execute: async ({ context, suspend }) => {
72
+ // Some condition that determines if we need to suspend
73
+ if (needHumanInput) {
74
+ // Optionally pass payload data that will be stored with suspended state
75
+ await suspend({ requestReason: "Need human input for prompt" });
76
+ // Code after suspend() will execute when the step is resumed
77
+ return { modelOutput: context.userInput };
78
+ }
79
+ return { modelOutput: "AI generated output" };
80
+ },
81
+ outputSchema: z.object({ modelOutput: z.string() }),
82
+ });
83
+
84
+ const improveResponseStep = new Step({
85
+ id: "improveResponse",
86
+ execute: async ({ context, suspend }) => {
87
+ // Another condition for suspension
88
+ if (needFurtherRefinement) {
89
+ await suspend();
90
+ return { improvedOutput: context.refinedOutput };
91
+ }
92
+ return { improvedOutput: "Improved output" };
93
+ },
94
+ outputSchema: z.object({ improvedOutput: z.string() }),
95
+ });
96
+
97
+ // Build the workflow
98
+ const workflow = new Workflow({
99
+ name: "multi-suspend-workflow",
100
+ triggerSchema: z.object({ input: z.string() }),
101
+ });
102
+
103
+ workflow
104
+ .step(getUserInput)
105
+ .then(promptAgentStep)
106
+ .then(evaluateTone)
107
+ .then(improveResponseStep)
108
+ .then(evaluateImproved)
109
+ .commit();
110
+
111
+ // Register the workflow with Mastra
112
+ export const mastra = new Mastra({
113
+ workflows: { workflow },
114
+ });
115
+ ```
116
+
117
+ ### Starting and Resuming the Workflow
118
+
119
+ ```typescript
120
+ // Get the workflow and create a run
121
+ const wf = mastra.getWorkflow("multi-suspend-workflow");
122
+ const run = wf.createRun();
123
+
124
+ // Start the workflow
125
+ const initialResult = await run.start({
126
+ triggerData: { input: "initial input" },
127
+ });
128
+
129
+ let promptAgentStepResult = initialResult.activePaths.get("promptAgent");
130
+ let promptAgentResumeResult = undefined;
131
+
132
+ // Check if a step is suspended
133
+ if (promptAgentStepResult?.status === "suspended") {
134
+ console.log("Workflow suspended at promptAgent step");
135
+
136
+ // Resume the workflow with new context
137
+ const resumeResult = await run.resume({
138
+ stepId: "promptAgent",
139
+ context: { userInput: "Human provided input" },
140
+ });
141
+
142
+ promptAgentResumeResult = resumeResult;
143
+ }
144
+
145
+ const improveResponseStepResult =
146
+ promptAgentResumeResult?.activePaths.get("improveResponse");
147
+
148
+ if (improveResponseStepResult?.status === "suspended") {
149
+ console.log("Workflow suspended at improveResponse step");
150
+
151
+ // Resume again with different context
152
+ const finalResult = await run.resume({
153
+ stepId: "improveResponse",
154
+ context: { refinedOutput: "Human refined output" },
155
+ });
156
+
157
+ console.log("Workflow completed:", finalResult?.results);
158
+ }
159
+ ```
160
+
161
+ ## Event-Based Suspension and Resumption
162
+
163
+ In addition to manually suspending steps, Mastra provides event-based suspension through the `afterEvent` method. This allows workflows to automatically suspend and wait for a specific event to occur before continuing.
164
+
165
+ ### Using afterEvent and resumeWithEvent
166
+
167
+ The `afterEvent` method automatically creates a suspension point in your workflow that waits for a specific event to occur. When the event happens, you can use `resumeWithEvent` to continue the workflow with the event data.
168
+
169
+ Here's how it works:
170
+
171
+ 1. Define events in your workflow configuration
172
+ 2. Use `afterEvent` to create a suspension point waiting for that event
173
+ 3. When the event occurs, call `resumeWithEvent` with the event name and data
174
+
175
+ ### Example: Event-Based Workflow
176
+
177
+ ```typescript
178
+ // Define steps
179
+ const getUserInput = new Step({
180
+ id: "getUserInput",
181
+ execute: async () => ({ userInput: "initial input" }),
182
+ outputSchema: z.object({ userInput: z.string() }),
183
+ });
184
+
185
+ const processApproval = new Step({
186
+ id: "processApproval",
187
+ execute: async ({ context }) => {
188
+ // Access the event data from the context
189
+ const approvalData = context.inputData?.resumedEvent;
190
+ return {
191
+ approved: approvalData?.approved,
192
+ approvedBy: approvalData?.approverName,
193
+ };
194
+ },
195
+ outputSchema: z.object({
196
+ approved: z.boolean(),
197
+ approvedBy: z.string(),
198
+ }),
199
+ });
200
+
201
+ // Create workflow with event definition
202
+ const approvalWorkflow = new Workflow({
203
+ name: "approval-workflow",
204
+ triggerSchema: z.object({ requestId: z.string() }),
205
+ events: {
206
+ approvalReceived: {
207
+ schema: z.object({
208
+ approved: z.boolean(),
209
+ approverName: z.string(),
210
+ }),
211
+ },
212
+ },
213
+ });
214
+
215
+ // Build workflow with event-based suspension
216
+ approvalWorkflow
217
+ .step(getUserInput)
218
+ .afterEvent("approvalReceived") // Workflow will automatically suspend here
219
+ .step(processApproval) // This step runs after the event is received
220
+ .commit();
221
+ ```
222
+
223
+ ### Running an Event-Based Workflow
224
+
225
+ ```typescript
226
+ // Get the workflow
227
+ const workflow = mastra.getWorkflow("approval-workflow");
228
+ const run = workflow.createRun();
229
+
230
+ // Start the workflow
231
+ const initialResult = await run.start({
232
+ triggerData: { requestId: "request-123" },
233
+ });
234
+
235
+ console.log("Workflow started, waiting for approval event");
236
+ console.log(initialResult.results);
237
+ // Output will show the workflow is suspended at the event step:
238
+ // {
239
+ // getUserInput: { status: 'success', output: { userInput: 'initial input' } },
240
+ // __approvalReceived_event: { status: 'suspended' }
241
+ // }
242
+
243
+ // Later, when the approval event occurs:
244
+ const resumeResult = await run.resumeWithEvent("approvalReceived", {
245
+ approved: true,
246
+ approverName: "Jane Doe",
247
+ });
248
+
249
+ console.log("Workflow resumed with event data:", resumeResult.results);
250
+ // Output will show the completed workflow:
251
+ // {
252
+ // getUserInput: { status: 'success', output: { userInput: 'initial input' } },
253
+ // __approvalReceived_event: { status: 'success', output: { executed: true, resumedEvent: { approved: true, approverName: 'Jane Doe' } } },
254
+ // processApproval: { status: 'success', output: { approved: true, approvedBy: 'Jane Doe' } }
255
+ // }
256
+ ```
257
+
258
+ ### Key Points About Event-Based Workflows
259
+
260
+ - The `suspend()` function can optionally take a payload object that will be stored with the suspended state
261
+ - Code after the `await suspend()` call will not execute until the step is resumed
262
+ - When a step is suspended, its status becomes `'suspended'` in the workflow results
263
+ - When resumed, the step's status changes from `'suspended'` to `'success'` once completed
264
+ - The `resume()` method requires the `stepId` to identify which suspended step to resume
265
+ - You can provide new context data when resuming that will be merged with existing step results
266
+
267
+ - Events must be defined in the workflow configuration with a schema
268
+ - The `afterEvent` method creates a special suspended step that waits for the event
269
+ - The event step is automatically named `__eventName_event` (e.g., `__approvalReceived_event`)
270
+ - Use `resumeWithEvent` to provide event data and continue the workflow
271
+ - Event data is validated against the schema defined for that event
272
+ - The event data is available in the context as `inputData.resumedEvent`
273
+
274
+ ## Storage for Suspend and Resume
275
+
276
+ When a workflow is suspended using `await suspend()`, Mastra automatically persists the entire workflow state to storage. This is essential for workflows that might remain suspended for extended periods, as it ensures the state is preserved across application restarts or server instances.
277
+
278
+ ### Default Storage: LibSQL
279
+
280
+ By default, Mastra uses LibSQL as its storage engine:
281
+
282
+ ```typescript
283
+ import { Mastra } from "@mastra/core/mastra";
284
+ import { DefaultStorage } from "@mastra/core/storage/libsql";
285
+
286
+ const mastra = new Mastra({
287
+ storage: new DefaultStorage({
288
+ config: {
289
+ url: "file:storage.db", // Local file-based database for development
290
+ // For production, use a persistent URL:
291
+ // url: process.env.DATABASE_URL,
292
+ // authToken: process.env.DATABASE_AUTH_TOKEN, // Optional for authenticated connections
293
+ },
294
+ }),
295
+ });
296
+ ```
297
+
298
+ The LibSQL storage can be configured in different modes:
299
+
300
+ - In-memory database (testing): `:memory:`
301
+ - File-based database (development): `file:storage.db`
302
+ - Remote database (production): URLs like `libsql://your-database.turso.io`
303
+
304
+ ### Alternative Storage Options
305
+
306
+ #### Upstash (Redis-Compatible)
307
+
308
+ For serverless applications or environments where Redis is preferred:
309
+
310
+ ```bash
311
+ npm install @mastra/upstash
312
+ ```
313
+
314
+ ```typescript
315
+ import { Mastra } from "@mastra/core/mastra";
316
+ import { UpstashStore } from "@mastra/upstash";
317
+
318
+ const mastra = new Mastra({
319
+ storage: new UpstashStore({
320
+ url: process.env.UPSTASH_URL,
321
+ token: process.env.UPSTASH_TOKEN,
322
+ }),
323
+ });
324
+ ```
325
+
326
+ ### Storage Considerations
327
+
328
+ - All storage options support suspend and resume functionality identically
329
+ - The workflow state is automatically serialized and saved when suspended
330
+ - No additional configuration is needed for suspend/resume to work with storage
331
+ - Choose your storage option based on your infrastructure, scaling needs, and existing technology stack
332
+
333
+ ## Watching and Resuming
334
+
335
+ To handle suspended workflows, use the `watch` method to monitor workflow status per run and `resume` to continue execution:
336
+
337
+ ```typescript
338
+ import { mastra } from "./index";
339
+
340
+ // Get the workflow
341
+ const myWorkflow = mastra.getWorkflow("myWorkflow");
342
+ const { start, watch, resume } = myWorkflow.createRun();
343
+
344
+ // Start watching the workflow before executing it
345
+ watch(async ({ activePaths }) => {
346
+ const isStepTwoSuspended = activePaths.get("stepTwo")?.status === "suspended";
347
+ if (isStepTwoSuspended) {
348
+ console.log("Workflow suspended, resuming with new value");
349
+
350
+ // Resume the workflow with new context
351
+ await resume({
352
+ stepId: "stepTwo",
353
+ context: { secondValue: 100 },
354
+ });
355
+ }
356
+ });
357
+
358
+ // Start the workflow execution
359
+ await start({ triggerData: { inputValue: 45 } });
360
+ ```
361
+
362
+ ### Watching and Resuming Event-Based Workflows
363
+
364
+ You can use the same watching pattern with event-based workflows:
365
+
366
+ ```typescript
367
+ const { start, watch, resumeWithEvent } = workflow.createRun();
368
+
369
+ // Watch for suspended event steps
370
+ watch(async ({ activePaths }) => {
371
+ const isApprovalReceivedSuspended =
372
+ activePaths.get("__approvalReceived_event")?.status === "suspended";
373
+ if (isApprovalReceivedSuspended) {
374
+ console.log("Workflow waiting for approval event");
375
+
376
+ // In a real scenario, you would wait for the actual event to occur
377
+ // For example, this could be triggered by a webhook or user interaction
378
+ setTimeout(async () => {
379
+ await resumeWithEvent("approvalReceived", {
380
+ approved: true,
381
+ approverName: "Auto Approver",
382
+ });
383
+ }, 5000); // Simulate event after 5 seconds
384
+ }
385
+ });
386
+
387
+ // Start the workflow
388
+ await start({ triggerData: { requestId: "auto-123" } });
389
+ ```
390
+
391
+ ## Further Reading
392
+
393
+ For a deeper understanding of how suspend and resume works under the hood:
394
+
395
+ - [Understanding Snapshots in Mastra Workflows](../../reference/workflows/snapshots.mdx) - Learn about the snapshot mechanism that powers suspend and resume functionality
396
+ - [Step Configuration Guide](./steps.mdx) - Learn more about configuring steps in your workflows
397
+ - [Control Flow Guide](./control-flow.mdx) - Advanced workflow control patterns
398
+ - [Event-Driven Workflows](../../reference/workflows/events.mdx) - Detailed reference for event-based workflows
399
+
400
+ ## Related Resources
401
+
402
+ - See the [Suspend and Resume Example](../../examples/workflows/suspend-and-resume.mdx) for a complete working example
403
+ - Check the [Step Class Reference](../../reference/workflows/step-class.mdx) for suspend/resume API details
404
+ - Review [Workflow Observability](../../reference/observability/otel-config.mdx) for monitoring suspended workflows