@mastra/mcp-docs-server 0.0.0-default-storage-virtual-file-20250410035748

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 (252) 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 +131 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +80 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +166 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +220 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +220 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +299 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  50. package/.docs/organized/changelogs/create-mastra.md +302 -0
  51. package/.docs/organized/changelogs/mastra.md +302 -0
  52. package/.docs/organized/code-examples/agent-network.md +282 -0
  53. package/.docs/organized/code-examples/agent.md +390 -0
  54. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  55. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  56. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  57. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  58. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  59. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  60. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  61. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  62. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  63. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  64. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  65. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  66. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  67. package/.docs/organized/code-examples/quick-start.md +129 -0
  68. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  69. package/.docs/organized/code-examples/weather-agent.md +353 -0
  70. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  71. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  72. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  73. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  74. package/.docs/raw/agents/adding-tools.mdx +239 -0
  75. package/.docs/raw/agents/adding-voice.mdx +175 -0
  76. package/.docs/raw/agents/agent-memory.mdx +62 -0
  77. package/.docs/raw/agents/mcp-guide.mdx +192 -0
  78. package/.docs/raw/agents/overview.mdx +303 -0
  79. package/.docs/raw/community/discord.mdx +12 -0
  80. package/.docs/raw/community/licensing.mdx +63 -0
  81. package/.docs/raw/deployment/client.mdx +120 -0
  82. package/.docs/raw/deployment/deployment.mdx +119 -0
  83. package/.docs/raw/deployment/server.mdx +276 -0
  84. package/.docs/raw/evals/custom-eval.mdx +22 -0
  85. package/.docs/raw/evals/overview.mdx +95 -0
  86. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  87. package/.docs/raw/evals/textual-evals.mdx +54 -0
  88. package/.docs/raw/faq/index.mdx +63 -0
  89. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  90. package/.docs/raw/frameworks/next-js.mdx +238 -0
  91. package/.docs/raw/getting-started/installation.mdx +436 -0
  92. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  93. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  94. package/.docs/raw/index.mdx +22 -0
  95. package/.docs/raw/integrations/index.mdx +213 -0
  96. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  97. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  98. package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
  99. package/.docs/raw/memory/memory-processors.mdx +131 -0
  100. package/.docs/raw/memory/overview.mdx +119 -0
  101. package/.docs/raw/memory/semantic-recall.mdx +122 -0
  102. package/.docs/raw/memory/working-memory.mdx +87 -0
  103. package/.docs/raw/observability/logging.mdx +38 -0
  104. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  105. package/.docs/raw/observability/tracing.mdx +115 -0
  106. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  107. package/.docs/raw/rag/overview.mdx +85 -0
  108. package/.docs/raw/rag/retrieval.mdx +365 -0
  109. package/.docs/raw/rag/vector-databases.mdx +340 -0
  110. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  111. package/.docs/raw/reference/agents/generate.mdx +327 -0
  112. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  113. package/.docs/raw/reference/agents/stream.mdx +362 -0
  114. package/.docs/raw/reference/cli/build.mdx +48 -0
  115. package/.docs/raw/reference/cli/deploy.mdx +22 -0
  116. package/.docs/raw/reference/cli/dev.mdx +134 -0
  117. package/.docs/raw/reference/cli/init.mdx +43 -0
  118. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  119. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  120. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  121. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  122. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  123. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  124. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  125. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  126. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  127. package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
  128. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  129. package/.docs/raw/reference/deployer/netlify.mdx +88 -0
  130. package/.docs/raw/reference/deployer/vercel.mdx +97 -0
  131. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  132. package/.docs/raw/reference/evals/bias.mdx +186 -0
  133. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  134. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  135. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  136. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  137. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  138. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  139. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  140. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  141. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  142. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  143. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  144. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  145. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  146. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  147. package/.docs/raw/reference/index.mdx +8 -0
  148. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  149. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  150. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  151. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  152. package/.docs/raw/reference/memory/query.mdx +167 -0
  153. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  154. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  155. package/.docs/raw/reference/observability/logger.mdx +55 -0
  156. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  157. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  158. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  159. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  160. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  161. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  162. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  163. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  164. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  165. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  166. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  167. package/.docs/raw/reference/rag/astra.mdx +258 -0
  168. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  169. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  170. package/.docs/raw/reference/rag/document.mdx +127 -0
  171. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  172. package/.docs/raw/reference/rag/extract-params.mdx +226 -0
  173. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  174. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  175. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  176. package/.docs/raw/reference/rag/pg.mdx +477 -0
  177. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  178. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  179. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  180. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  181. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  182. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  183. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  184. package/.docs/raw/reference/storage/postgresql.mdx +48 -0
  185. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  186. package/.docs/raw/reference/tools/client.mdx +188 -0
  187. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  188. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  189. package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
  190. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  191. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  192. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  193. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  194. package/.docs/raw/reference/voice/google.mdx +198 -0
  195. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  196. package/.docs/raw/reference/voice/murf.mdx +251 -0
  197. package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
  198. package/.docs/raw/reference/voice/openai.mdx +168 -0
  199. package/.docs/raw/reference/voice/playai.mdx +159 -0
  200. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  201. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  202. package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
  203. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  204. package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
  205. package/.docs/raw/reference/voice/voice.on.mdx +189 -0
  206. package/.docs/raw/reference/voice/voice.send.mdx +118 -0
  207. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  208. package/.docs/raw/reference/workflows/after.mdx +88 -0
  209. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  210. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  211. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  212. package/.docs/raw/reference/workflows/else.mdx +72 -0
  213. package/.docs/raw/reference/workflows/events.mdx +305 -0
  214. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  215. package/.docs/raw/reference/workflows/if.mdx +107 -0
  216. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  217. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  218. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  219. package/.docs/raw/reference/workflows/start.mdx +84 -0
  220. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  221. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  222. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  223. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  224. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  225. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  226. package/.docs/raw/reference/workflows/then.mdx +74 -0
  227. package/.docs/raw/reference/workflows/until.mdx +165 -0
  228. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  229. package/.docs/raw/reference/workflows/while.mdx +168 -0
  230. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  231. package/.docs/raw/storage/overview.mdx +378 -0
  232. package/.docs/raw/voice/overview.mdx +135 -0
  233. package/.docs/raw/voice/speech-to-text.mdx +45 -0
  234. package/.docs/raw/voice/text-to-speech.mdx +52 -0
  235. package/.docs/raw/voice/voice-to-voice.mdx +310 -0
  236. package/.docs/raw/workflows/control-flow.mdx +778 -0
  237. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  238. package/.docs/raw/workflows/error-handling.mdx +183 -0
  239. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  240. package/.docs/raw/workflows/overview.mdx +167 -0
  241. package/.docs/raw/workflows/steps.mdx +108 -0
  242. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  243. package/.docs/raw/workflows/variables.mdx +313 -0
  244. package/LICENSE +44 -0
  245. package/README.md +129 -0
  246. package/dist/_tsup-dts-rollup.d.ts +149 -0
  247. package/dist/chunk-QWYMT5LP.js +194 -0
  248. package/dist/prepare-docs/prepare.d.ts +1 -0
  249. package/dist/prepare-docs/prepare.js +1 -0
  250. package/dist/stdio.d.ts +1 -0
  251. package/dist/stdio.js +518 -0
  252. package/package.json +60 -0
@@ -0,0 +1,63 @@
1
+ ---
2
+ title: "Licensing"
3
+ description: "Mastra License"
4
+ ---
5
+
6
+ # License
7
+
8
+ ## Elastic License 2.0 (ELv2)
9
+
10
+ Mastra is licensed under the Elastic License 2.0 (ELv2), a modern license designed to balance open-source principles with sustainable business practices.
11
+
12
+ ### What is Elastic License 2.0?
13
+
14
+ The Elastic License 2.0 is a source-available license that grants users broad rights to use, modify, and distribute the software while including specific limitations to protect the project's sustainability. It allows:
15
+
16
+ - Free use for most purposes
17
+ - Viewing, modifying, and redistributing the source code
18
+ - Creating and distributing derivative works
19
+ - Commercial use within your organization
20
+
21
+ The primary limitation is that you cannot provide Mastra as a hosted or managed service that offers users access to the substantial functionality of the software.
22
+
23
+ ### Why We Chose Elastic License 2.0
24
+
25
+ We selected the Elastic License 2.0 for several important reasons:
26
+
27
+ 1. **Sustainability**: It enables us to maintain a healthy balance between openness and the ability to sustain long-term development.
28
+
29
+ 2. **Innovation Protection**: It ensures we can continue investing in innovation without concerns about our work being repackaged as competing services.
30
+
31
+ 3. **Community Focus**: It maintains the spirit of open source by allowing users to view, modify, and learn from our code while protecting our ability to support the community.
32
+
33
+ 4. **Business Clarity**: It provides clear guidelines for how Mastra can be used in commercial contexts.
34
+
35
+ ### Building Your Business with Mastra
36
+
37
+ Despite the licensing restrictions, there are numerous ways to build successful businesses using Mastra:
38
+
39
+ #### Allowed Business Models
40
+
41
+ - **Building Applications**: Create and sell applications built with Mastra
42
+ - **Offering Consulting Services**: Provide expertise, implementation, and customization services
43
+ - **Developing Custom Solutions**: Build bespoke AI solutions for clients using Mastra
44
+ - **Creating Add-ons and Extensions**: Develop and sell complementary tools that extend Mastra's functionality
45
+ - **Training and Education**: Offer courses and educational materials about using Mastra effectively
46
+
47
+ #### Examples of Compliant Usage
48
+
49
+ - A company builds an AI-powered customer service application using Mastra and sells it to clients
50
+ - A consulting firm offers implementation and customization services for Mastra
51
+ - A developer creates specialized agents and tools with Mastra and licenses them to other businesses
52
+ - A startup builds a vertical-specific solution (e.g., healthcare AI assistant) powered by Mastra
53
+
54
+ #### What to Avoid
55
+
56
+ The main restriction is that you cannot offer Mastra itself as a hosted service where users access its core functionality. This means:
57
+
58
+ - Don't create a SaaS platform that is essentially Mastra with minimal modifications
59
+ - Don't offer a managed Mastra service where customers are primarily paying to use Mastra's features
60
+
61
+ ### Questions About Licensing?
62
+
63
+ If you have specific questions about how the Elastic License 2.0 applies to your use case, please [contact us](https://discord.gg/BTYqqHKUrf) on Discord for clarification. We're committed to supporting legitimate business use cases while protecting the sustainability of the project.
@@ -0,0 +1,296 @@
1
+ ---
2
+ title: "Using with AI SDK"
3
+ description: "Learn how Mastra leverages the AI SDK library and how you can leverage it further with Mastra"
4
+ ---
5
+
6
+ # AI SDK
7
+
8
+ Mastra leverages AI SDK's model routing (a unified interface on top of OpenAI, Anthropic, etc), structured output, and tool calling.
9
+
10
+ We explain this in greater detail in [this blog post](https://mastra.ai/blog/using-ai-sdk-with-mastra)
11
+
12
+ ## Mastra + AI SDK
13
+
14
+ Mastra acts as a layer on top of AI SDK to help teams productionize their proof-of-concepts quickly and easily.
15
+
16
+ <img
17
+ src="/docs/mastra-ai-sdk.png"
18
+ alt="Agent interaction trace showing spans, LLM calls, and tool executions"
19
+ style={{ maxWidth: "800px", width: "100%", margin: "8px 0" }}
20
+ className="nextra-image rounded-md py-8"
21
+ data-zoom
22
+ width={800}
23
+ height={400}
24
+ />
25
+
26
+ ## Model routing
27
+
28
+ When creating agents in Mastra, you can specify any AI SDK-supported model:
29
+
30
+ ```typescript
31
+ import { openai } from "@ai-sdk/openai";
32
+ import { Agent } from "@mastra/core/agent";
33
+
34
+ const agent = new Agent({
35
+ name: "WeatherAgent",
36
+ instructions: "Instructions for the agent...",
37
+ model: openai("gpt-4-turbo"), // Model comes directly from AI SDK
38
+ });
39
+
40
+ const result = await agent.generate("What is the weather like?");
41
+ ```
42
+
43
+ ## AI SDK Hooks
44
+
45
+ Mastra is compatible with AI SDK's hooks for seamless frontend integration:
46
+
47
+ ### useChat
48
+
49
+ The `useChat` hook enables real-time chat interactions in your frontend application
50
+
51
+ - Works with agent data streams i.e. `.toDataStreamResponse()`
52
+ - The useChat `api` defaults to `/api/chat`
53
+ - Works with the Mastra REST API agent stream endpoint `{MASTRA_BASE_URL}/agents/:agentId/stream` for data streams,
54
+ i.e. no structured output is defined.
55
+
56
+ ```typescript filename="app/api/chat/route.ts" copy
57
+ import { mastra } from "@/src/mastra";
58
+
59
+ export async function POST(req: Request) {
60
+ const { messages } = await req.json();
61
+ const myAgent = mastra.getAgent("weatherAgent");
62
+ const stream = await myAgent.stream(messages);
63
+
64
+ return stream.toDataStreamResponse();
65
+ }
66
+ ```
67
+
68
+ ```typescript copy
69
+ import { useChat } from '@ai-sdk/react';
70
+
71
+ export function ChatComponent() {
72
+ const { messages, input, handleInputChange, handleSubmit } = useChat({
73
+ api: '/path-to-your-agent-stream-api-endpoint'
74
+ });
75
+
76
+ return (
77
+ <div>
78
+ {messages.map(m => (
79
+ <div key={m.id}>
80
+ {m.role}: {m.content}
81
+ </div>
82
+ ))}
83
+ <form onSubmit={handleSubmit}>
84
+ <input
85
+ value={input}
86
+ onChange={handleInputChange}
87
+ placeholder="Say something..."
88
+ />
89
+ </form>
90
+ </div>
91
+ );
92
+ }
93
+ ```
94
+
95
+ > **Gotcha**: When using `useChat` with agent memory functionality, make sure to check out the [Agent Memory section](/docs/agents/agent-memory#usechat) for important implementation details.
96
+
97
+ ### useCompletion
98
+
99
+ For single-turn completions, use the `useCompletion` hook:
100
+
101
+ - Works with agent data streams i.e. `.toDataStreamResponse()`
102
+ - The useCompletion `api` defaults to `/api/completion`
103
+ - Works with the Mastra REST API agent stream endpoint `{MASTRA_BASE_URL}/agents/:agentId/stream` for data streams,
104
+ i.e. no structured output is defined.
105
+
106
+ ```typescript filename="app/api/completion/route.ts" copy
107
+ import { mastra } from "@/src/mastra";
108
+
109
+ export async function POST(req: Request) {
110
+ const { messages } = await req.json();
111
+ const myAgent = mastra.getAgent("weatherAgent");
112
+ const stream = await myAgent.stream(messages);
113
+
114
+ return stream.toDataStreamResponse();
115
+ }
116
+ ```
117
+
118
+ ```typescript
119
+ import { useCompletion } from "@ai-sdk/react";
120
+
121
+ export function CompletionComponent() {
122
+ const {
123
+ completion,
124
+ input,
125
+ handleInputChange,
126
+ handleSubmit,
127
+ } = useCompletion({
128
+ api: '/path-to-your-agent-stream-api-endpoint'
129
+ });
130
+
131
+ return (
132
+ <div>
133
+ <form onSubmit={handleSubmit}>
134
+ <input
135
+ value={input}
136
+ onChange={handleInputChange}
137
+ placeholder="Enter a prompt..."
138
+ />
139
+ </form>
140
+ <p>Completion result: {completion}</p>
141
+ </div>
142
+ );
143
+ }
144
+ ```
145
+
146
+ ### useObject
147
+
148
+ For consuming text streams that represent JSON objects and parsing them into a complete object based on a schema.
149
+
150
+ - Works with agent text streams i.e. `.toTextStreamResponse()`
151
+ - The useObject `api` defaults to `/api/completion`
152
+ - Works with the Mastra REST API agent stream endpoint `{MASTRA_BASE_URL}/agents/:agentId/stream` for text streams,
153
+ i.e. structured output is defined.
154
+
155
+ ```typescript filename="app/api/use-object/route.ts" copy
156
+ import { mastra } from "@/src/mastra";
157
+
158
+ export async function POST(req: Request) {
159
+ const { messages } = await req.json();
160
+ const myAgent = mastra.getAgent("weatherAgent");
161
+ const stream = await myAgent.stream(messages, {
162
+ output: z.object({
163
+ weather: z.string(),
164
+ }),
165
+ });
166
+
167
+ return stream.toTextStreamResponse();
168
+ }
169
+ ```
170
+
171
+ ```typescript
172
+ import { experimental_useObject as useObject } from '@ai-sdk/react';
173
+
174
+ export default function Page() {
175
+ const { object, submit } = useObject({
176
+ api: '/api/use-object',
177
+ schema: z.object({
178
+ weather: z.string(),
179
+ }),
180
+ });
181
+
182
+ return (
183
+ <div>
184
+ <button onClick={() => submit('example input')}>Generate</button>
185
+ {object?.content && <p>{object.content}</p>}
186
+ </div>
187
+ );
188
+ }
189
+ ```
190
+
191
+ ## Tool Calling
192
+
193
+ ### AI SDK Tool Format
194
+
195
+ Mastra supports tools created using the AI SDK format, so you can use
196
+ them directly with Mastra agents. See our tools doc on [Vercel AI SDK Tool Format
197
+ ](/docs/agents/adding-tools#vercel-ai-sdk-tool-format) for more details.
198
+
199
+ ### Client-side tool calling
200
+
201
+ Mastra leverages AI SDK's tool calling, so what applies in AI SDK applies here still.
202
+ [Agent Tools](/docs/agents/adding-tools) in Mastra are 100% percent compatible with AI SDK tools.
203
+
204
+ Mastra tools also expose an optional `execute` async function. It is optional because you might want to forward tool calls to the client or to a queue instead of executing them in the same process.
205
+
206
+ One way to then leverage client-side tool calling is to use the `@ai-sdk/react` `useChat` hook's `onToolCall` property for
207
+ client-side tool execution
208
+
209
+ ## Custom DataStream
210
+ In certain scenarios you need to write custom data, message annotations to an agent's dataStream.
211
+ This can be useful for:
212
+
213
+ - Streaming additional data to the client
214
+ - Passing progress info back to the client in real time
215
+
216
+ Mastra integrates well with AI SDK to make this possible
217
+
218
+ ### CreateDataStream
219
+ The `createDataStream` function allows you to stream additional data to the client
220
+
221
+ ```typescript copy
222
+ import { createDataStream } from "ai"
223
+ import { Agent } from '@mastra/core/agent';
224
+
225
+ export const weatherAgent = new Agent({
226
+ name: 'Weather Agent',
227
+ instructions: `
228
+ You are a helpful weather assistant that provides accurate weather information.
229
+
230
+ Your primary function is to help users get weather details for specific locations. When responding:
231
+ - Always ask for a location if none is provided
232
+ - If the location name isn’t in English, please translate it
233
+ - If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
234
+ - Include relevant details like humidity, wind conditions, and precipitation
235
+ - Keep responses concise but informative
236
+
237
+ Use the weatherTool to fetch current weather data.
238
+ `,
239
+ model: openai('gpt-4o'),
240
+ tools: { weatherTool },
241
+ });
242
+
243
+ const stream = createDataStream({
244
+ async execute(dataStream) {
245
+ // Write data
246
+ dataStream.writeData({ value: 'Hello' });
247
+
248
+ // Write annotation
249
+ dataStream.writeMessageAnnotation({ type: 'status', value: 'processing' });
250
+
251
+ //mastra agent stream
252
+ const agentStream = await weatherAgent.stream('What is the weather')
253
+
254
+ // Merge agent stream
255
+ agentStream.mergeIntoDataStream(dataStream);
256
+ },
257
+ onError: error => `Custom error: ${error.message}`,
258
+ });
259
+
260
+ ```
261
+ ### CreateDataStreamResponse
262
+ The `createDataStreamResponse` function creates a Response object that streams data to the client
263
+
264
+ ```typescript filename="app/api/chat/route.ts" copy
265
+ import { mastra } from "@/src/mastra";
266
+
267
+ export async function POST(req: Request) {
268
+ const { messages } = await req.json();
269
+ const myAgent = mastra.getAgent("weatherAgent");
270
+ //mastra agent stream
271
+ const agentStream = await myAgent.stream(messages);
272
+
273
+ const response = createDataStreamResponse({
274
+ status: 200,
275
+ statusText: 'OK',
276
+ headers: {
277
+ 'Custom-Header': 'value',
278
+ },
279
+ async execute(dataStream) {
280
+ // Write data
281
+ dataStream.writeData({ value: 'Hello' });
282
+
283
+ // Write annotation
284
+ dataStream.writeMessageAnnotation({ type: 'status', value: 'processing' });
285
+
286
+ // Merge agent stream
287
+ agentStream.mergeIntoDataStream(dataStream);
288
+ },
289
+ onError: error => `Custom error: ${error.message}`,
290
+ });
291
+
292
+ return response
293
+ }
294
+ ```
295
+
296
+
@@ -0,0 +1,238 @@
1
+ ---
2
+ title: "Getting started with Mastra and NextJS | Mastra Guides"
3
+ description: Guide on integrating Mastra with NextJS.
4
+ ---
5
+ import { Callout, Steps, Tabs } from "nextra/components";
6
+
7
+ # Integrate Mastra in your Next.js project
8
+
9
+ There are two main ways to integrate Mastra with your Next.js application: as a separate backend service or directly integrated into your Next.js app.
10
+
11
+ ## 1. Separate Backend Integration
12
+
13
+ Best for larger projects where you want to:
14
+ - Scale your AI backend independently
15
+ - Keep clear separation of concerns
16
+ - Have more deployment flexibility
17
+
18
+ <Steps>
19
+ ### Create Mastra Backend
20
+
21
+ Create a new Mastra project using our CLI:
22
+
23
+ <Tabs items={["npx", "npm", "yarn", "pnpm"]}>
24
+ <Tabs.Tab>
25
+ ```bash copy
26
+ npx create-mastra@latest
27
+ ```
28
+ </Tabs.Tab>
29
+ <Tabs.Tab>
30
+ ```bash copy
31
+ npm create mastra
32
+ ```
33
+ </Tabs.Tab>
34
+ <Tabs.Tab>
35
+ ```bash copy
36
+ yarn create mastra
37
+ ```
38
+ </Tabs.Tab>
39
+ <Tabs.Tab>
40
+ ```bash copy
41
+ pnpm create mastra
42
+ ```
43
+ </Tabs.Tab>
44
+ </Tabs>
45
+
46
+ For detailed setup instructions, see our [installation guide](/docs/getting-started/installation).
47
+
48
+ ### Install MastraClient
49
+
50
+ <Tabs items={["npm", "yarn", "pnpm"]}>
51
+ <Tabs.Tab>
52
+ ```bash copy
53
+ npm install @mastra/client-js
54
+ ```
55
+ </Tabs.Tab>
56
+ <Tabs.Tab>
57
+ ```bash copy
58
+ yarn add @mastra/client-js
59
+ ```
60
+ </Tabs.Tab>
61
+ <Tabs.Tab>
62
+ ```bash copy
63
+ pnpm add @mastra/client-js
64
+ ```
65
+ </Tabs.Tab>
66
+ </Tabs>
67
+
68
+ ### Use MastraClient
69
+
70
+ Create a client instance and use it in your Next.js application:
71
+
72
+ ```typescript filename="lib/mastra.ts" copy
73
+ import { MastraClient } from '@mastra/client-js';
74
+
75
+ // Initialize the client
76
+ export const mastraClient = new MastraClient({
77
+ baseUrl: process.env.NEXT_PUBLIC_MASTRA_API_URL || 'http://localhost:4111',
78
+ });
79
+ ```
80
+
81
+ Example usage in your React component:
82
+
83
+ ```typescript filename="app/components/SimpleWeather.tsx" copy
84
+ 'use client'
85
+
86
+ import { mastraClient } from '@/lib/mastra'
87
+
88
+ export function SimpleWeather() {
89
+ async function handleSubmit(formData: FormData) {
90
+ const city = formData.get('city')
91
+ const agent = mastraClient.getAgent('weatherAgent')
92
+
93
+ try {
94
+ const response = await agent.generate({
95
+ messages: [{ role: 'user', content: `What's the weather like in ${city}?` }],
96
+ })
97
+ // Handle the response
98
+ console.log(response.text)
99
+ } catch (error) {
100
+ console.error('Error:', error)
101
+ }
102
+ }
103
+
104
+ return (
105
+ <form action={handleSubmit}>
106
+ <input name="city" placeholder="Enter city name" />
107
+ <button type="submit">Get Weather</button>
108
+ </form>
109
+ )
110
+ }
111
+ ```
112
+
113
+ ### Deployment
114
+
115
+ When you're ready to deploy, you can use any of our platform-specific deployers (Vercel, Netlify, Cloudflare) or deploy to any Node.js hosting platform. Check our [deployment guide](/docs/deployment/deployment) for detailed instructions.
116
+ </Steps>
117
+
118
+ ## 2. Direct Integration
119
+
120
+ Better for smaller projects or prototypes. This approach bundles Mastra directly with your Next.js application.
121
+
122
+ <Steps>
123
+ ### Initialize Mastra in your Next.js Root
124
+
125
+ First, navigate to your Next.js project root and initialize Mastra:
126
+
127
+ ```bash copy
128
+ cd your-nextjs-app
129
+ ```
130
+
131
+ Then run the initialization command:
132
+
133
+ <Tabs items={["npm", "yarn", "pnpm"]}>
134
+ <Tabs.Tab>
135
+ ```bash copy
136
+ npx mastra@latest init
137
+ ```
138
+ </Tabs.Tab>
139
+ <Tabs.Tab>
140
+ ```bash copy
141
+ yarn dlx mastra@latest init
142
+ ```
143
+ </Tabs.Tab>
144
+ <Tabs.Tab>
145
+ ```bash copy
146
+ pnpm dlx mastra@latest init
147
+ ```
148
+ </Tabs.Tab>
149
+ </Tabs>
150
+
151
+ This will set up Mastra in your Next.js project. For more details about init and other configuration options, see our [mastra init reference](/docs/reference/cli/init).
152
+
153
+ ### Configure Next.js
154
+
155
+ Add to your `next.config.js`:
156
+
157
+ ```js filename="next.config.js" copy
158
+ /** @type {import('next').NextConfig} */
159
+ const nextConfig = {
160
+ serverExternalPackages: ["@mastra/*"],
161
+ // ... your other Next.js config
162
+ }
163
+
164
+ module.exports = nextConfig
165
+ ```
166
+
167
+ #### Server Actions Example
168
+
169
+ ```typescript filename="app/actions.ts" copy
170
+ 'use server'
171
+
172
+ import { mastra } from '@/mastra'
173
+
174
+ export async function getWeatherInfo(city: string) {
175
+ const agent = mastra.getAgent('weatherAgent')
176
+
177
+ const result = await agent.generate(`What's the weather like in ${city}?`)
178
+
179
+ return result
180
+ }
181
+ ```
182
+
183
+ Use it in your component:
184
+
185
+ ```typescript filename="app/components/Weather.tsx" copy
186
+ 'use client'
187
+
188
+ import { getWeatherInfo } from '../actions'
189
+
190
+ export function Weather() {
191
+ async function handleSubmit(formData: FormData) {
192
+ const city = formData.get('city') as string
193
+ const result = await getWeatherInfo(city)
194
+ // Handle the result
195
+ console.log(result)
196
+ }
197
+
198
+ return (
199
+ <form action={handleSubmit}>
200
+ <input name="city" placeholder="Enter city name" />
201
+ <button type="submit">Get Weather</button>
202
+ </form>
203
+ )
204
+ }
205
+ ```
206
+
207
+ #### API Routes Example
208
+
209
+ ```typescript filename="app/api/chat/route.ts" copy
210
+ import { mastra } from '@/mastra'
211
+ import { NextResponse } from 'next/server'
212
+
213
+ export async function POST(req: Request) {
214
+ const { city } = await req.json()
215
+ const agent = mastra.getAgent('weatherAgent')
216
+
217
+ const result = await agent.stream(`What's the weather like in ${city}?`)
218
+
219
+ return result.toDataStreamResponse()
220
+ }
221
+ ```
222
+
223
+ ### Deployment
224
+
225
+ When using direct integration, your Mastra instance will be deployed alongside your Next.js application. Ensure you:
226
+ - Set up environment variables for your LLM API keys in your deployment platform
227
+ - Implement proper error handling for production use
228
+ - Monitor your AI agent's performance and costs
229
+ </Steps>
230
+
231
+ ## Observability
232
+
233
+ Mastra provides built-in observability features to help you monitor, debug, and optimize your AI operations. This includes:
234
+ - Tracing of AI operations and their performance
235
+ - Logging of prompts, completions, and errors
236
+ - Integration with observability platforms like Langfuse and LangSmith
237
+
238
+ For detailed setup instructions and configuration options specific to Next.js local development, see our [Next.js Observability Configuration Guide](/docs/deployment/logging-and-tracing#nextjs-configuration).