@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718

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 (254) 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 +161 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -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-registry-registry.md +26 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  51. package/.docs/organized/changelogs/create-mastra.md +302 -0
  52. package/.docs/organized/changelogs/mastra.md +302 -0
  53. package/.docs/organized/code-examples/agent-network.md +282 -0
  54. package/.docs/organized/code-examples/agent.md +388 -0
  55. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  56. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  57. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  58. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  59. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  60. package/.docs/organized/code-examples/client-side-tools.md +69 -0
  61. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  62. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  63. package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
  64. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  65. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  66. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  67. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  68. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  69. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  70. package/.docs/organized/code-examples/quick-start.md +129 -0
  71. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  72. package/.docs/organized/code-examples/weather-agent.md +353 -0
  73. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  74. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  75. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  76. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  77. package/.docs/raw/agents/adding-tools.mdx +317 -0
  78. package/.docs/raw/agents/adding-voice.mdx +175 -0
  79. package/.docs/raw/agents/agent-memory.mdx +62 -0
  80. package/.docs/raw/agents/mcp-guide.mdx +215 -0
  81. package/.docs/raw/agents/overview.mdx +303 -0
  82. package/.docs/raw/community/discord.mdx +12 -0
  83. package/.docs/raw/community/licensing.mdx +63 -0
  84. package/.docs/raw/deployment/client.mdx +120 -0
  85. package/.docs/raw/deployment/deployment.mdx +127 -0
  86. package/.docs/raw/deployment/server.mdx +282 -0
  87. package/.docs/raw/evals/custom-eval.mdx +22 -0
  88. package/.docs/raw/evals/overview.mdx +95 -0
  89. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  90. package/.docs/raw/evals/textual-evals.mdx +54 -0
  91. package/.docs/raw/faq/index.mdx +63 -0
  92. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  93. package/.docs/raw/frameworks/next-js.mdx +238 -0
  94. package/.docs/raw/getting-started/installation.mdx +442 -0
  95. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  96. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  97. package/.docs/raw/index.mdx +22 -0
  98. package/.docs/raw/integrations/index.mdx +213 -0
  99. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  100. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  101. package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
  102. package/.docs/raw/memory/memory-processors.mdx +131 -0
  103. package/.docs/raw/memory/overview.mdx +119 -0
  104. package/.docs/raw/memory/semantic-recall.mdx +122 -0
  105. package/.docs/raw/memory/working-memory.mdx +87 -0
  106. package/.docs/raw/observability/logging.mdx +38 -0
  107. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  108. package/.docs/raw/observability/tracing.mdx +115 -0
  109. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  110. package/.docs/raw/rag/overview.mdx +85 -0
  111. package/.docs/raw/rag/retrieval.mdx +365 -0
  112. package/.docs/raw/rag/vector-databases.mdx +340 -0
  113. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  114. package/.docs/raw/reference/agents/generate.mdx +334 -0
  115. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  116. package/.docs/raw/reference/agents/stream.mdx +369 -0
  117. package/.docs/raw/reference/cli/build.mdx +55 -0
  118. package/.docs/raw/reference/cli/dev.mdx +134 -0
  119. package/.docs/raw/reference/cli/init.mdx +43 -0
  120. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  121. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  122. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  123. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  124. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  125. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  126. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  127. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  128. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  129. package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
  130. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  131. package/.docs/raw/reference/deployer/netlify.mdx +109 -0
  132. package/.docs/raw/reference/deployer/vercel.mdx +117 -0
  133. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  134. package/.docs/raw/reference/evals/bias.mdx +186 -0
  135. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  136. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  137. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  138. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  139. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  140. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  141. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  142. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  143. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  144. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  145. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  146. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  147. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  148. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  149. package/.docs/raw/reference/index.mdx +12 -0
  150. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  151. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  152. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  153. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  154. package/.docs/raw/reference/memory/query.mdx +167 -0
  155. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  156. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  157. package/.docs/raw/reference/observability/logger.mdx +55 -0
  158. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  159. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  160. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  161. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  162. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  163. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  164. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  165. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  166. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  167. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  168. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  169. package/.docs/raw/reference/rag/astra.mdx +258 -0
  170. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  171. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  172. package/.docs/raw/reference/rag/document.mdx +127 -0
  173. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  174. package/.docs/raw/reference/rag/extract-params.mdx +226 -0
  175. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  176. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  177. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  178. package/.docs/raw/reference/rag/pg.mdx +477 -0
  179. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  180. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  181. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  182. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  183. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  184. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  185. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  186. package/.docs/raw/reference/storage/postgresql.mdx +48 -0
  187. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  188. package/.docs/raw/reference/tools/client.mdx +207 -0
  189. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  190. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  191. package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
  192. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  193. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  194. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  195. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  196. package/.docs/raw/reference/voice/google.mdx +198 -0
  197. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  198. package/.docs/raw/reference/voice/murf.mdx +251 -0
  199. package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
  200. package/.docs/raw/reference/voice/openai.mdx +168 -0
  201. package/.docs/raw/reference/voice/playai.mdx +159 -0
  202. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  203. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  204. package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
  205. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  206. package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
  207. package/.docs/raw/reference/voice/voice.on.mdx +189 -0
  208. package/.docs/raw/reference/voice/voice.send.mdx +118 -0
  209. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  210. package/.docs/raw/reference/workflows/after.mdx +88 -0
  211. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  212. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  213. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  214. package/.docs/raw/reference/workflows/else.mdx +72 -0
  215. package/.docs/raw/reference/workflows/events.mdx +305 -0
  216. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  217. package/.docs/raw/reference/workflows/if.mdx +107 -0
  218. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  219. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  220. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  221. package/.docs/raw/reference/workflows/start.mdx +84 -0
  222. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  223. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  224. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  225. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  226. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  227. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  228. package/.docs/raw/reference/workflows/then.mdx +74 -0
  229. package/.docs/raw/reference/workflows/until.mdx +165 -0
  230. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  231. package/.docs/raw/reference/workflows/while.mdx +168 -0
  232. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  233. package/.docs/raw/storage/overview.mdx +378 -0
  234. package/.docs/raw/voice/overview.mdx +135 -0
  235. package/.docs/raw/voice/speech-to-text.mdx +45 -0
  236. package/.docs/raw/voice/text-to-speech.mdx +52 -0
  237. package/.docs/raw/voice/voice-to-voice.mdx +310 -0
  238. package/.docs/raw/workflows/control-flow.mdx +778 -0
  239. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  240. package/.docs/raw/workflows/error-handling.mdx +183 -0
  241. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  242. package/.docs/raw/workflows/overview.mdx +203 -0
  243. package/.docs/raw/workflows/steps.mdx +108 -0
  244. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  245. package/.docs/raw/workflows/variables.mdx +313 -0
  246. package/LICENSE.md +46 -0
  247. package/README.md +129 -0
  248. package/dist/_tsup-dts-rollup.d.ts +149 -0
  249. package/dist/chunk-QWYMT5LP.js +194 -0
  250. package/dist/prepare-docs/prepare.d.ts +1 -0
  251. package/dist/prepare-docs/prepare.js +1 -0
  252. package/dist/stdio.d.ts +1 -0
  253. package/dist/stdio.js +518 -0
  254. package/package.json +60 -0
@@ -0,0 +1,215 @@
1
+ ---
2
+ title: "Using MCP With Mastra | Agents | Mastra Docs"
3
+ description: "Use MCP in Mastra to integrate third party tools and resources in your AI agents."
4
+ ---
5
+
6
+ # Using MCP With Mastra
7
+
8
+ [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is a standardized way for AI models to discover and interact with external tools and resources.
9
+
10
+ ## Overview
11
+
12
+ MCP in Mastra provides a standardized way to connect to tool servers and supports both stdio and SSE-based connections.
13
+
14
+ ## Installation
15
+
16
+ Using pnpm:
17
+
18
+ ```bash
19
+ pnpm add @mastra/mcp@latest
20
+ ```
21
+
22
+ Using npm:
23
+
24
+ ```bash
25
+ npm install @mastra/mcp@latest
26
+ ```
27
+
28
+ ## Using MCP in Your Code
29
+
30
+ The `MCPConfiguration` class provides a way to manage multiple tool servers in your Mastra applications without managing multiple MCP clients. You can configure both stdio-based and SSE-based servers:
31
+
32
+ ```typescript
33
+ import { MCPConfiguration } from "@mastra/mcp";
34
+ import { Agent } from "@mastra/core/agent";
35
+ import { openai } from "@ai-sdk/openai";
36
+
37
+ const mcp = new MCPConfiguration({
38
+ servers: {
39
+ // stdio example
40
+ sequential: {
41
+ name: "sequential-thinking",
42
+ server: {
43
+ command: "npx",
44
+ args: ["-y", "@modelcontextprotocol/server-sequential-thinking"],
45
+ },
46
+ },
47
+ // SSE example
48
+ weather: {
49
+ url: new URL("http://localhost:8080/sse"),
50
+ requestInit: {
51
+ headers: {
52
+ Authorization: "Bearer your-token",
53
+ },
54
+ },
55
+ },
56
+ },
57
+ });
58
+ ```
59
+
60
+ ### Tools vs Toolsets
61
+
62
+ The `MCPConfiguration` class provides two ways to access MCP tools, each suited for different use cases:
63
+
64
+ #### Using Tools (`getTools()`)
65
+
66
+ Use this approach when:
67
+
68
+ - You have a single MCP connection
69
+ - The tools are used by a single user/context
70
+ - Tool configuration (API keys, credentials) remains constant
71
+ - You want to initialize an Agent with a fixed set of tools
72
+
73
+ ```typescript
74
+ const agent = new Agent({
75
+ name: "CLI Assistant",
76
+ instructions: "You help users with CLI tasks",
77
+ model: openai("gpt-4o-mini"),
78
+ tools: await mcp.getTools(), // Tools are fixed at agent creation
79
+ });
80
+ ```
81
+
82
+ #### Using Toolsets (`getToolsets()`)
83
+
84
+ Use this approach when:
85
+
86
+ - You need per-request tool configuration
87
+ - Tools need different credentials per user
88
+ - Running in a multi-user environment (web app, API, etc)
89
+ - Tool configuration needs to change dynamically
90
+
91
+ ```typescript
92
+ const mcp = new MCPConfiguration({
93
+ servers: {
94
+ example: {
95
+ command: "npx",
96
+ args: ["-y", "@example/fakemcp"],
97
+ env: {
98
+ API_KEY: "your-api-key",
99
+ },
100
+ },
101
+ },
102
+ });
103
+
104
+ // Get the current toolsets configured for this user
105
+ const toolsets = await mcp.getToolsets();
106
+
107
+ // Use the agent with user-specific tool configurations
108
+ const response = await agent.stream(
109
+ "What's new in Mastra and how's the weather?",
110
+ {
111
+ toolsets,
112
+ },
113
+ );
114
+ ```
115
+
116
+ ## MCP Registries
117
+
118
+ MCP servers can be accessed through registries that provide curated collections of tools.
119
+ We've curated an [MCP Registry Registry](/mcp-registry-registry) to help you find the best places to source MCP servers, but here's how you can use tools from some of our favorites:
120
+
121
+ ### mcp.run Registry
122
+
123
+ [mcp.run](https://www.mcp.run/) makes it easy for you to call pre-authenticated, secure MCP Servers. The tools from mcp.run are free, and entirely managed, so your agent only needs a SSE URL and can use any tools a user has installed. MCP Servers are grouped into [Profiles](https://docs.mcp.run/user-guide/manage-profiles), and accessed with a unique SSE URL.
124
+
125
+ For each Profile, you can copy/paste unique, signed URLs into your `MCPConfiguration` like this:
126
+
127
+ ```typescript
128
+ const mcp = new MCPConfiguration({
129
+ servers: {
130
+ marketing: {
131
+ url: new URL(process.env.MCP_RUN_SSE_URL!),
132
+ },
133
+ },
134
+ });
135
+ ```
136
+
137
+ > Important: Each SSE URL on on [mcp.run](https://mcp.run) contains a unique signature, that should be treated like a password. It's best to read your SSE URL as an environment variable and manage it outside of your application code.
138
+
139
+ ```bash filename=".env" copy
140
+ MCP_RUN_SSE_URL=https://www.mcp.run/api/mcp/sse?nonce=...
141
+ ```
142
+
143
+ ### Composio.dev Registry
144
+
145
+ [Composio.dev](https://composio.dev) provides a registry of [SSE-based MCP servers](https://mcp.composio.dev) that can be easily integrated with Mastra. The SSE URL that's generated for Cursor is compatible with Mastra - you can use it directly in your configuration:
146
+
147
+ ```typescript
148
+ const mcp = new MCPConfiguration({
149
+ servers: {
150
+ googleSheets: {
151
+ url: new URL("https://mcp.composio.dev/googlesheets/[private-url-path]"),
152
+ },
153
+ gmail: {
154
+ url: new URL("https://mcp.composio.dev/gmail/[private-url-path]"),
155
+ },
156
+ },
157
+ });
158
+ ```
159
+
160
+ When using Composio-provided tools, you can authenticate with services (like Google Sheets or Gmail) directly through conversation with your agent. The tools include authentication capabilities that guide you through the process while chatting.
161
+
162
+ Note: The Composio.dev integration is best suited for single-user scenarios like personal automation, as the SSE URL is tied to your account and can't be used for multiple users. Each URL represents a single account's authentication context.
163
+
164
+ ### Smithery.ai Registry
165
+
166
+ [Smithery.ai](https://smithery.ai) provides a registry of MCP servers that you can easily use with Mastra:
167
+
168
+ ```typescript
169
+ // Unix/Mac
170
+ const mcp = new MCPConfiguration({
171
+ servers: {
172
+ sequentialThinking: {
173
+ command: "npx",
174
+ args: [
175
+ "-y",
176
+ "@smithery/cli@latest",
177
+ "run",
178
+ "@smithery-ai/server-sequential-thinking",
179
+ "--config",
180
+ "{}",
181
+ ],
182
+ },
183
+ },
184
+ });
185
+
186
+ // Windows
187
+ const mcp = new MCPConfiguration({
188
+ servers: {
189
+ sequentialThinking: {
190
+ command: "cmd",
191
+ args: [
192
+ "/c",
193
+ "npx",
194
+ "-y",
195
+ "@smithery/cli@latest",
196
+ "run",
197
+ "@smithery-ai/server-sequential-thinking",
198
+ "--config",
199
+ "{}",
200
+ ],
201
+ },
202
+ },
203
+ });
204
+ ```
205
+
206
+ This example is adapted from the Claude integration example in the Smithery documentation.
207
+
208
+ ## Using the Mastra Documentation Server
209
+
210
+ Looking to use Mastra's MCP documentation server in your IDE? Check out our [MCP Documentation Server guide](/docs/getting-started/mcp-docs-server) to get started.
211
+
212
+ ## Next Steps
213
+
214
+ - Learn more about [MCPConfiguration](/reference/tools/mcp-configuration)
215
+ - Check out our [example projects](/examples) that use MCP
@@ -0,0 +1,303 @@
1
+ ---
2
+ title: "Creating and Calling Agents | Agent Documentation | Mastra"
3
+ description: Overview of agents in Mastra, detailing their capabilities and how they interact with tools, workflows, and external systems.
4
+ ---
5
+
6
+ # Creating and Calling Agents
7
+
8
+ Agents in Mastra are systems where the language model can autonomously decide on a sequence of actions to perform tasks. They have access to tools, workflows, and synced data, enabling them to perform complex tasks and interact with external systems. Agents can invoke your custom functions, utilize third-party APIs through integrations, and access knowledge bases you have built.
9
+
10
+ Agents are like employees who can be used for ongoing projects. They have names, persistent memory, consistent model configurations, and instructions across calls, as well as a set of enabled tools.
11
+
12
+ ## 1. Creating an Agent
13
+
14
+ To create an agent in Mastra, you use the `Agent` class and define its properties:
15
+
16
+ ```ts showLineNumbers filename="src/mastra/agents/index.ts" copy
17
+ import { Agent } from "@mastra/core/agent";
18
+ import { openai } from "@ai-sdk/openai";
19
+
20
+ export const myAgent = new Agent({
21
+ name: "My Agent",
22
+ instructions: "You are a helpful assistant.",
23
+ model: openai("gpt-4o-mini"),
24
+ });
25
+ ```
26
+
27
+ **Note:** Ensure that you have set the necessary environment variables, such as your OpenAI API key, in your `.env` file:
28
+
29
+ ```.env filename=".env" copy
30
+ OPENAI_API_KEY=your_openai_api_key
31
+ ```
32
+
33
+ Also, make sure you have the `@mastra/core` package installed:
34
+
35
+ ```bash npm2yarn copy
36
+ npm install @mastra/core
37
+ ```
38
+
39
+ ### Registering the Agent
40
+
41
+ Register your agent with Mastra to enable logging and access to configured tools and integrations:
42
+
43
+ ```ts showLineNumbers filename="src/mastra/index.ts" copy
44
+ import { Mastra } from "@mastra/core";
45
+ import { myAgent } from "./agents";
46
+
47
+ export const mastra = new Mastra({
48
+ agents: { myAgent },
49
+ });
50
+ ```
51
+
52
+ ## 2. Generating and streaming text
53
+
54
+ ### Generating text
55
+
56
+ Use the `.generate()` method to have your agent produce text responses:
57
+
58
+ ```ts showLineNumbers filename="src/mastra/index.ts" copy
59
+ const response = await myAgent.generate([
60
+ { role: "user", content: "Hello, how can you assist me today?" },
61
+ ]);
62
+
63
+ console.log("Agent:", response.text);
64
+ ```
65
+
66
+ For more details about the generate method and its options, see the [generate reference documentation](/reference/agents/generate).
67
+
68
+ ### Streaming responses
69
+
70
+ For more real-time responses, you can stream the agent's response:
71
+
72
+ ```ts showLineNumbers filename="src/mastra/index.ts" copy
73
+ const stream = await myAgent.stream([
74
+ { role: "user", content: "Tell me a story." },
75
+ ]);
76
+
77
+ console.log("Agent:");
78
+
79
+ for await (const chunk of stream.textStream) {
80
+ process.stdout.write(chunk);
81
+ }
82
+ ```
83
+
84
+ For more details about streaming responses, see the [stream reference documentation](/reference/agents/stream).
85
+
86
+ ## 3. Structured Output
87
+
88
+ Agents can return structured data by providing a JSON Schema or using a Zod schema.
89
+
90
+ ### Using JSON Schema
91
+
92
+ ```typescript
93
+ const schema = {
94
+ type: "object",
95
+ properties: {
96
+ summary: { type: "string" },
97
+ keywords: { type: "array", items: { type: "string" } },
98
+ },
99
+ additionalProperties: false,
100
+ required: ["summary", "keywords"],
101
+ };
102
+
103
+ const response = await myAgent.generate(
104
+ [
105
+ {
106
+ role: "user",
107
+ content:
108
+ "Please provide a summary and keywords for the following text: ...",
109
+ },
110
+ ],
111
+ {
112
+ output: schema,
113
+ },
114
+ );
115
+
116
+ console.log("Structured Output:", response.object);
117
+ ```
118
+
119
+ ### Using Zod
120
+
121
+ You can also use Zod schemas for type-safe structured outputs.
122
+
123
+ First, install Zod:
124
+
125
+ ```bash npm2yarn copy
126
+ npm install zod
127
+ ```
128
+
129
+ Then, define a Zod schema and use it with the agent:
130
+
131
+ ```ts showLineNumbers filename="src/mastra/index.ts" copy
132
+ import { z } from "zod";
133
+
134
+ // Define the Zod schema
135
+ const schema = z.object({
136
+ summary: z.string(),
137
+ keywords: z.array(z.string()),
138
+ });
139
+
140
+ // Use the schema with the agent
141
+ const response = await myAgent.generate(
142
+ [
143
+ {
144
+ role: "user",
145
+ content:
146
+ "Please provide a summary and keywords for the following text: ...",
147
+ },
148
+ ],
149
+ {
150
+ output: schema,
151
+ },
152
+ );
153
+
154
+ console.log("Structured Output:", response.object);
155
+ ```
156
+
157
+ ### Using Tools
158
+
159
+ If you need to generate structured output alongside tool calls, you'll need to use the `experimental_output` property instead of `output`. Here's how:
160
+
161
+ ```typescript
162
+ const schema = z.object({
163
+ summary: z.string(),
164
+ keywords: z.array(z.string()),
165
+ });
166
+
167
+ const response = await myAgent.generate(
168
+ [
169
+ {
170
+ role: "user",
171
+ content:
172
+ "Please analyze this repository and provide a summary and keywords...",
173
+ },
174
+ ],
175
+ {
176
+ // Use experimental_output to enable both structured output and tool calls
177
+ experimental_output: schema,
178
+ },
179
+ );
180
+
181
+ console.log("Structured Output:", response.object);
182
+ ```
183
+
184
+ <br />
185
+
186
+ This allows you to have strong typing and validation for the structured data returned by the agent.
187
+
188
+ ## 4. Multi-step Tool use Agents
189
+
190
+ Agents can be enhanced with tools - functions that extend their capabilities beyond text generation. Tools allow agents to perform calculations, access external systems, and process data. For details on creating and configuring tools, see the [Adding Tools documentation](/docs/agents/adding-tools).
191
+
192
+ ### Using maxSteps
193
+
194
+ The `maxSteps` parameter controls the maximum number of sequential LLM calls an agent can make, particularly important when using tool calls. By default, it is set to 1 to prevent infinite loops in case of misconfigured tools. You can increase this limit based on your use case:
195
+
196
+ ```ts showLineNumbers filename="src/mastra/agents/index.ts" copy
197
+ import { Agent } from "@mastra/core/agent";
198
+ import { openai } from "@ai-sdk/openai";
199
+ import * as mathjs from "mathjs";
200
+ import { z } from "zod";
201
+
202
+ export const myAgent = new Agent({
203
+ name: "My Agent",
204
+ instructions: "You are a helpful assistant that can solve math problems.",
205
+ model: openai("gpt-4o-mini"),
206
+ tools: {
207
+ calculate: {
208
+ description: "Calculator for mathematical expressions",
209
+ schema: z.object({ expression: z.string() }),
210
+ execute: async ({ expression }) => mathjs.evaluate(expression),
211
+ },
212
+ },
213
+ });
214
+
215
+ const response = await myAgent.generate(
216
+ [
217
+ {
218
+ role: "user",
219
+ content:
220
+ "If a taxi driver earns $9461 per hour and works 12 hours a day, how much does they earn in one day?",
221
+ },
222
+ ],
223
+ {
224
+ maxSteps: 5, // Allow up to 5 tool usage steps
225
+ },
226
+ );
227
+ ```
228
+
229
+ ### Using onStepFinish
230
+
231
+ You can monitor the progress of multi-step operations using the `onStepFinish` callback. This is useful for debugging or providing progress updates to users.
232
+ `onStepFinish` is only available when streaming or generating text without structured output.
233
+
234
+ ```ts showLineNumbers filename="src/mastra/agents/index.ts" copy
235
+ const response = await myAgent.generate(
236
+ [{ role: "user", content: "Calculate the taxi driver's daily earnings." }],
237
+ {
238
+ maxSteps: 5,
239
+ onStepFinish: ({ text, toolCalls, toolResults }) => {
240
+ console.log("Step completed:", { text, toolCalls, toolResults });
241
+ },
242
+ },
243
+ );
244
+ ```
245
+
246
+ ### Using onFinish
247
+
248
+ The `onFinish` callback is available when streaming responses and provides detailed information about the completed interaction. It is called after the LLM has finished generating its response and all tool executions have completed.
249
+ This callback receives the final response text, execution steps, token usage statistics, and other metadata that can be useful for monitoring and logging:
250
+
251
+ ```ts showLineNumbers filename="src/mastra/agents/index.ts" copy
252
+ const stream = await myAgent.stream(
253
+ [{ role: "user", content: "Calculate the taxi driver's daily earnings." }],
254
+ {
255
+ maxSteps: 5,
256
+ onFinish: ({
257
+ steps,
258
+ text,
259
+ finishReason, // 'complete', 'length', 'tool', etc.
260
+ usage, // token usage statistics
261
+ reasoningDetails, // additional context about the agent's decisions
262
+ }) => {
263
+ console.log("Stream complete:", {
264
+ totalSteps: steps.length,
265
+ finishReason,
266
+ usage,
267
+ });
268
+ },
269
+ },
270
+ );
271
+ ```
272
+
273
+ ## 5. Running Agents
274
+
275
+ Mastra provides a CLI command `mastra dev` to run your agents behind an API. By default, this looks for exported agents in files in the `src/mastra/agents` directory.
276
+
277
+ ### Starting the Server
278
+
279
+ ```bash
280
+ mastra dev
281
+ ```
282
+
283
+ This will start the server and make your agent available at `http://localhost:4111/api/agents/myAgent/generate`.
284
+
285
+ ### Interacting with the Agent
286
+
287
+ You can interact with the agent using `curl` from the command line:
288
+
289
+ ```bash
290
+ curl -X POST http://localhost:4111/api/agents/myAgent/generate \
291
+ -H "Content-Type: application/json" \
292
+ -d '{
293
+ "messages": [
294
+ { "role": "user", "content": "Hello, how can you assist me today?" }
295
+ ]
296
+ }'
297
+ ```
298
+
299
+ ## Next Steps
300
+
301
+ - Learn about Agent Memory in the [Agent Memory](./agent-memory.mdx) guide.
302
+ - Learn about Agent Tools in the [Agent Tools](./adding-tools.mdx) guide.
303
+ - See an example agent in the [Chef Michel](../guides/chef-michel.mdx) example.
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: "Discord Community and Bot | Documentation | Mastra"
3
+ description: Information about the Mastra Discord community and MCP bot.
4
+ ---
5
+
6
+ # Discord Community
7
+
8
+ The Discord server has over 1000 members and serves as the main discussion forum for Mastra. The Mastra team monitors Discord during North American and European business hours, with community members active across other time zones.[Join the Discord server](https://discord.gg/BTYqqHKUrf).
9
+
10
+ ## Discord MCP Bot
11
+
12
+ In addition to community members, we have an (experimental!) Discord bot that can also help answer questions. It uses [Model Context Protocol (MCP)](/docs/agents/mcp-guide). You can ask it a question with `/ask` (either in public channels or DMs) and clear history (in DMs only) with `/cleardm`.
@@ -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.