@mastra/mcp-docs-server 1.0.0-beta.1 → 1.0.0-beta.11

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 (491) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +1 -15
  2. package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +1 -7
  3. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +201 -1
  4. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +1 -55
  5. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
  6. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +276 -76
  7. package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
  8. package/.docs/organized/changelogs/%40mastra%2Fauth.md +6 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
  10. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
  11. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +200 -0
  12. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
  13. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
  14. package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +26 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +89 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fcore.md +392 -192
  17. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
  18. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
  19. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
  20. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
  21. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
  22. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +200 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
  24. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
  25. package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +61 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
  27. package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
  28. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
  29. package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
  30. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
  31. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
  32. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
  33. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
  34. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
  35. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
  36. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
  37. package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
  38. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
  39. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +263 -63
  40. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
  41. package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
  42. package/.docs/organized/changelogs/%40mastra%2Freact.md +154 -1
  43. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +18 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +42 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fserver.md +274 -74
  46. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
  47. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
  48. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +92 -1
  54. package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -1
  55. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
  56. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
  57. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
  58. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
  59. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
  60. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
  61. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
  62. package/.docs/organized/changelogs/create-mastra.md +201 -1
  63. package/.docs/organized/changelogs/mastra.md +201 -1
  64. package/.docs/organized/code-examples/agui.md +1 -0
  65. package/.docs/organized/code-examples/ai-elements.md +2 -2
  66. package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
  67. package/.docs/organized/code-examples/ai-sdk-v5.md +3 -2
  68. package/.docs/organized/code-examples/assistant-ui.md +2 -2
  69. package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
  70. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +2 -2
  71. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +2 -2
  72. package/.docs/organized/code-examples/client-side-tools.md +1 -1
  73. package/.docs/organized/code-examples/crypto-chatbot.md +2 -2
  74. package/.docs/organized/code-examples/fireworks-r1.md +1 -1
  75. package/.docs/organized/code-examples/heads-up-game.md +1 -1
  76. package/.docs/organized/code-examples/mcp-configuration.md +0 -3
  77. package/.docs/organized/code-examples/mcp-server-adapters.md +720 -0
  78. package/.docs/organized/code-examples/memory-per-resource-example.md +1 -1
  79. package/.docs/organized/code-examples/memory-with-processors.md +1 -1
  80. package/.docs/organized/code-examples/openapi-spec-writer.md +1 -1
  81. package/.docs/organized/code-examples/processors-with-ai-sdk.md +14 -0
  82. package/.docs/organized/code-examples/quick-start.md +2 -2
  83. package/.docs/organized/code-examples/server-app-access.md +342 -0
  84. package/.docs/organized/code-examples/server-express-adapter.md +87 -0
  85. package/.docs/organized/code-examples/server-hono-adapter.md +85 -0
  86. package/.docs/organized/code-examples/stock-price-tool.md +1 -21
  87. package/.docs/organized/code-examples/workflow-ai-recruiter.md +1 -1
  88. package/.docs/organized/code-examples/workflow-with-inline-steps.md +1 -1
  89. package/.docs/organized/code-examples/workflow-with-memory.md +1 -1
  90. package/.docs/organized/code-examples/workflow-with-separate-steps.md +1 -1
  91. package/.docs/organized/code-examples/workflow-with-suspend-resume.md +1 -1
  92. package/.docs/raw/agents/adding-voice.mdx +56 -10
  93. package/.docs/raw/agents/agent-approval.mdx +189 -0
  94. package/.docs/raw/agents/agent-memory.mdx +1 -1
  95. package/.docs/raw/agents/guardrails.mdx +70 -30
  96. package/.docs/raw/agents/networks.mdx +3 -3
  97. package/.docs/raw/agents/overview.mdx +18 -167
  98. package/.docs/raw/agents/processors.mdx +430 -0
  99. package/.docs/raw/agents/structured-output.mdx +224 -0
  100. package/.docs/raw/agents/using-tools.mdx +14 -14
  101. package/.docs/raw/auth/auth0.mdx +1 -1
  102. package/.docs/raw/auth/clerk.mdx +1 -1
  103. package/.docs/raw/auth/firebase.mdx +1 -1
  104. package/.docs/raw/auth/index.mdx +1 -1
  105. package/.docs/raw/auth/jwt.mdx +1 -1
  106. package/.docs/raw/auth/supabase.mdx +1 -1
  107. package/.docs/raw/auth/workos.mdx +1 -1
  108. package/.docs/raw/community/contributing-templates.mdx +1 -1
  109. package/.docs/raw/community/discord.mdx +2 -2
  110. package/.docs/raw/community/licensing.mdx +1 -1
  111. package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
  112. package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
  113. package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
  114. package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
  115. package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
  116. package/.docs/raw/deployment/{server-deployment.mdx → building-mastra.mdx} +4 -4
  117. package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +2 -2
  118. package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +3 -3
  119. package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +2 -2
  120. package/.docs/raw/deployment/{serverless-platforms → cloud-providers}/cloudflare-deployer.mdx +1 -1
  121. package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +2 -2
  122. package/.docs/raw/deployment/cloud-providers/index.mdx +26 -29
  123. package/.docs/raw/deployment/{serverless-platforms → cloud-providers}/netlify-deployer.mdx +45 -14
  124. package/.docs/raw/deployment/{serverless-platforms → cloud-providers}/vercel-deployer.mdx +1 -1
  125. package/.docs/raw/{mastra-cloud → deployment/mastra-cloud}/dashboard.mdx +3 -3
  126. package/.docs/raw/deployment/mastra-cloud/observability.mdx +53 -0
  127. package/.docs/raw/{mastra-cloud → deployment/mastra-cloud}/overview.mdx +3 -3
  128. package/.docs/raw/{mastra-cloud → deployment/mastra-cloud}/setting-up.mdx +4 -4
  129. package/.docs/raw/deployment/monorepo.mdx +3 -3
  130. package/.docs/raw/deployment/overview.mdx +7 -7
  131. package/.docs/raw/deployment/web-framework.mdx +6 -6
  132. package/.docs/raw/evals/{off-the-shelf-scorers.mdx → built-in-scorers.mdx} +17 -15
  133. package/.docs/raw/evals/custom-scorers.mdx +4 -6
  134. package/.docs/raw/evals/overview.mdx +5 -6
  135. package/.docs/raw/evals/running-in-ci.mdx +2 -4
  136. package/.docs/raw/getting-started/{installation.mdx → manual-install.mdx} +6 -80
  137. package/.docs/raw/getting-started/mcp-docs-server.mdx +63 -6
  138. package/.docs/raw/getting-started/project-structure.mdx +2 -2
  139. package/.docs/raw/getting-started/start.mdx +72 -0
  140. package/.docs/raw/getting-started/studio.mdx +32 -7
  141. package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +147 -0
  142. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +627 -0
  143. package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +71 -19
  144. package/.docs/raw/guides/build-your-ui/copilotkit.mdx +206 -0
  145. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +24 -26
  146. package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +4 -5
  147. package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +26 -25
  148. package/.docs/raw/guides/getting-started/quickstart.mdx +97 -0
  149. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +24 -26
  150. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
  151. package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
  152. package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
  153. package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
  154. package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
  155. package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
  156. package/.docs/raw/guides/guide/web-search.mdx +12 -10
  157. package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
  158. package/.docs/raw/guides/index.mdx +3 -35
  159. package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
  160. package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +119 -0
  161. package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +121 -1
  162. package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +42 -2
  163. package/.docs/raw/guides/migrations/upgrade-to-v1/evals.mdx +31 -1
  164. package/.docs/raw/guides/migrations/upgrade-to-v1/mastra.mdx +27 -3
  165. package/.docs/raw/guides/migrations/upgrade-to-v1/mcp.mdx +1 -1
  166. package/.docs/raw/guides/migrations/upgrade-to-v1/memory.mdx +28 -0
  167. package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +25 -3
  168. package/.docs/raw/guides/migrations/upgrade-to-v1/storage.mdx +80 -0
  169. package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +68 -3
  170. package/.docs/raw/guides/migrations/upgrade-to-v1/vectors.mdx +25 -1
  171. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +174 -1
  172. package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
  173. package/.docs/raw/index.mdx +3 -3
  174. package/.docs/raw/mcp/overview.mdx +358 -0
  175. package/.docs/raw/mcp/publishing-mcp-server.mdx +139 -0
  176. package/.docs/raw/memory/conversation-history.mdx +1 -1
  177. package/.docs/raw/memory/memory-processors.mdx +265 -80
  178. package/.docs/raw/memory/overview.mdx +2 -2
  179. package/.docs/raw/memory/semantic-recall.mdx +9 -9
  180. package/.docs/raw/memory/storage/memory-with-libsql.mdx +3 -8
  181. package/.docs/raw/memory/storage/memory-with-mongodb.mdx +150 -0
  182. package/.docs/raw/memory/storage/memory-with-pg.mdx +3 -8
  183. package/.docs/raw/memory/storage/memory-with-upstash.mdx +3 -8
  184. package/.docs/raw/memory/threads-and-resources.mdx +4 -4
  185. package/.docs/raw/memory/working-memory.mdx +16 -8
  186. package/.docs/raw/{logging.mdx → observability/logging.mdx} +7 -7
  187. package/.docs/raw/observability/overview.mdx +3 -4
  188. package/.docs/raw/observability/tracing/bridges/otel.mdx +200 -0
  189. package/.docs/raw/observability/tracing/exporters/arize.mdx +37 -1
  190. package/.docs/raw/observability/tracing/exporters/braintrust.mdx +20 -1
  191. package/.docs/raw/observability/tracing/exporters/cloud.mdx +2 -2
  192. package/.docs/raw/observability/tracing/exporters/default.mdx +1 -1
  193. package/.docs/raw/observability/tracing/exporters/langfuse.mdx +84 -1
  194. package/.docs/raw/observability/tracing/exporters/langsmith.mdx +13 -1
  195. package/.docs/raw/observability/tracing/exporters/otel.mdx +123 -25
  196. package/.docs/raw/observability/tracing/exporters/posthog.mdx +127 -0
  197. package/.docs/raw/observability/tracing/overview.mdx +80 -9
  198. package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +1 -2
  199. package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
  200. package/.docs/raw/rag/overview.mdx +4 -3
  201. package/.docs/raw/rag/retrieval.mdx +44 -39
  202. package/.docs/raw/rag/vector-databases.mdx +94 -3
  203. package/.docs/raw/reference/agents/agent.mdx +19 -16
  204. package/.docs/raw/reference/agents/generate.mdx +67 -99
  205. package/.docs/raw/reference/agents/generateLegacy.mdx +3 -3
  206. package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
  207. package/.docs/raw/reference/agents/getDefaultOptions.mdx +1 -1
  208. package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
  209. package/.docs/raw/reference/agents/getDescription.mdx +1 -1
  210. package/.docs/raw/reference/agents/getInstructions.mdx +1 -1
  211. package/.docs/raw/reference/agents/getLLM.mdx +2 -2
  212. package/.docs/raw/reference/agents/getMemory.mdx +1 -1
  213. package/.docs/raw/reference/agents/getModel.mdx +1 -1
  214. package/.docs/raw/reference/agents/getTools.mdx +69 -0
  215. package/.docs/raw/reference/agents/getVoice.mdx +1 -1
  216. package/.docs/raw/reference/agents/listAgents.mdx +1 -1
  217. package/.docs/raw/reference/agents/listScorers.mdx +1 -1
  218. package/.docs/raw/reference/agents/listTools.mdx +2 -2
  219. package/.docs/raw/reference/agents/listWorkflows.mdx +1 -1
  220. package/.docs/raw/reference/agents/network.mdx +33 -72
  221. package/.docs/raw/reference/ai-sdk/chat-route.mdx +127 -0
  222. package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +117 -0
  223. package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +64 -0
  224. package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +116 -0
  225. package/.docs/raw/reference/ai-sdk/network-route.mdx +99 -0
  226. package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +289 -0
  227. package/.docs/raw/reference/ai-sdk/with-mastra.mdx +119 -0
  228. package/.docs/raw/reference/ai-sdk/workflow-route.mdx +110 -0
  229. package/.docs/raw/reference/auth/auth0.mdx +1 -1
  230. package/.docs/raw/reference/auth/clerk.mdx +1 -1
  231. package/.docs/raw/reference/auth/firebase.mdx +1 -1
  232. package/.docs/raw/reference/auth/jwt.mdx +1 -1
  233. package/.docs/raw/reference/auth/supabase.mdx +1 -1
  234. package/.docs/raw/reference/auth/workos.mdx +1 -1
  235. package/.docs/raw/reference/cli/create-mastra.mdx +1 -1
  236. package/.docs/raw/reference/cli/mastra.mdx +19 -6
  237. package/.docs/raw/reference/client-js/agents.mdx +252 -68
  238. package/.docs/raw/reference/client-js/error-handling.mdx +1 -1
  239. package/.docs/raw/reference/client-js/logs.mdx +1 -1
  240. package/.docs/raw/reference/client-js/mastra-client.mdx +4 -4
  241. package/.docs/raw/reference/client-js/memory.mdx +48 -2
  242. package/.docs/raw/reference/client-js/observability.mdx +1 -1
  243. package/.docs/raw/reference/client-js/telemetry.mdx +1 -1
  244. package/.docs/raw/reference/client-js/tools.mdx +1 -1
  245. package/.docs/raw/reference/client-js/vectors.mdx +1 -1
  246. package/.docs/raw/reference/client-js/workflows.mdx +93 -64
  247. package/.docs/raw/reference/core/addGateway.mdx +59 -0
  248. package/.docs/raw/reference/core/getAgent.mdx +1 -1
  249. package/.docs/raw/reference/core/getAgentById.mdx +1 -1
  250. package/.docs/raw/reference/core/getDeployer.mdx +1 -1
  251. package/.docs/raw/reference/core/getGateway.mdx +59 -0
  252. package/.docs/raw/reference/core/getGatewayById.mdx +62 -0
  253. package/.docs/raw/reference/core/getLogger.mdx +2 -2
  254. package/.docs/raw/reference/core/getMCPServer.mdx +2 -2
  255. package/.docs/raw/reference/core/getMCPServerById.mdx +2 -2
  256. package/.docs/raw/reference/core/getMemory.mdx +73 -0
  257. package/.docs/raw/reference/core/getScorer.mdx +1 -1
  258. package/.docs/raw/reference/core/getScorerById.mdx +1 -1
  259. package/.docs/raw/reference/core/getServer.mdx +3 -3
  260. package/.docs/raw/reference/core/getStorage.mdx +1 -1
  261. package/.docs/raw/reference/core/getStoredAgentById.mdx +183 -0
  262. package/.docs/raw/reference/core/getTelemetry.mdx +1 -1
  263. package/.docs/raw/reference/core/getVector.mdx +1 -1
  264. package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
  265. package/.docs/raw/reference/core/listAgents.mdx +1 -1
  266. package/.docs/raw/reference/core/listGateways.mdx +53 -0
  267. package/.docs/raw/reference/core/listLogs.mdx +2 -2
  268. package/.docs/raw/reference/core/listLogsByRunId.mdx +2 -2
  269. package/.docs/raw/reference/core/listMCPServers.mdx +2 -2
  270. package/.docs/raw/reference/core/listMemory.mdx +70 -0
  271. package/.docs/raw/reference/core/listScorers.mdx +1 -1
  272. package/.docs/raw/reference/core/listStoredAgents.mdx +151 -0
  273. package/.docs/raw/reference/core/listVectors.mdx +1 -1
  274. package/.docs/raw/reference/core/listWorkflows.mdx +1 -1
  275. package/.docs/raw/reference/core/mastra-class.mdx +17 -1
  276. package/.docs/raw/reference/core/mastra-model-gateway.mdx +227 -0
  277. package/.docs/raw/reference/core/setLogger.mdx +2 -2
  278. package/.docs/raw/reference/core/setStorage.mdx +1 -1
  279. package/.docs/raw/reference/core/setTelemetry.mdx +2 -2
  280. package/.docs/raw/reference/deployer/cloudflare.mdx +1 -1
  281. package/.docs/raw/reference/deployer/deployer.mdx +1 -1
  282. package/.docs/raw/reference/deployer/netlify.mdx +2 -3
  283. package/.docs/raw/reference/deployer/vercel.mdx +1 -1
  284. package/.docs/raw/reference/evals/answer-relevancy.mdx +29 -99
  285. package/.docs/raw/reference/evals/answer-similarity.mdx +13 -259
  286. package/.docs/raw/reference/evals/bias.mdx +30 -88
  287. package/.docs/raw/reference/evals/completeness.mdx +32 -91
  288. package/.docs/raw/reference/evals/content-similarity.mdx +29 -89
  289. package/.docs/raw/reference/evals/context-precision.mdx +29 -131
  290. package/.docs/raw/reference/evals/context-relevance.mdx +12 -12
  291. package/.docs/raw/reference/evals/create-scorer.mdx +1 -1
  292. package/.docs/raw/reference/evals/faithfulness.mdx +29 -102
  293. package/.docs/raw/reference/evals/hallucination.mdx +29 -104
  294. package/.docs/raw/reference/evals/keyword-coverage.mdx +29 -108
  295. package/.docs/raw/reference/evals/mastra-scorer.mdx +1 -1
  296. package/.docs/raw/reference/evals/noise-sensitivity.mdx +12 -12
  297. package/.docs/raw/reference/evals/prompt-alignment.mdx +16 -16
  298. package/.docs/raw/reference/evals/run-evals.mdx +1 -1
  299. package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
  300. package/.docs/raw/reference/evals/textual-difference.mdx +28 -101
  301. package/.docs/raw/reference/evals/tone-consistency.mdx +26 -99
  302. package/.docs/raw/reference/evals/tool-call-accuracy.mdx +8 -8
  303. package/.docs/raw/reference/evals/toxicity.mdx +30 -93
  304. package/.docs/raw/reference/index.mdx +1 -0
  305. package/.docs/raw/reference/logging/pino-logger.mdx +2 -2
  306. package/.docs/raw/reference/memory/createThread.mdx +1 -1
  307. package/.docs/raw/reference/memory/deleteMessages.mdx +1 -1
  308. package/.docs/raw/reference/memory/getThreadById.mdx +1 -1
  309. package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +1 -1
  310. package/.docs/raw/reference/memory/memory-class.mdx +6 -8
  311. package/.docs/raw/reference/memory/query.mdx +1 -1
  312. package/.docs/raw/reference/memory/recall.mdx +1 -1
  313. package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +177 -0
  314. package/.docs/raw/reference/observability/tracing/configuration.mdx +1 -5
  315. package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +30 -1
  316. package/.docs/raw/reference/observability/tracing/exporters/braintrust.mdx +1 -1
  317. package/.docs/raw/reference/observability/tracing/exporters/cloud-exporter.mdx +1 -1
  318. package/.docs/raw/reference/observability/tracing/exporters/console-exporter.mdx +1 -1
  319. package/.docs/raw/reference/observability/tracing/exporters/default-exporter.mdx +1 -1
  320. package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +44 -1
  321. package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +18 -2
  322. package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +34 -44
  323. package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
  324. package/.docs/raw/reference/observability/tracing/instances.mdx +1 -5
  325. package/.docs/raw/reference/observability/tracing/interfaces.mdx +30 -5
  326. package/.docs/raw/reference/observability/tracing/processors/sensitive-data-filter.mdx +1 -1
  327. package/.docs/raw/reference/observability/tracing/spans.mdx +1 -5
  328. package/.docs/raw/reference/processors/batch-parts-processor.mdx +2 -2
  329. package/.docs/raw/reference/processors/language-detector.mdx +11 -4
  330. package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
  331. package/.docs/raw/reference/processors/moderation-processor.mdx +13 -6
  332. package/.docs/raw/reference/processors/pii-detector.mdx +13 -6
  333. package/.docs/raw/reference/processors/processor-interface.mdx +803 -0
  334. package/.docs/raw/reference/processors/prompt-injection-detector.mdx +11 -4
  335. package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
  336. package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +4 -5
  337. package/.docs/raw/reference/processors/token-limiter-processor.mdx +3 -3
  338. package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
  339. package/.docs/raw/reference/processors/unicode-normalizer.mdx +2 -2
  340. package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
  341. package/.docs/raw/reference/rag/chunk.mdx +1 -1
  342. package/.docs/raw/reference/rag/database-config.mdx +1 -1
  343. package/.docs/raw/reference/rag/document.mdx +1 -1
  344. package/.docs/raw/reference/rag/embeddings.mdx +6 -6
  345. package/.docs/raw/reference/rag/extract-params.mdx +1 -1
  346. package/.docs/raw/reference/rag/graph-rag.mdx +1 -1
  347. package/.docs/raw/reference/rag/metadata-filters.mdx +1 -1
  348. package/.docs/raw/reference/rag/rerank.mdx +2 -3
  349. package/.docs/raw/reference/rag/rerankWithScorer.mdx +1 -2
  350. package/.docs/raw/reference/server/create-route.mdx +328 -0
  351. package/.docs/raw/reference/server/express-adapter.mdx +260 -0
  352. package/.docs/raw/reference/server/hono-adapter.mdx +242 -0
  353. package/.docs/raw/reference/server/mastra-server.mdx +345 -0
  354. package/.docs/raw/reference/server/routes.mdx +250 -0
  355. package/.docs/raw/reference/storage/cloudflare-d1.mdx +38 -1
  356. package/.docs/raw/reference/storage/cloudflare.mdx +1 -1
  357. package/.docs/raw/reference/storage/convex.mdx +164 -0
  358. package/.docs/raw/reference/storage/dynamodb.mdx +1 -1
  359. package/.docs/raw/reference/storage/lance.mdx +34 -1
  360. package/.docs/raw/reference/storage/libsql.mdx +38 -1
  361. package/.docs/raw/reference/storage/mongodb.mdx +40 -1
  362. package/.docs/raw/reference/storage/mssql.mdx +38 -1
  363. package/.docs/raw/reference/storage/postgresql.mdx +38 -1
  364. package/.docs/raw/reference/storage/upstash.mdx +1 -1
  365. package/.docs/raw/reference/streaming/ChunkType.mdx +25 -4
  366. package/.docs/raw/reference/streaming/agents/MastraModelOutput.mdx +1 -1
  367. package/.docs/raw/reference/streaming/agents/stream.mdx +84 -124
  368. package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +1 -1
  369. package/.docs/raw/reference/streaming/workflows/observeStream.mdx +8 -10
  370. package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
  371. package/.docs/raw/reference/streaming/workflows/stream.mdx +84 -25
  372. package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
  373. package/.docs/raw/reference/templates/overview.mdx +2 -5
  374. package/.docs/raw/reference/tools/client.mdx +2 -3
  375. package/.docs/raw/reference/tools/create-tool.mdx +135 -4
  376. package/.docs/raw/reference/tools/document-chunker-tool.mdx +1 -1
  377. package/.docs/raw/reference/tools/graph-rag-tool.mdx +7 -7
  378. package/.docs/raw/reference/tools/mcp-client.mdx +131 -23
  379. package/.docs/raw/reference/tools/mcp-server.mdx +56 -8
  380. package/.docs/raw/reference/tools/vector-query-tool.mdx +16 -17
  381. package/.docs/raw/reference/vectors/astra.mdx +1 -1
  382. package/.docs/raw/reference/vectors/chroma.mdx +82 -2
  383. package/.docs/raw/reference/vectors/convex.mdx +429 -0
  384. package/.docs/raw/reference/vectors/couchbase.mdx +25 -18
  385. package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
  386. package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
  387. package/.docs/raw/reference/vectors/lance.mdx +39 -23
  388. package/.docs/raw/reference/vectors/libsql.mdx +36 -3
  389. package/.docs/raw/reference/vectors/mongodb.mdx +36 -3
  390. package/.docs/raw/reference/vectors/opensearch.mdx +38 -17
  391. package/.docs/raw/reference/vectors/pg.mdx +44 -37
  392. package/.docs/raw/reference/vectors/pinecone.mdx +70 -3
  393. package/.docs/raw/reference/vectors/qdrant.mdx +37 -2
  394. package/.docs/raw/reference/vectors/s3vectors.mdx +1 -1
  395. package/.docs/raw/reference/vectors/turbopuffer.mdx +75 -1
  396. package/.docs/raw/reference/vectors/upstash.mdx +1 -1
  397. package/.docs/raw/reference/vectors/vectorize.mdx +1 -1
  398. package/.docs/raw/reference/voice/azure.mdx +96 -81
  399. package/.docs/raw/reference/voice/cloudflare.mdx +1 -1
  400. package/.docs/raw/reference/voice/composite-voice.mdx +72 -29
  401. package/.docs/raw/reference/voice/deepgram.mdx +1 -1
  402. package/.docs/raw/reference/voice/elevenlabs.mdx +1 -1
  403. package/.docs/raw/reference/voice/google-gemini-live.mdx +1 -1
  404. package/.docs/raw/reference/voice/google.mdx +160 -21
  405. package/.docs/raw/reference/voice/mastra-voice.mdx +1 -1
  406. package/.docs/raw/reference/voice/murf.mdx +1 -1
  407. package/.docs/raw/reference/voice/openai-realtime.mdx +3 -3
  408. package/.docs/raw/reference/voice/openai.mdx +1 -1
  409. package/.docs/raw/reference/voice/playai.mdx +1 -1
  410. package/.docs/raw/reference/voice/sarvam.mdx +1 -1
  411. package/.docs/raw/reference/voice/speechify.mdx +1 -1
  412. package/.docs/raw/reference/voice/voice.addInstructions.mdx +3 -4
  413. package/.docs/raw/reference/voice/voice.addTools.mdx +2 -2
  414. package/.docs/raw/reference/voice/voice.answer.mdx +2 -2
  415. package/.docs/raw/reference/voice/voice.close.mdx +2 -2
  416. package/.docs/raw/reference/voice/voice.connect.mdx +2 -2
  417. package/.docs/raw/reference/voice/voice.events.mdx +1 -1
  418. package/.docs/raw/reference/voice/voice.getSpeakers.mdx +1 -1
  419. package/.docs/raw/reference/voice/voice.listen.mdx +87 -53
  420. package/.docs/raw/reference/voice/voice.off.mdx +2 -2
  421. package/.docs/raw/reference/voice/voice.on.mdx +2 -2
  422. package/.docs/raw/reference/voice/voice.send.mdx +2 -2
  423. package/.docs/raw/reference/voice/voice.speak.mdx +76 -41
  424. package/.docs/raw/reference/voice/voice.updateConfig.mdx +2 -2
  425. package/.docs/raw/reference/workflows/run-methods/cancel.mdx +1 -1
  426. package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
  427. package/.docs/raw/reference/workflows/run-methods/resume.mdx +45 -1
  428. package/.docs/raw/reference/workflows/run-methods/start.mdx +48 -4
  429. package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
  430. package/.docs/raw/reference/workflows/run.mdx +28 -6
  431. package/.docs/raw/reference/workflows/step.mdx +65 -1
  432. package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +1 -1
  433. package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
  434. package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +1 -1
  435. package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
  436. package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
  437. package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +69 -4
  438. package/.docs/raw/reference/workflows/workflow-methods/map.mdx +1 -1
  439. package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
  440. package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +1 -1
  441. package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +1 -1
  442. package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +1 -1
  443. package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
  444. package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +1 -1
  445. package/.docs/raw/reference/workflows/workflow.mdx +44 -2
  446. package/.docs/raw/server-db/custom-adapters.mdx +386 -0
  447. package/.docs/raw/server-db/custom-api-routes.mdx +6 -6
  448. package/.docs/raw/server-db/mastra-client.mdx +3 -4
  449. package/.docs/raw/server-db/{production-server.mdx → mastra-server.mdx} +22 -12
  450. package/.docs/raw/server-db/middleware.mdx +31 -31
  451. package/.docs/raw/server-db/request-context.mdx +3 -4
  452. package/.docs/raw/server-db/server-adapters.mdx +312 -0
  453. package/.docs/raw/server-db/storage.mdx +12 -1
  454. package/.docs/raw/streaming/events.mdx +1 -1
  455. package/.docs/raw/streaming/overview.mdx +27 -16
  456. package/.docs/raw/streaming/tool-streaming.mdx +58 -19
  457. package/.docs/raw/streaming/workflow-streaming.mdx +6 -12
  458. package/.docs/raw/tools-mcp/advanced-usage.mdx +2 -3
  459. package/.docs/raw/tools-mcp/mcp-overview.mdx +4 -6
  460. package/.docs/raw/tools-mcp/overview.mdx +1 -1
  461. package/.docs/raw/voice/overview.mdx +88 -41
  462. package/.docs/raw/voice/speech-to-speech.mdx +5 -5
  463. package/.docs/raw/voice/speech-to-text.mdx +2 -3
  464. package/.docs/raw/voice/text-to-speech.mdx +2 -3
  465. package/.docs/raw/workflows/agents-and-tools.mdx +43 -5
  466. package/.docs/raw/workflows/control-flow.mdx +534 -3
  467. package/.docs/raw/workflows/error-handling.mdx +5 -4
  468. package/.docs/raw/workflows/human-in-the-loop.mdx +160 -213
  469. package/.docs/raw/workflows/inngest-workflow.mdx +1 -1
  470. package/.docs/raw/workflows/input-data-mapping.mdx +1 -1
  471. package/.docs/raw/workflows/overview.mdx +67 -47
  472. package/.docs/raw/workflows/snapshots.mdx +5 -3
  473. package/.docs/raw/workflows/suspend-and-resume.mdx +121 -204
  474. package/.docs/raw/workflows/time-travel.mdx +313 -0
  475. package/.docs/raw/workflows/workflow-state.mdx +190 -0
  476. package/CHANGELOG.md +88 -0
  477. package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.js} +24 -4
  478. package/dist/prepare-docs/package-changes.d.ts.map +1 -1
  479. package/dist/prepare-docs/prepare.js +1 -1
  480. package/dist/stdio.js +17 -19
  481. package/package.json +10 -14
  482. package/.docs/raw/deployment/serverless-platforms/index.mdx +0 -58
  483. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +0 -688
  484. package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -123
  485. package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +0 -382
  486. package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
  487. package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
  488. package/.docs/raw/getting-started/templates.mdx +0 -73
  489. package/.docs/raw/mastra-cloud/observability.mdx +0 -51
  490. package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
  491. package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: "Control Flow | Workflows | Mastra Docs"
2
+ title: "Control Flow | Workflows"
3
3
  description: "Control flow in Mastra workflows allows you to manage branching, merging, and conditions to construct workflows that meet your logic requirements."
4
4
  ---
5
5
 
@@ -59,7 +59,7 @@ export const testWorkflow = createWorkflow({
59
59
 
60
60
  ## Simultaneous steps with `.parallel()`
61
61
 
62
- Use `.parallel()` to run steps at the same time. Each step's `id` is used when defining a following step's `inputSchema` and becomes the key on the `inputData` object used to access the previous step's values. The outputs of parallel steps can then be referenced or combined by a following step.
62
+ Use `.parallel()` to run steps at the same time. All parallel steps must complete before the workflow continues to the next step. Each step's `id` is used when defining a following step's `inputSchema` and becomes the key on the `inputData` object used to access the previous step's values. The outputs of parallel steps can then be referenced or combined by a following step.
63
63
 
64
64
  ![Concurrent steps with .parallel()](/img/workflows/workflows-control-flow-parallel.jpg)
65
65
 
@@ -112,6 +112,72 @@ export const testWorkflow = createWorkflow({
112
112
 
113
113
  > 📹 Watch: How to run steps in parallel and optimize your Mastra workflow → [YouTube (3 minutes)](https://youtu.be/GQJxve5Hki4)
114
114
 
115
+ ### Output structure
116
+
117
+ When steps run in parallel, the output is an object where each key is the step's `id` and the value is that step's output. This allows you to access each parallel step's result independently.
118
+
119
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
120
+ const step1 = createStep({
121
+ id: "format-step",
122
+ inputSchema: z.object({ message: z.string() }),
123
+ outputSchema: z.object({ formatted: z.string() }),
124
+ execute: async ({ inputData }) => ({
125
+ formatted: inputData.message.toUpperCase()
126
+ })
127
+ });
128
+
129
+ const step2 = createStep({
130
+ id: "count-step",
131
+ inputSchema: z.object({ message: z.string() }),
132
+ outputSchema: z.object({ count: z.number() }),
133
+ execute: async ({ inputData }) => ({
134
+ count: inputData.message.length
135
+ })
136
+ });
137
+
138
+ const step3 = createStep({
139
+ id: "combine-step",
140
+ // The inputSchema must match the structure of parallel outputs
141
+ inputSchema: z.object({
142
+ "format-step": z.object({ formatted: z.string() }),
143
+ "count-step": z.object({ count: z.number() })
144
+ }),
145
+ outputSchema: z.object({ result: z.string() }),
146
+ execute: async ({ inputData }) => {
147
+ // Access each parallel step's output by its id
148
+ const formatted = inputData["format-step"].formatted;
149
+ const count = inputData["count-step"].count;
150
+ return {
151
+ result: `${formatted} (${count} characters)`
152
+ };
153
+ }
154
+ });
155
+
156
+ export const testWorkflow = createWorkflow({
157
+ id: "parallel-output-example",
158
+ inputSchema: z.object({ message: z.string() }),
159
+ outputSchema: z.object({ result: z.string() })
160
+ })
161
+ .parallel([step1, step2])
162
+ .then(step3)
163
+ .commit();
164
+
165
+ // When executed with { message: "hello" }
166
+ // The parallel output structure will be:
167
+ // {
168
+ // "format-step": { formatted: "HELLO" },
169
+ // "count-step": { count: 5 }
170
+ // }
171
+ ```
172
+
173
+ **Key points:**
174
+ - Each parallel step's output is keyed by its `id`
175
+ - All parallel steps execute simultaneously
176
+ - The next step receives an object containing all parallel step outputs
177
+ - You must define the `inputSchema` of the following step to match this structure
178
+
179
+ > See [Choosing the right pattern](#choosing-the-right-pattern) to understand when to use `.parallel()` vs `.foreach()`.
180
+
115
181
  ## Conditional logic with `.branch()`
116
182
 
117
183
  Use `.branch()` to choose which step to run based on a condition. All steps in a branch need the same `inputSchema` and `outputSchema` because branching requires consistent schemas so workflows can follow different paths.
@@ -158,6 +224,85 @@ export const testWorkflow = createWorkflow({
158
224
  .commit();
159
225
  ```
160
226
 
227
+ ### Output structure
228
+
229
+ When using conditional branching, only one branch executes based on which condition evaluates to `true` first. The output structure is similar to `.parallel()`, where the result is keyed by the executed step's `id`.
230
+
231
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
232
+ const step1 = createStep({
233
+ id: "initial-step",
234
+ inputSchema: z.object({ value: z.number() }),
235
+ outputSchema: z.object({ value: z.number() }),
236
+ execute: async ({ inputData }) => inputData
237
+ });
238
+
239
+ const highValueStep = createStep({
240
+ id: "high-value-step",
241
+ inputSchema: z.object({ value: z.number() }),
242
+ outputSchema: z.object({ result: z.string() }),
243
+ execute: async ({ inputData }) => ({
244
+ result: `High value: ${inputData.value}`
245
+ })
246
+ });
247
+
248
+ const lowValueStep = createStep({
249
+ id: "low-value-step",
250
+ inputSchema: z.object({ value: z.number() }),
251
+ outputSchema: z.object({ result: z.string() }),
252
+ execute: async ({ inputData }) => ({
253
+ result: `Low value: ${inputData.value}`
254
+ })
255
+ });
256
+
257
+ const finalStep = createStep({
258
+ id: "final-step",
259
+ // The inputSchema must account for either branch's output
260
+ inputSchema: z.object({
261
+ "high-value-step": z.object({ result: z.string() }).optional(),
262
+ "low-value-step": z.object({ result: z.string() }).optional()
263
+ }),
264
+ outputSchema: z.object({ message: z.string() }),
265
+ execute: async ({ inputData }) => {
266
+ // Only one branch will have executed
267
+ const result = inputData["high-value-step"]?.result ||
268
+ inputData["low-value-step"]?.result;
269
+ return { message: result };
270
+ }
271
+ });
272
+
273
+ export const testWorkflow = createWorkflow({
274
+ id: "branch-output-example",
275
+ inputSchema: z.object({ value: z.number() }),
276
+ outputSchema: z.object({ message: z.string() })
277
+ })
278
+ .then(step1)
279
+ .branch([
280
+ [async ({ inputData }) => inputData.value > 10, highValueStep],
281
+ [async ({ inputData }) => inputData.value <= 10, lowValueStep]
282
+ ])
283
+ .then(finalStep)
284
+ .commit();
285
+
286
+ // When executed with { value: 15 }
287
+ // Only the high-value-step executes, output structure:
288
+ // {
289
+ // "high-value-step": { result: "High value: 15" }
290
+ // }
291
+
292
+ // When executed with { value: 5 }
293
+ // Only the low-value-step executes, output structure:
294
+ // {
295
+ // "low-value-step": { result: "Low value: 5" }
296
+ // }
297
+ ```
298
+
299
+ **Key points:**
300
+ - Only one branch executes based on condition evaluation order
301
+ - The output is keyed by the executed step's `id`
302
+ - Subsequent steps should handle all possible branch outputs
303
+ - Use optional fields in the `inputSchema` when the next step needs to handle multiple possible branches
304
+ - Conditions are evaluated in the order they're defined
305
+
161
306
  ## Input data mapping
162
307
 
163
308
  When using `.then()`, `.parallel()`, or `.branch()`, it is sometimes necessary to transform the output of a previous step to match the input of the next. In these cases you can use `.map()` to access the `inputData` and transform it to create a suitable data shape for the next step.
@@ -188,6 +333,43 @@ The `.map()` method provides additional helper functions for more complex mappin
188
333
  - [`getInitData()`](/reference/v1/workflows/workflow-methods/map#using-getinitdata): Access the workflow's initial input data
189
334
  - [`mapVariable()`](/reference/v1/workflows/workflow-methods/map#using-mapvariable): Use declarative object syntax to extract and rename fields
190
335
 
336
+ ### Parallel and Branch outputs
337
+
338
+ When working with `.parallel()` or `.branch()` outputs, you can use `.map()` to transform the data structure before passing it to the next step. This is especially useful when you need to flatten or restructure the output.
339
+
340
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
341
+ export const testWorkflow = createWorkflow({...})
342
+ .parallel([step1, step2])
343
+ .map(async ({ inputData }) => {
344
+ // Transform the parallel output structure
345
+ return {
346
+ combined: `${inputData["step1"].value} - ${inputData["step2"].value}`
347
+ };
348
+ })
349
+ .then(nextStep)
350
+ .commit();
351
+ ```
352
+
353
+ You can also use the helper functions provided by `.map()`:
354
+
355
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
356
+ export const testWorkflow = createWorkflow({...})
357
+ .branch([
358
+ [condition1, stepA],
359
+ [condition2, stepB]
360
+ ])
361
+ .map(async ({ inputData, getStepResult }) => {
362
+ // Access specific step results
363
+ const stepAResult = getStepResult("stepA");
364
+ const stepBResult = getStepResult("stepB");
365
+
366
+ // Return the result from whichever branch executed
367
+ return stepAResult || stepBResult;
368
+ })
369
+ .then(nextStep)
370
+ .commit();
371
+ ```
372
+
191
373
  ## Looping steps
192
374
 
193
375
  Workflows support different looping methods that let you repeat steps until or while a condition is met, or iterate over arrays. Loops can be combined with other control methods like `.then()`.
@@ -248,7 +430,7 @@ export const testWorkflow = createWorkflow({
248
430
 
249
431
  ### Looping with `.foreach()`
250
432
 
251
- Use `.foreach()` to run the same step for each item in an array. The input must be of type `array` so the loop can iterate over its values, applying the steps logic to each one.
433
+ Use `.foreach()` to run the same step for each item in an array. The input must be of type `array` so the loop can iterate over its values, applying the step's logic to each one. See [Choosing the right pattern](#choosing-the-right-pattern) for guidance on when to use `.foreach()` vs other methods.
252
434
 
253
435
  ![Repeating with .foreach()](/img/workflows/workflows-control-flow-foreach.jpg)
254
436
 
@@ -274,6 +456,32 @@ export const testWorkflow = createWorkflow({
274
456
  .commit();
275
457
  ```
276
458
 
459
+ #### Output structure
460
+
461
+ The `.foreach()` method always returns an array containing the output of each iteration. The order of outputs matches the order of inputs.
462
+
463
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
464
+ const addTenStep = createStep({
465
+ id: "add-ten",
466
+ inputSchema: z.object({ value: z.number() }),
467
+ outputSchema: z.object({ value: z.number() }),
468
+ execute: async ({ inputData }) => ({
469
+ value: inputData.value + 10
470
+ })
471
+ });
472
+
473
+ export const testWorkflow = createWorkflow({
474
+ id: "foreach-output-example",
475
+ inputSchema: z.array(z.object({ value: z.number() })),
476
+ outputSchema: z.array(z.object({ value: z.number() }))
477
+ })
478
+ .foreach(addTenStep)
479
+ .commit();
480
+
481
+ // When executed with [{ value: 1 }, { value: 22 }, { value: 333 }]
482
+ // Output: [{ value: 11 }, { value: 32 }, { value: 343 }]
483
+ ```
484
+
277
485
  #### Concurrency limits
278
486
 
279
487
  Use `concurrency` to control the number of array items processed at the same time. The default is `1`, which runs steps sequentially. Increasing the value allows `.foreach()` to process multiple items simultaneously.
@@ -286,6 +494,324 @@ export const testWorkflow = createWorkflow({...})
286
494
  .commit();
287
495
  ```
288
496
 
497
+ #### Aggregating results after `.foreach()`
498
+
499
+ Since `.foreach()` outputs an array, you can use `.then()` or `.map()` to aggregate or transform the results. The step following `.foreach()` receives the entire array as its input.
500
+
501
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
502
+ const processItemStep = createStep({
503
+ id: "process-item",
504
+ inputSchema: z.object({ value: z.number() }),
505
+ outputSchema: z.object({ processed: z.number() }),
506
+ execute: async ({ inputData }) => ({
507
+ processed: inputData.value * 2
508
+ })
509
+ });
510
+
511
+ const aggregateStep = createStep({
512
+ id: "aggregate",
513
+ // Input is an array of outputs from foreach
514
+ inputSchema: z.array(z.object({ processed: z.number() })),
515
+ outputSchema: z.object({ total: z.number() }),
516
+ execute: async ({ inputData }) => ({
517
+ // Sum all processed values
518
+ total: inputData.reduce((sum, item) => sum + item.processed, 0)
519
+ })
520
+ });
521
+
522
+ export const testWorkflow = createWorkflow({
523
+ id: "foreach-aggregate-example",
524
+ inputSchema: z.array(z.object({ value: z.number() })),
525
+ outputSchema: z.object({ total: z.number() })
526
+ })
527
+ .foreach(processItemStep)
528
+ .then(aggregateStep) // Receives the full array from foreach
529
+ .commit();
530
+
531
+ // When executed with [{ value: 1 }, { value: 2 }, { value: 3 }]
532
+ // After foreach: [{ processed: 2 }, { processed: 4 }, { processed: 6 }]
533
+ // After aggregate: { total: 12 }
534
+ ```
535
+
536
+ You can also use `.map()` to transform the array output:
537
+
538
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
539
+ export const testWorkflow = createWorkflow({...})
540
+ .foreach(processItemStep)
541
+ .map(async ({ inputData }) => ({
542
+ // Transform the array into a different structure
543
+ values: inputData.map(item => item.processed),
544
+ count: inputData.length
545
+ }))
546
+ .then(nextStep)
547
+ .commit();
548
+ ```
549
+
550
+ #### Chaining multiple `.foreach()` calls
551
+
552
+ When you chain `.foreach()` calls, each operates on the array output of the previous step. This is useful when each item in your array needs to be transformed by multiple steps in sequence.
553
+
554
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
555
+ const chunkStep = createStep({
556
+ id: "chunk",
557
+ // Takes a document, returns an array of chunks
558
+ inputSchema: z.object({ content: z.string() }),
559
+ outputSchema: z.array(z.object({ chunk: z.string() })),
560
+ execute: async ({ inputData }) => {
561
+ // Split document into chunks
562
+ const chunks = inputData.content.match(/.{1,100}/g) || [];
563
+ return chunks.map(chunk => ({ chunk }));
564
+ }
565
+ });
566
+
567
+ const embedStep = createStep({
568
+ id: "embed",
569
+ // Takes a single chunk, returns embedding
570
+ inputSchema: z.object({ chunk: z.string() }),
571
+ outputSchema: z.object({ embedding: z.array(z.number()) }),
572
+ execute: async ({ inputData }) => ({
573
+ embedding: [/* vector embedding */]
574
+ })
575
+ });
576
+
577
+ // For a single document that produces multiple chunks:
578
+ export const singleDocWorkflow = createWorkflow({
579
+ id: "single-doc-rag",
580
+ inputSchema: z.object({ content: z.string() }),
581
+ outputSchema: z.array(z.object({ embedding: z.array(z.number()) }))
582
+ })
583
+ .then(chunkStep) // Returns array of chunks
584
+ .foreach(embedStep) // Process each chunk -> array of embeddings
585
+ .commit();
586
+ ```
587
+
588
+ For processing multiple documents where each produces multiple chunks, you have options:
589
+
590
+ **Option 1: Process all documents in a single step with batching control**
591
+
592
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
593
+ const downloadAndChunkStep = createStep({
594
+ id: "download-and-chunk",
595
+ inputSchema: z.array(z.string()), // Array of URLs
596
+ outputSchema: z.array(z.object({ chunk: z.string(), source: z.string() })),
597
+ execute: async ({ inputData: urls }) => {
598
+ // Control batching/parallelization within the step
599
+ const allChunks = [];
600
+ for (const url of urls) {
601
+ const content = await fetch(url).then(r => r.text());
602
+ const chunks = content.match(/.{1,100}/g) || [];
603
+ allChunks.push(...chunks.map(chunk => ({ chunk, source: url })));
604
+ }
605
+ return allChunks;
606
+ }
607
+ });
608
+
609
+ export const multiDocWorkflow = createWorkflow({...})
610
+ .then(downloadAndChunkStep) // Returns flat array of all chunks
611
+ .foreach(embedStep, { concurrency: 10 }) // Embed each chunk in parallel
612
+ .commit();
613
+ ```
614
+
615
+ **Option 2: Use foreach for documents, aggregate chunks, then foreach for embeddings**
616
+
617
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
618
+ const downloadStep = createStep({
619
+ id: "download",
620
+ inputSchema: z.string(), // Single URL
621
+ outputSchema: z.object({ content: z.string(), source: z.string() }),
622
+ execute: async ({ inputData: url }) => ({
623
+ content: await fetch(url).then(r => r.text()),
624
+ source: url
625
+ })
626
+ });
627
+
628
+ const chunkDocStep = createStep({
629
+ id: "chunk-doc",
630
+ inputSchema: z.object({ content: z.string(), source: z.string() }),
631
+ outputSchema: z.array(z.object({ chunk: z.string(), source: z.string() })),
632
+ execute: async ({ inputData }) => {
633
+ const chunks = inputData.content.match(/.{1,100}/g) || [];
634
+ return chunks.map(chunk => ({ chunk, source: inputData.source }));
635
+ }
636
+ });
637
+
638
+ export const multiDocWorkflow = createWorkflow({
639
+ id: "multi-doc-rag",
640
+ inputSchema: z.array(z.string()), // Array of URLs
641
+ outputSchema: z.array(z.object({ embedding: z.array(z.number()) }))
642
+ })
643
+ .foreach(downloadStep, { concurrency: 5 }) // Download docs in parallel
644
+ .foreach(chunkDocStep) // Chunk each doc -> array of chunk arrays
645
+ .map(async ({ inputData }) => {
646
+ // Flatten nested arrays: [[chunks], [chunks]] -> [chunks]
647
+ return inputData.flat();
648
+ })
649
+ .foreach(embedStep, { concurrency: 10 }) // Embed all chunks
650
+ .commit();
651
+ ```
652
+
653
+ **Key points about chaining `.foreach()`:**
654
+ - Each `.foreach()` operates on the array from the previous step
655
+ - If a step inside `.foreach()` returns an array, the output becomes an array of arrays
656
+ - Use `.map()` with `.flat()` to flatten nested arrays when needed
657
+ - For complex RAG pipelines, Option 1 (handling batching in a single step) often provides better control
658
+
659
+ #### Nested workflows inside foreach
660
+
661
+ The step after `.foreach()` only executes after all iterations complete. If you need to run multiple sequential operations per item, use a nested workflow instead of chaining multiple `.foreach()` calls. This keeps all operations for each item together and makes the data flow clearer.
662
+
663
+ ```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
664
+ // Define a workflow that processes a single document
665
+ const processDocumentWorkflow = createWorkflow({
666
+ id: "process-document",
667
+ inputSchema: z.object({ url: z.string() }),
668
+ outputSchema: z.object({
669
+ embeddings: z.array(z.array(z.number())),
670
+ metadata: z.object({ url: z.string(), chunkCount: z.number() })
671
+ })
672
+ })
673
+ .then(downloadStep) // Download the document
674
+ .then(chunkStep) // Split into chunks
675
+ .then(embedChunksStep) // Embed all chunks for this document
676
+ .then(formatResultStep) // Format the final output
677
+ .commit();
678
+
679
+ // Use the nested workflow inside foreach
680
+ export const batchProcessWorkflow = createWorkflow({
681
+ id: "batch-process-documents",
682
+ inputSchema: z.array(z.object({ url: z.string() })),
683
+ outputSchema: z.array(z.object({
684
+ embeddings: z.array(z.array(z.number())),
685
+ metadata: z.object({ url: z.string(), chunkCount: z.number() })
686
+ }))
687
+ })
688
+ .foreach(processDocumentWorkflow, { concurrency: 3 })
689
+ .commit();
690
+
691
+ // Each document goes through all 4 steps before the next document starts (with concurrency: 1)
692
+ // With concurrency: 3, up to 3 documents process their full pipelines in parallel
693
+ ```
694
+
695
+ **Why use nested workflows:**
696
+ - **Better parallelism**: With `concurrency: N`, multiple items run their full pipelines simultaneously. Chained `.foreach().foreach()` processes all items through step 1, waits, then all through step 2 - nested workflows let each item progress independently
697
+ - All steps for one item complete together before results are collected
698
+ - Cleaner than multiple `.foreach()` calls which create nested arrays
699
+ - Each nested workflow execution is independent with its own data flow
700
+ - Easier to test and reuse the per-item logic separately
701
+
702
+ **How it works:**
703
+ 1. The parent workflow passes each array item to an instance of the nested workflow
704
+ 2. Each nested workflow runs its full step sequence for that item
705
+ 3. With `concurrency > 1`, multiple nested workflows execute in parallel
706
+ 4. The nested workflow's final output becomes one element in the result array
707
+ 5. After all nested workflows complete, the next step in the parent receives the full array
708
+
709
+ ## Choosing the right pattern
710
+
711
+ Use this section as a reference for selecting the appropriate control flow method.
712
+
713
+ ### Quick reference
714
+
715
+ | Method | Purpose | Input | Output | Concurrency |
716
+ |--------|---------|-------|--------|-------------|
717
+ | `.then(step)` | Sequential processing | `T` | `U` | N/A (one at a time) |
718
+ | `.parallel([a, b])` | Different operations on same input | `T` | `{ a: U, b: V }` | All run simultaneously |
719
+ | `.foreach(step)` | Same operation on each array item | `T[]` | `U[]` | Configurable (default: 1) |
720
+ | `.branch([...])` | Conditional path selection | `T` | `{ selectedStep: U }` | Only one branch runs |
721
+
722
+ ### `.parallel()` vs `.foreach()`
723
+
724
+ **Use `.parallel()` when you have one input that needs different processing:**
725
+
726
+ ```typescript
727
+ // Same user data processed differently in parallel
728
+ workflow
729
+ .parallel([validateStep, enrichStep, scoreStep])
730
+ .then(combineResultsStep)
731
+ ```
732
+
733
+ **Use `.foreach()` when you have many inputs that need the same processing:**
734
+
735
+ ```typescript
736
+ // Multiple URLs each processed the same way
737
+ workflow
738
+ .foreach(downloadStep, { concurrency: 5 })
739
+ .then(aggregateStep)
740
+ ```
741
+
742
+ ### When to use nested workflows
743
+
744
+ **Inside `.foreach()`** - when each array item needs multiple sequential steps:
745
+
746
+ ```typescript
747
+ // Each document goes through a full pipeline
748
+ const processDocWorkflow = createWorkflow({...})
749
+ .then(downloadStep)
750
+ .then(parseStep)
751
+ .then(embedStep)
752
+ .commit();
753
+
754
+ workflow.foreach(processDocWorkflow, { concurrency: 3 })
755
+ ```
756
+
757
+ This is cleaner than chaining `.foreach().foreach()`, which creates nested arrays.
758
+
759
+ **Inside `.parallel()`** - when a parallel branch needs its own multi-step pipeline:
760
+
761
+ ```typescript
762
+ const pipelineA = createWorkflow({...}).then(step1).then(step2).commit();
763
+ const pipelineB = createWorkflow({...}).then(step3).then(step4).commit();
764
+
765
+ workflow.parallel([pipelineA, pipelineB])
766
+ ```
767
+
768
+ ### Chaining patterns
769
+
770
+ | Pattern | What happens | Common use case |
771
+ |---------|--------------|-----------------|
772
+ | `.then().then()` | Sequential steps | Simple pipelines |
773
+ | `.parallel().then()` | Run in parallel, then combine | Fan-out/fan-in |
774
+ | `.foreach().then()` | Process all items, then aggregate | Map-reduce |
775
+ | `.foreach().foreach()` | Creates array of arrays | Avoid - use nested workflow or `.map()` with `.flat()` |
776
+ | `.foreach(workflow)` | Full pipeline per item | Multi-step processing per array item |
777
+
778
+ ### Synchronization: when does the next step run?
779
+
780
+ Both `.parallel()` and `.foreach()` are synchronization points. The next step in the workflow only executes after all parallel branches or all array iterations have completed.
781
+
782
+ ```typescript
783
+ workflow
784
+ .parallel([stepA, stepB, stepC]) // All 3 run simultaneously
785
+ .then(combineStep) // Waits for ALL 3 to finish before running
786
+ .commit();
787
+
788
+ workflow
789
+ .foreach(processStep, { concurrency: 5 }) // Up to 5 items process at once
790
+ .then(aggregateStep) // Waits for ALL items to finish before running
791
+ .commit();
792
+ ```
793
+
794
+ This means:
795
+ - `.parallel()` collects all branch outputs into an object, then passes it to the next step
796
+ - `.foreach()` collects all iteration outputs into an array, then passes it to the next step
797
+ - There is no way to "stream" results to the next step as they complete
798
+
799
+ ### Concurrency behavior
800
+
801
+ | Method | Behavior |
802
+ |--------|----------|
803
+ | `.then()` | Sequential - one step at a time |
804
+ | `.parallel()` | All branches run simultaneously (no limit option) |
805
+ | `.foreach()` | Controlled via `{ concurrency: N }` - default is 1 (sequential) |
806
+ | Nested workflow in `.foreach()` | Respects parent's concurrency setting |
807
+
808
+ **Performance tip:** For I/O-bound operations in `.foreach()`, increase concurrency to process items in parallel:
809
+
810
+ ```typescript
811
+ // Process up to 10 items simultaneously
812
+ workflow.foreach(fetchDataStep, { concurrency: 10 })
813
+ ```
814
+
289
815
  ## Loop management
290
816
 
291
817
  Loop conditions can be implemented in different ways depending on how you want the loop to end. Common patterns include checking values returned in `inputData`, setting a maximum number of iterations, or aborting execution when a limit is reached.
@@ -306,3 +832,8 @@ export const testWorkflow = createWorkflow({...})
306
832
  })
307
833
  .commit();
308
834
  ```
835
+
836
+ ## Related
837
+
838
+ - [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
839
+ - [Human-in-the-loop](/docs/v1/workflows/human-in-the-loop)
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: "Error Handling | Workflows | Mastra Docs"
2
+ title: "Error Handling | Workflows"
3
3
  description: "Learn how to handle errors in Mastra workflows using step retries, conditional branching, and monitoring."
4
4
  ---
5
5
 
@@ -187,6 +187,7 @@ for await (const chunk of stream.stream) {
187
187
 
188
188
  ## Related
189
189
 
190
- - [Control Flow](./control-flow)
191
- - [Conditional Branching](./control-flow#conditional-logic-with-branch)
192
- - [Running Workflows](/docs/v1/workflows/overview)
190
+ - [Control Flow](/docs/v1/workflows/control-flow)
191
+ - [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
192
+ - [Time Travel](/docs/v1/workflows/time-travel)
193
+ - [Human-in-the-loop](/docs/v1/workflows/human-in-the-loop)