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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +253 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +16 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +202 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  15. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +113 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +281 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +302 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  52. package/.docs/organized/changelogs/create-mastra.md +302 -0
  53. package/.docs/organized/changelogs/mastra.md +302 -0
  54. package/.docs/organized/code-examples/agent-network.md +282 -0
  55. package/.docs/organized/code-examples/agent.md +426 -0
  56. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  57. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  58. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  59. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  60. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  61. package/.docs/organized/code-examples/client-side-tools.md +69 -0
  62. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  63. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  64. package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
  65. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  66. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  67. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  68. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  69. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  70. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  71. package/.docs/organized/code-examples/quick-start.md +129 -0
  72. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  73. package/.docs/organized/code-examples/weather-agent.md +331 -0
  74. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  75. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  76. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  77. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  78. package/.docs/raw/agents/adding-tools.mdx +288 -0
  79. package/.docs/raw/agents/adding-voice.mdx +200 -0
  80. package/.docs/raw/agents/agent-memory.mdx +62 -0
  81. package/.docs/raw/agents/mcp-guide.mdx +215 -0
  82. package/.docs/raw/agents/overview.mdx +303 -0
  83. package/.docs/raw/agents/runtime-variables.mdx +137 -0
  84. package/.docs/raw/community/discord.mdx +12 -0
  85. package/.docs/raw/community/licensing.mdx +63 -0
  86. package/.docs/raw/deployment/client.mdx +120 -0
  87. package/.docs/raw/deployment/deployment.mdx +127 -0
  88. package/.docs/raw/deployment/overview.mdx +63 -0
  89. package/.docs/raw/deployment/server.mdx +282 -0
  90. package/.docs/raw/evals/custom-eval.mdx +22 -0
  91. package/.docs/raw/evals/overview.mdx +95 -0
  92. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  93. package/.docs/raw/evals/textual-evals.mdx +54 -0
  94. package/.docs/raw/faq/index.mdx +63 -0
  95. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  96. package/.docs/raw/frameworks/next-js.mdx +238 -0
  97. package/.docs/raw/getting-started/installation.mdx +442 -0
  98. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  99. package/.docs/raw/getting-started/model-capability.mdx +11 -0
  100. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  101. package/.docs/raw/index.mdx +22 -0
  102. package/.docs/raw/integrations/index.mdx +213 -0
  103. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  104. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  105. package/.docs/raw/local-dev/mastra-dev.mdx +124 -0
  106. package/.docs/raw/mastra-cloud/deploying.mdx +136 -0
  107. package/.docs/raw/mastra-cloud/observability.mdx +163 -0
  108. package/.docs/raw/mastra-cloud/overview.mdx +57 -0
  109. package/.docs/raw/mastra-cloud/setting-up.mdx +122 -0
  110. package/.docs/raw/memory/memory-processors.mdx +131 -0
  111. package/.docs/raw/memory/overview.mdx +119 -0
  112. package/.docs/raw/memory/semantic-recall.mdx +126 -0
  113. package/.docs/raw/memory/working-memory.mdx +87 -0
  114. package/.docs/raw/observability/logging.mdx +38 -0
  115. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  116. package/.docs/raw/observability/tracing.mdx +115 -0
  117. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  118. package/.docs/raw/rag/overview.mdx +85 -0
  119. package/.docs/raw/rag/retrieval.mdx +365 -0
  120. package/.docs/raw/rag/vector-databases.mdx +340 -0
  121. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  122. package/.docs/raw/reference/agents/generate.mdx +334 -0
  123. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  124. package/.docs/raw/reference/agents/stream.mdx +369 -0
  125. package/.docs/raw/reference/cli/build.mdx +55 -0
  126. package/.docs/raw/reference/cli/dev.mdx +134 -0
  127. package/.docs/raw/reference/cli/init.mdx +43 -0
  128. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  129. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  130. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  131. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  132. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  133. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  134. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  135. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  136. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  137. package/.docs/raw/reference/deployer/cloudflare.mdx +212 -0
  138. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  139. package/.docs/raw/reference/deployer/netlify.mdx +116 -0
  140. package/.docs/raw/reference/deployer/vercel.mdx +122 -0
  141. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  142. package/.docs/raw/reference/evals/bias.mdx +186 -0
  143. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  144. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  145. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  146. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  147. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  148. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  149. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  150. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  151. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  152. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  153. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  154. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  155. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  156. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  157. package/.docs/raw/reference/index.mdx +12 -0
  158. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  159. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  160. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  161. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  162. package/.docs/raw/reference/memory/query.mdx +167 -0
  163. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  164. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  165. package/.docs/raw/reference/observability/logger.mdx +55 -0
  166. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  167. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  168. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  169. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  170. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  171. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  172. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  173. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  174. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  175. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  176. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  177. package/.docs/raw/reference/rag/astra.mdx +258 -0
  178. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  179. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  180. package/.docs/raw/reference/rag/document.mdx +127 -0
  181. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  182. package/.docs/raw/reference/rag/extract-params.mdx +249 -0
  183. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  184. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  185. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  186. package/.docs/raw/reference/rag/pg.mdx +501 -0
  187. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  188. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  189. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  190. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  191. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  192. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  193. package/.docs/raw/reference/storage/cloudflare-d1.mdx +89 -0
  194. package/.docs/raw/reference/storage/cloudflare.mdx +93 -0
  195. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  196. package/.docs/raw/reference/storage/postgresql.mdx +93 -0
  197. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  198. package/.docs/raw/reference/tools/client.mdx +321 -0
  199. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  200. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  201. package/.docs/raw/reference/tools/mcp-configuration.mdx +222 -0
  202. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  203. package/.docs/raw/reference/voice/azure.mdx +215 -0
  204. package/.docs/raw/reference/voice/cloudflare.mdx +152 -0
  205. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  206. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  207. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  208. package/.docs/raw/reference/voice/google.mdx +198 -0
  209. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  210. package/.docs/raw/reference/voice/murf.mdx +251 -0
  211. package/.docs/raw/reference/voice/openai-realtime.mdx +432 -0
  212. package/.docs/raw/reference/voice/openai.mdx +168 -0
  213. package/.docs/raw/reference/voice/playai.mdx +159 -0
  214. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  215. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  216. package/.docs/raw/reference/voice/voice.addInstructions.mdx +70 -0
  217. package/.docs/raw/reference/voice/voice.addTools.mdx +77 -0
  218. package/.docs/raw/reference/voice/voice.answer.mdx +69 -0
  219. package/.docs/raw/reference/voice/voice.close.mdx +56 -0
  220. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  221. package/.docs/raw/reference/voice/voice.events.mdx +80 -0
  222. package/.docs/raw/reference/voice/voice.getSpeakers.mdx +283 -0
  223. package/.docs/raw/reference/voice/voice.listen.mdx +198 -0
  224. package/.docs/raw/reference/voice/voice.off.mdx +72 -0
  225. package/.docs/raw/reference/voice/voice.on.mdx +129 -0
  226. package/.docs/raw/reference/voice/voice.send.mdx +81 -0
  227. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  228. package/.docs/raw/reference/voice/voice.updateConfig.mdx +87 -0
  229. package/.docs/raw/reference/workflows/after.mdx +88 -0
  230. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  231. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  232. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  233. package/.docs/raw/reference/workflows/else.mdx +72 -0
  234. package/.docs/raw/reference/workflows/events.mdx +305 -0
  235. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  236. package/.docs/raw/reference/workflows/if.mdx +107 -0
  237. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  238. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  239. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  240. package/.docs/raw/reference/workflows/start.mdx +84 -0
  241. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  242. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  243. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  244. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  245. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  246. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  247. package/.docs/raw/reference/workflows/then.mdx +74 -0
  248. package/.docs/raw/reference/workflows/until.mdx +165 -0
  249. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  250. package/.docs/raw/reference/workflows/while.mdx +168 -0
  251. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  252. package/.docs/raw/storage/overview.mdx +378 -0
  253. package/.docs/raw/voice/overview.mdx +816 -0
  254. package/.docs/raw/voice/speech-to-speech.mdx +73 -0
  255. package/.docs/raw/voice/speech-to-text.mdx +84 -0
  256. package/.docs/raw/voice/text-to-speech.mdx +89 -0
  257. package/.docs/raw/workflows/control-flow.mdx +778 -0
  258. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  259. package/.docs/raw/workflows/error-handling.mdx +183 -0
  260. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  261. package/.docs/raw/workflows/overview.mdx +170 -0
  262. package/.docs/raw/workflows/runtime-variables.mdx +153 -0
  263. package/.docs/raw/workflows/steps.mdx +108 -0
  264. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  265. package/.docs/raw/workflows/variables.mdx +313 -0
  266. package/LICENSE.md +46 -0
  267. package/README.md +129 -0
  268. package/dist/_tsup-dts-rollup.d.ts +140 -0
  269. package/dist/chunk-HYPVNJL7.js +194 -0
  270. package/dist/prepare-docs/prepare.d.ts +1 -0
  271. package/dist/prepare-docs/prepare.js +1 -0
  272. package/dist/stdio.d.ts +1 -0
  273. package/dist/stdio.js +650 -0
  274. package/package.json +60 -0
@@ -0,0 +1,288 @@
1
+ ---
2
+ title: "Agent Tool Selection | Agent Documentation | Mastra"
3
+ description: Tools are typed functions that can be executed by agents or workflows, with built-in integration access and parameter validation. Each tool has a schema that defines its inputs, an executor function that implements its logic, and access to configured integrations.
4
+ ---
5
+
6
+ # Agent Tool Selection
7
+
8
+ Tools are typed functions that can be executed by agents or workflows, with built-in integration access and parameter validation. Each tool has a schema that defines its inputs, an executor function that implements its logic, and access to configured integrations.
9
+
10
+ ## Creating Tools
11
+
12
+ In this section, we'll walk through the process of creating a tool that can be used by your agents. Let's create a simple tool that fetches current weather information for a given city.
13
+
14
+ ```typescript filename="src/mastra/tools/weatherInfo.ts" copy
15
+ import { createTool } from "@mastra/core/tools";
16
+ import { z } from "zod";
17
+
18
+ const getWeatherInfo = async (city: string) => {
19
+ // Replace with an actual API call to a weather service
20
+ const data = await fetch(`https://api.example.com/weather?city=${city}`).then(
21
+ (r) => r.json(),
22
+ );
23
+ return data;
24
+ };
25
+
26
+ export const weatherInfo = createTool({
27
+ id: "Get Weather Information",
28
+ inputSchema: z.object({
29
+ city: z.string(),
30
+ }),
31
+ description: `Fetches the current weather information for a given city`,
32
+ execute: async ({ context: { city } }) => {
33
+ console.log("Using tool to fetch weather information for", city);
34
+ return await getWeatherInfo(city);
35
+ },
36
+ });
37
+ ```
38
+
39
+ ## Adding Tools to an Agent
40
+
41
+ Now we'll add the tool to an agent. We'll create an agent that can answer questions about the weather and configure it to use our `weatherInfo` tool.
42
+
43
+ ```typescript filename="src/mastra/agents/weatherAgent.ts"
44
+ import { Agent } from "@mastra/core/agent";
45
+ import { openai } from "@ai-sdk/openai";
46
+ import * as tools from "../tools/weatherInfo";
47
+
48
+ export const weatherAgent = new Agent<typeof tools>({
49
+ name: "Weather Agent",
50
+ instructions:
51
+ "You are a helpful assistant that provides current weather information. When asked about the weather, use the weather information tool to fetch the data.",
52
+ model: openai("gpt-4o-mini"),
53
+ tools: {
54
+ weatherInfo: tools.weatherInfo,
55
+ },
56
+ });
57
+ ```
58
+
59
+ ## Registering the Agent
60
+
61
+ We need to initialize Mastra with our agent.
62
+
63
+ ```typescript filename="src/index.ts"
64
+ import { Mastra } from "@mastra/core";
65
+ import { weatherAgent } from "./agents/weatherAgent";
66
+
67
+ export const mastra = new Mastra({
68
+ agents: { weatherAgent },
69
+ });
70
+ ```
71
+
72
+ This registers your agent with Mastra, making it available for use.
73
+
74
+ ## Abort Signals
75
+
76
+ The abort signals from `generate` and `stream` (text generation) are forwarded to the tool execution. You can access them in the second parameter of the execute function and e.g. abort long-running computations or forward them to fetch calls inside tools.
77
+
78
+ ```typescript
79
+ import { Agent } from "@mastra/core/agent";
80
+ import { createTool } from "@mastra/core/tools";
81
+ import { z } from "zod";
82
+
83
+ const agent = new Agent({
84
+ name: "Weather agent",
85
+ tools: {
86
+ weather: createTool({
87
+ id: "Get Weather Information",
88
+ description: "Get the weather in a location",
89
+ inputSchema: z.object({ location: z.string() }),
90
+ execute: async ({ context: { location } }, { abortSignal }) => {
91
+ return fetch(
92
+ `https://api.weatherapi.com/v1/current.json?q=${location}`,
93
+ { signal: abortSignal }, // forward the abort signal to fetch
94
+ );
95
+ },
96
+ }),
97
+ },
98
+ });
99
+
100
+ const result = await agent.generate("What is the weather in San Francisco?", {
101
+ abortSignal: myAbortSignal, // signal that will be forwarded to tools
102
+ });
103
+ ```
104
+
105
+ ## Injecting Request/User-Specific Variables
106
+
107
+ We support dependency injection for tools and workflows. You can pass a container directly to your `generate` or `stream` function calls, or inject it using [server middleware](/docs/deployment/server#Middleware).
108
+
109
+ Here's an example where we change the temperature scale between Fahrenheit and Celsius:
110
+
111
+ ```typescript filename="src/agents/weather-agent.ts"
112
+ import { Agent } from "@mastra/core/agent";
113
+ import { createTool } from "@mastra/core/tools";
114
+ import { z } from "zod";
115
+
116
+ export const agent = new Agent({
117
+ name: "Weather agent",
118
+ tools: {
119
+ weather: createTool({
120
+ id: "Get Weather Information",
121
+ description: "Get the weather in a location",
122
+ inputSchema: z.object({ location: z.string() }),
123
+ execute: async ({ context: { location }, container }) => {
124
+ const scale = container.get("temperature-scale");
125
+
126
+ const result = await fetch(
127
+ `https://api.weatherapi.com/v1/current.json?q=${location}`,
128
+ );
129
+
130
+ const json = await result.json();
131
+
132
+ return {
133
+ temperature: scale === "celsius" ? json.temp_c : json.temp_f,
134
+ };
135
+ },
136
+ }),
137
+ },
138
+ });
139
+ ```
140
+
141
+ ```typescript
142
+ import { agent } from "./agents/weather";
143
+
144
+ type MyContainer = {"temperature-scale", "celsius" | "farenheit"}
145
+
146
+ const container = new Container<MyContainer>();
147
+ container.set("temperature-scale", "celsius");
148
+
149
+ const result = await agent.generate("What is the weather in San Francisco?", {
150
+ container,
151
+ });
152
+ ```
153
+
154
+ ## Debugging Tools
155
+
156
+ You can test tools using Vitest or any other testing framework. Writing unit tests for your tools ensures they behave as expected and helps catch errors early.
157
+
158
+ ## Calling an Agent with a Tool
159
+
160
+ Now we can call the agent, and it will use the tool to fetch the weather information.
161
+
162
+ ## Example: Interacting with the Agent
163
+
164
+ ```typescript filename="src/index.ts"
165
+ import { mastra } from "./index";
166
+
167
+ async function main() {
168
+ const agent = mastra.getAgent("weatherAgent");
169
+ const response = await agent.generate(
170
+ "What's the weather like in New York City today?",
171
+ );
172
+
173
+ console.log(response.text);
174
+ }
175
+
176
+ main();
177
+ ```
178
+
179
+ The agent will use the `weatherInfo` tool to get the current weather in New York City and respond accordingly.
180
+
181
+ ## Vercel AI SDK Tool Format
182
+
183
+ Mastra supports tools created using the Vercel AI SDK format. You can import and use these tools directly:
184
+
185
+ ```typescript filename="src/mastra/tools/vercelTool.ts" copy
186
+ import { tool } from "ai";
187
+ import { z } from "zod";
188
+
189
+ export const weatherInfo = tool({
190
+ description: "Fetches the current weather information for a given city",
191
+ parameters: z.object({
192
+ city: z.string().describe("The city to get weather for"),
193
+ }),
194
+ execute: async ({ city }) => {
195
+ // Replace with actual API call
196
+ const data = await fetch(`https://api.example.com/weather?city=${city}`);
197
+ return data.json();
198
+ },
199
+ });
200
+ ```
201
+
202
+ You can use Vercel tools alongside Mastra tools in your agents:
203
+
204
+ ```typescript filename="src/mastra/agents/weatherAgent.ts"
205
+ import { Agent } from "@mastra/core/agent";
206
+ import { openai } from "@ai-sdk/openai";
207
+ import { weatherInfo } from "../tools/vercelTool";
208
+ import * as mastraTools from "../tools/mastraTools";
209
+
210
+ export const weatherAgent = new Agent({
211
+ name: "Weather Agent",
212
+ instructions:
213
+ "You are a helpful assistant that provides weather information.",
214
+ model: openai("gpt-4"),
215
+ tools: {
216
+ weatherInfo, // Vercel tool
217
+ ...mastraTools, // Mastra tools
218
+ },
219
+ });
220
+ ```
221
+
222
+ Both tool formats will work seamlessly within your agent's workflow.
223
+
224
+ ## Tool Design Best Practices
225
+
226
+ When creating tools for your agents, following these guidelines will help ensure reliable and intuitive tool usage:
227
+
228
+ ### Tool Descriptions
229
+
230
+ Your tool's main description should focus on its purpose and value:
231
+
232
+ - Keep descriptions simple and focused on **what** the tool does
233
+ - Emphasize the tool's primary use case
234
+ - Avoid implementation details in the main description
235
+ - Focus on helping the agent understand **when** to use the tool
236
+
237
+ ```typescript
238
+ createTool({
239
+ id: "documentSearch",
240
+ description:
241
+ "Access the knowledge base to find information needed to answer user questions",
242
+ // ... rest of tool configuration
243
+ });
244
+ ```
245
+
246
+ ### Parameter Schemas
247
+
248
+ Technical details belong in the parameter schemas, where they help the agent use the tool correctly:
249
+
250
+ - Make parameters self-documenting with clear descriptions
251
+ - Include default values and their implications
252
+ - Provide examples where helpful
253
+ - Describe the impact of different parameter choices
254
+
255
+ ```typescript
256
+ inputSchema: z.object({
257
+ query: z.string().describe("The search query to find relevant information"),
258
+ limit: z.number().describe(
259
+ "Number of results to return. Higher values provide more context, lower values focus on best matches"
260
+ ),
261
+ options: z.string().describe(
262
+ "Optional configuration. Example: '{'filter': 'category=news'}'"
263
+ ),
264
+ }),
265
+ ```
266
+
267
+ ### Agent Interaction Patterns
268
+
269
+ Tools are more likely to be used effectively when:
270
+
271
+ - Queries or tasks are complex enough to clearly require tool assistance
272
+ - Agent instructions provide clear guidance on tool usage
273
+ - Parameter requirements are well-documented in the schema
274
+ - The tool's purpose aligns with the query's needs
275
+
276
+ ### Common Pitfalls
277
+
278
+ - Overloading the main description with technical details
279
+ - Mixing implementation details with usage guidance
280
+ - Unclear parameter descriptions or missing examples
281
+
282
+ Following these practices helps ensure your tools are discoverable and usable by agents while maintaining clean separation between purpose (main description) and implementation details (parameter schemas).
283
+
284
+ ## Model Context Protocol (MCP) Tools
285
+
286
+ Mastra also supports tools from MCP-compatible servers through the `@mastra/mcp` package. MCP provides a standardized way for AI models to discover and interact with external tools and resources. This makes it easy to integrate third-party tools into your agents without writing custom integrations.
287
+
288
+ For detailed information about using MCP tools, including configuration options and best practices, see our [MCP guide](/docs/agents/mcp-guide).
@@ -0,0 +1,200 @@
1
+ # Adding Voice to Agents
2
+
3
+ Mastra agents can be enhanced with voice capabilities, allowing them to speak responses and listen to user input. You can configure an agent to use either a single voice provider or combine multiple providers for different operations.
4
+
5
+ ## Using a Single Provider
6
+
7
+ The simplest way to add voice to an agent is to use a single provider for both speaking and listening:
8
+
9
+ ```typescript
10
+ import { createReadStream } from "fs";
11
+ import path from "path";
12
+ import { Agent } from "@mastra/core/agent";
13
+ import { OpenAIVoice } from "@mastra/voice-openai";
14
+ import { openai } from "@ai-sdk/openai";
15
+
16
+ // Initialize the voice provider with default settings
17
+ const voice = new OpenAIVoice();
18
+
19
+ // Create an agent with voice capabilities
20
+ export const agent = new Agent({
21
+ name: "Agent",
22
+ instructions: `You are a helpful assistant with both STT and TTS capabilities.`,
23
+ model: openai("gpt-4o"),
24
+ voice,
25
+ });
26
+
27
+ // The agent can now use voice for interaction
28
+ const audioStream = await agent.voice.speak("Hello, I'm your AI assistant!", {
29
+ filetype: "m4a",
30
+ });
31
+
32
+ playAudio(audioStream!);
33
+
34
+ try {
35
+ const transcription = await agent.voice.listen(audioStream);
36
+ console.log(transcription)
37
+ } catch (error) {
38
+ console.error("Error transcribing audio:", error);
39
+ }
40
+ ```
41
+
42
+ ## Using Multiple Providers
43
+
44
+ For more flexibility, you can use different providers for speaking and listening using the CompositeVoice class:
45
+
46
+ ```typescript
47
+ import { Agent } from "@mastra/core/agent";
48
+ import { CompositeVoice } from "@mastra/core/voice";
49
+ import { OpenAIVoice } from "@mastra/voice-openai";
50
+ import { PlayAIVoice } from "@mastra/voice-playai";
51
+ import { openai } from "@ai-sdk/openai";
52
+
53
+ export const agent = new Agent({
54
+ name: "Agent",
55
+ instructions: `You are a helpful assistant with both STT and TTS capabilities.`,
56
+ model: openai("gpt-4o"),
57
+
58
+ // Create a composite voice using OpenAI for listening and PlayAI for speaking
59
+ voice: new CompositeVoice({
60
+ input: new OpenAIVoice(),
61
+ output: new PlayAIVoice(),
62
+ }),
63
+ });
64
+ ```
65
+
66
+ ## Working with Audio Streams
67
+
68
+ The `speak()` and `listen()` methods work with Node.js streams. Here's how to save and load audio files:
69
+
70
+ ### Saving Speech Output
71
+
72
+ The `speak` method returns a stream that you can pipe to a file or speaker.
73
+
74
+ ```typescript
75
+ import { createWriteStream } from "fs";
76
+ import path from "path";
77
+
78
+ // Generate speech and save to file
79
+ const audio = await agent.voice.speak("Hello, World!");
80
+ const filePath = path.join(process.cwd(), "agent.mp3");
81
+ const writer = createWriteStream(filePath);
82
+
83
+ audio.pipe(writer);
84
+
85
+ await new Promise<void>((resolve, reject) => {
86
+ writer.on("finish", () => resolve());
87
+ writer.on("error", reject);
88
+ });
89
+ ```
90
+
91
+
92
+ ### Transcribing Audio Input
93
+
94
+ The `listen` method expects a stream of audio data from a microphone or file.
95
+
96
+ ```typescript
97
+ import { createReadStream } from "fs";
98
+ import path from "path";
99
+
100
+ // Read audio file and transcribe
101
+ const audioFilePath = path.join(process.cwd(), "/agent.m4a");
102
+ const audioStream = createReadStream(audioFilePath);
103
+
104
+ try {
105
+ console.log("Transcribing audio file...");
106
+ const transcription = await agent.voice.listen(audioStream, {
107
+ filetype: "m4a",
108
+ });
109
+ console.log("Transcription:", transcription);
110
+ } catch (error) {
111
+ console.error("Error transcribing audio:", error);
112
+ }
113
+ ```
114
+
115
+ ## Speech-to-Speech Voice Interactions
116
+
117
+ For more dynamic and interactive voice experiences, you can use real-time voice providers that support speech-to-speech capabilities:
118
+
119
+ ```typescript
120
+ import { Agent } from "@mastra/core/agent";
121
+ import { getMicrophoneStream } from "@mastra/node-audio";
122
+ import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
123
+ import { search, calculate } from "../tools";
124
+
125
+ // Initialize the realtime voice provider
126
+ const voice = new OpenAIRealtimeVoice({
127
+ chatModel: {
128
+ apiKey: process.env.OPENAI_API_KEY,
129
+ model: "gpt-4o-mini-realtime",
130
+ },
131
+ speaker: "alloy",
132
+ });
133
+
134
+ // Create an agent with speech-to-speech voice capabilities
135
+ export const agent = new Agent({
136
+ name: "Agent",
137
+ instructions: `You are a helpful assistant with speech-to-speech capabilities.`,
138
+ model: openai("gpt-4o"),
139
+ tools: {
140
+ // Tools configured on Agent are passed to voice provider
141
+ search,
142
+ calculate,
143
+ },
144
+ voice,
145
+ });
146
+
147
+ // Establish a WebSocket connection
148
+ await agent.voice.connect();
149
+
150
+ // Start a conversation
151
+ agent.voice.speak("Hello, I'm your AI assistant!");
152
+
153
+ // Stream audio from a microphone
154
+ const microphoneStream = getMicrophoneStream();
155
+ agent.voice.send(microphoneStream);
156
+
157
+ // When done with the conversation
158
+ agent.voice.close();
159
+ ```
160
+
161
+ ### Event System
162
+
163
+ The realtime voice provider emits several events you can listen for:
164
+
165
+ ```typescript
166
+ // Listen for speech audio data sent from voice provider
167
+ agent.voice.on("speaking", ({ audio }) => {
168
+ // audio contains ReadableStream or Int16Array audio data
169
+ });
170
+
171
+ // Listen for transcribed text sent from both voice provider and user
172
+ agent.voice.on("writing", ({ text, role }) => {
173
+ console.log(`${role} said: ${text}`);
174
+ });
175
+
176
+ // Listen for errors
177
+ agent.voice.on("error", (error) => {
178
+ console.error("Voice error:", error);
179
+ });
180
+ ```
181
+
182
+ ## Supported Voice Providers
183
+
184
+ Mastra supports multiple voice providers for text-to-speech (TTS) and speech-to-text (STT) capabilities:
185
+
186
+ | Provider | Package | Features | Reference |
187
+ |----------|---------|----------|-----------|
188
+ | OpenAI | `@mastra/voice-openai` | TTS, STT | [Documentation](/reference/voice/openai) |
189
+ | OpenAI Realtime | `@mastra/voice-openai-realtime` | Realtime speech-to-speech | [Documentation](/reference/voice/openai-realtime) |
190
+ | ElevenLabs | `@mastra/voice-elevenlabs` | High-quality TTS | [Documentation](/reference/voice/elevenlabs) |
191
+ | PlayAI | `@mastra/voice-playai` | TTS | [Documentation](/reference/voice/playai) |
192
+ | Google | `@mastra/voice-google` | TTS, STT | [Documentation](/reference/voice/google) |
193
+ | Deepgram | `@mastra/voice-deepgram` | STT | [Documentation](/reference/voice/deepgram) |
194
+ | Murf | `@mastra/voice-murf` | TTS | [Documentation](/reference/voice/murf) |
195
+ | Speechify | `@mastra/voice-speechify` | TTS | [Documentation](/reference/voice/speechify) |
196
+ | Sarvam | `@mastra/voice-sarvam` | TTS, STT | [Documentation](/reference/voice/sarvam) |
197
+ | Azure | `@mastra/voice-azure` | TTS, STT | [Documentation](/reference/voice/mastra-voice) |
198
+ | Cloudflare | `@mastra/voice-cloudflare` | TTS | [Documentation](/reference/voice/mastra-voice) |
199
+
200
+ For more details on voice capabilities, see the [Voice API Reference](/reference/voice/mastra-voice).
@@ -0,0 +1,62 @@
1
+ ---
2
+ title: "Using Agent Memory | Agents | Mastra Docs"
3
+ description: Documentation on how agents in Mastra use memory to store conversation history and contextual information.
4
+ ---
5
+
6
+ # Agent Memory
7
+
8
+ Agents in Mastra can leverage a powerful memory system to store conversation history, recall relevant information, and maintain persistent context across interactions. This allows agents to have more natural, stateful conversations.
9
+
10
+ ## Enabling Memory for an Agent
11
+
12
+ To enable memory, simply instantiate the `Memory` class and pass it to your agent's configuration. You also need to install the memory package:
13
+
14
+ ```bash npm2yarn copy
15
+ npm install @mastra/memory
16
+ ```
17
+
18
+ ```typescript
19
+ import { Agent } from "@mastra/core/agent";
20
+ import { Memory } from "@mastra/memory";
21
+ import { openai } from "@ai-sdk/openai";
22
+
23
+ // Basic memory setup
24
+ const memory = new Memory();
25
+
26
+ const agent = new Agent({
27
+ name: "MyMemoryAgent",
28
+ instructions: "You are a helpful assistant with memory.",
29
+ model: openai("gpt-4o"),
30
+ memory: memory, // Attach the memory instance
31
+ });
32
+ ```
33
+
34
+ This basic setup uses default settings, including LibSQL for storage and FastEmbed for embeddings. For detailed setup instructions, see [Memory](/docs/memory/overview).
35
+
36
+ ## Using Memory in Agent Calls
37
+
38
+ To utilize memory during interactions, you **must** provide `resourceId` and `threadId` when calling the agent's `stream()` or `generate()` methods.
39
+
40
+ - `resourceId`: Typically identifies the user or entity (e.g., `user_123`).
41
+ - `threadId`: Identifies a specific conversation thread (e.g., `support_chat_456`).
42
+
43
+ ```typescript
44
+ // Example agent call using memory
45
+ await agent.stream("Remember my favorite color is blue.", {
46
+ resourceId: "user_alice",
47
+ threadId: "preferences_thread",
48
+ });
49
+
50
+ // Later in the same thread...
51
+ const response = await agent.stream("What's my favorite color?", {
52
+ resourceId: "user_alice",
53
+ threadId: "preferences_thread",
54
+ });
55
+ // Agent will use memory to recall the favorite color.
56
+ ```
57
+
58
+ These IDs ensure that conversation history and context are correctly stored and retrieved for the appropriate user and conversation.
59
+
60
+ ## Next Steps
61
+
62
+ Keep exploring Mastra's [memory capabilities](/docs/memory/overview) like threads, conversation history, semantic recall, and working memory.