@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,229 @@
1
+ ---
2
+ title: "Reference: createTool() | Tools | Agents | Mastra Docs"
3
+ description: Documentation for the createTool function in Mastra, which creates custom tools for agents and workflows.
4
+ ---
5
+
6
+ # `createTool()`
7
+
8
+ The `createTool()` function creates typed tools that can be executed by agents or workflows. Tools have built-in schema validation, execution context, and integration with the Mastra ecosystem.
9
+
10
+ ## Overview
11
+
12
+ Tools are a fundamental building block in Mastra that allow agents to interact with external systems, perform computations, and access data. Each tool has:
13
+
14
+ - A unique identifier
15
+ - A description that helps the AI understand when and how to use the tool
16
+ - Optional input and output schemas for validation
17
+ - An execution function that implements the tool's logic
18
+
19
+ ## Example Usage
20
+
21
+ ```ts filename="src/tools/stock-tools.ts" showLineNumbers copy
22
+ import { createTool } from "@mastra/core/tools";
23
+ import { z } from "zod";
24
+
25
+ // Helper function to fetch stock data
26
+ const getStockPrice = async (symbol: string) => {
27
+ const response = await fetch(
28
+ `https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}`
29
+ );
30
+ const data = await response.json();
31
+ return data.prices["4. close"];
32
+ };
33
+
34
+ // Create a tool to get stock prices
35
+ export const stockPriceTool = createTool({
36
+ id: "getStockPrice",
37
+ description: "Fetches the current stock price for a given ticker symbol",
38
+ inputSchema: z.object({
39
+ symbol: z.string().describe("The stock ticker symbol (e.g., AAPL, MSFT)")
40
+ }),
41
+ outputSchema: z.object({
42
+ symbol: z.string(),
43
+ price: z.number(),
44
+ currency: z.string(),
45
+ timestamp: z.string()
46
+ }),
47
+ execute: async ({ context }) => {
48
+ const price = await getStockPrice(context.symbol);
49
+
50
+ return {
51
+ symbol: context.symbol,
52
+ price: parseFloat(price),
53
+ currency: "USD",
54
+ timestamp: new Date().toISOString()
55
+ };
56
+ }
57
+ });
58
+
59
+ // Create a tool that uses the thread context
60
+ export const threadInfoTool = createTool({
61
+ id: "getThreadInfo",
62
+ description: "Returns information about the current conversation thread",
63
+ inputSchema: z.object({
64
+ includeResource: z.boolean().optional().default(false)
65
+ }),
66
+ execute: async ({ context, threadId, resourceId }) => {
67
+ return {
68
+ threadId,
69
+ resourceId: context.includeResource ? resourceId : undefined,
70
+ timestamp: new Date().toISOString()
71
+ };
72
+ }
73
+ });
74
+ ```
75
+
76
+ ## API Reference
77
+
78
+ ### Parameters
79
+
80
+ `createTool()` accepts a single object with the following properties:
81
+
82
+ <PropertiesTable
83
+ content={[
84
+ {
85
+ name: "id",
86
+ type: "string",
87
+ required: true,
88
+ description: "Unique identifier for the tool. This should be descriptive of the tool's function."
89
+ },
90
+ {
91
+ name: "description",
92
+ type: "string",
93
+ required: true,
94
+ description: "Detailed description of what the tool does, when it should be used, and what inputs it requires. This helps the AI understand how to use the tool effectively."
95
+ },
96
+ {
97
+ name: "execute",
98
+ type: "(context: ToolExecutionContext, options?: any) => Promise<any>",
99
+ required: false,
100
+ description: "Async function that implements the tool's logic. Receives the execution context and optional configuration.",
101
+ properties: [
102
+ {
103
+ type: "ToolExecutionContext",
104
+ parameters: [
105
+ {
106
+ name: "context",
107
+ type: "object",
108
+ description: "The validated input data that matches the inputSchema"
109
+ },
110
+ {
111
+ name: "threadId",
112
+ type: "string",
113
+ isOptional: true,
114
+ description: "Identifier for the conversation thread, if available"
115
+ },
116
+ {
117
+ name: "resourceId",
118
+ type: "string",
119
+ isOptional: true,
120
+ description: "Identifier for the user or resource interacting with the tool"
121
+ },
122
+ {
123
+ name: "mastra",
124
+ type: "Mastra",
125
+ isOptional: true,
126
+ description: "Reference to the Mastra instance, if available"
127
+ },
128
+ ]
129
+ },
130
+ {
131
+ type: "ToolOptions",
132
+ parameters: [
133
+ {
134
+ name: "toolCallId",
135
+ type: "string",
136
+ description: "The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data."
137
+ },
138
+ {
139
+ name: "messages",
140
+ type: "CoreMessage[]",
141
+ description: "Messages that were sent to the language model to initiate the response that contained the tool call. The messages do not include the system prompt nor the assistant response that contained the tool call."
142
+ },
143
+ {
144
+ name: "abortSignal",
145
+ type: "AbortSignal",
146
+ isOptional: true,
147
+ description: "An optional abort signal that indicates that the overall operation should be aborted."
148
+ },
149
+ ]
150
+ }
151
+ ]
152
+ },
153
+ {
154
+ name: "inputSchema",
155
+ type: "ZodSchema",
156
+ required: false,
157
+ description: "Zod schema that defines and validates the tool's input parameters. If not provided, the tool will accept any input."
158
+ },
159
+ {
160
+ name: "outputSchema",
161
+ type: "ZodSchema",
162
+ required: false,
163
+ description: "Zod schema that defines and validates the tool's output. Helps ensure the tool returns data in the expected format."
164
+ },
165
+ ]}
166
+ />
167
+
168
+ ### Returns
169
+
170
+ <PropertiesTable
171
+ content={[
172
+ {
173
+ name: "Tool",
174
+ type: "Tool<TSchemaIn, TSchemaOut>",
175
+ description: "A Tool instance that can be used with agents, workflows, or directly executed.",
176
+ properties: [
177
+ {
178
+ type: "Tool",
179
+ parameters: [
180
+ {
181
+ name: "id",
182
+ type: "string",
183
+ description: "The tool's unique identifier"
184
+ },
185
+ {
186
+ name: "description",
187
+ type: "string",
188
+ description: "Description of the tool's functionality"
189
+ },
190
+ {
191
+ name: "inputSchema",
192
+ type: "ZodSchema | undefined",
193
+ description: "Schema for validating inputs"
194
+ },
195
+ {
196
+ name: "outputSchema",
197
+ type: "ZodSchema | undefined",
198
+ description: "Schema for validating outputs"
199
+ },
200
+ {
201
+ name: "execute",
202
+ type: "Function",
203
+ description: "The tool's execution function"
204
+ }
205
+ ]
206
+ }
207
+ ]
208
+ }
209
+ ]}
210
+ />
211
+
212
+ ## Type Safety
213
+
214
+ The `createTool()` function provides full type safety through TypeScript generics:
215
+
216
+ - Input types are inferred from the `inputSchema`
217
+ - Output types are inferred from the `outputSchema`
218
+ - The execution context is properly typed based on the input schema
219
+
220
+ This ensures that your tools are type-safe throughout your application.
221
+
222
+ ## Best Practices
223
+
224
+ 1. **Descriptive IDs**: Use clear, action-oriented IDs like `getWeatherForecast` or `searchDatabase`
225
+ 2. **Detailed Descriptions**: Provide comprehensive descriptions that explain when and how to use the tool
226
+ 3. **Input Validation**: Use Zod schemas to validate inputs and provide helpful error messages
227
+ 4. **Error Handling**: Implement proper error handling in your execute function
228
+ 5. **Idempotency**: When possible, make your tools idempotent (same input always produces same output)
229
+ 6. **Performance**: Keep tools lightweight and fast to execute
@@ -0,0 +1,334 @@
1
+ ---
2
+ title: "Reference: Agent.generate() | Agents | Mastra Docs"
3
+ description: "Documentation for the `.generate()` method in Mastra agents, which produces text or structured responses."
4
+ ---
5
+
6
+ # Agent.generate()
7
+
8
+ The `generate()` method is used to interact with an agent to produce text or structured responses. This method accepts `messages` and an optional `options` object as parameters.
9
+
10
+ ## Parameters
11
+
12
+ ### `messages`
13
+
14
+ The `messages` parameter can be:
15
+
16
+ - A single string
17
+ - An array of strings
18
+ - An array of message objects with `role` and `content` properties
19
+
20
+ The message object structure:
21
+
22
+ ```typescript
23
+ interface Message {
24
+ role: 'system' | 'user' | 'assistant';
25
+ content: string;
26
+ }
27
+ ```
28
+
29
+ ### `options` (Optional)
30
+
31
+ An optional object that can include configuration for output structure, memory management, tool usage, telemetry, and more.
32
+
33
+ <PropertiesTable
34
+ content={[
35
+ {
36
+ name: "abortSignal",
37
+ type: "AbortSignal",
38
+ isOptional: true,
39
+ description: "Signal object that allows you to abort the agent's execution. When the signal is aborted, all ongoing operations will be terminated.",
40
+ },
41
+ {
42
+ name: "context",
43
+ type: "CoreMessage[]",
44
+ isOptional: true,
45
+ description: "Additional context messages to provide to the agent.",
46
+ },
47
+ {
48
+ name: "experimental_output",
49
+ type: "Zod schema | JsonSchema7",
50
+ isOptional: true,
51
+ description: "Enables structured output generation alongside text generation and tool calls. The model will generate responses that conform to the provided schema.",
52
+ },
53
+ {
54
+ name: "instructions",
55
+ type: "string",
56
+ isOptional: true,
57
+ description: "Custom instructions that override the agent's default instructions for this specific generation. Useful for dynamically modifying agent behavior without creating a new agent instance.",
58
+ },
59
+ {
60
+ name: "output",
61
+ type: "Zod schema | JsonSchema7",
62
+ isOptional: true,
63
+ description: "Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.",
64
+ },
65
+ {
66
+ name: "maxSteps",
67
+ type: "number",
68
+ isOptional: true,
69
+ defaultValue: "5",
70
+ description: "Maximum number of execution steps allowed.",
71
+ },
72
+ {
73
+ name: "maxRetries",
74
+ type: "number",
75
+ isOptional: true,
76
+ defaultValue: "2",
77
+ description: "Maximum number of retries. Set to 0 to disable retries.",
78
+ },
79
+ {
80
+ name: "memoryOptions",
81
+ type: "MemoryConfig",
82
+ isOptional: true,
83
+ description: "Configuration options for memory management. See MemoryConfig section below for details.",
84
+ },
85
+ {
86
+ name: "onStepFinish",
87
+ type: "GenerateTextOnStepFinishCallback<any> | never",
88
+ isOptional: true,
89
+ description: "Callback function called after each execution step. Receives step details as a JSON string. Unavailable for structured output",
90
+ },
91
+ {
92
+ name: "resourceId",
93
+ type: "string",
94
+ isOptional: true,
95
+ description: "Identifier for the user or resource interacting with the agent. Must be provided if threadId is provided.",
96
+ },
97
+ {
98
+ name: "telemetry",
99
+ type: "TelemetrySettings",
100
+ isOptional: true,
101
+ description: "Settings for telemetry collection during generation. See TelemetrySettings section below for details.",
102
+ },
103
+ {
104
+ name: "temperature",
105
+ type: "number",
106
+ isOptional: true,
107
+ description: "Controls randomness in the model's output. Higher values (e.g., 0.8) make the output more random, lower values (e.g., 0.2) make it more focused and deterministic.",
108
+ },
109
+ {
110
+ name: "threadId",
111
+ type: "string",
112
+ isOptional: true,
113
+ description: "Identifier for the conversation thread. Allows for maintaining context across multiple interactions. Must be provided if resourceId is provided.",
114
+ },
115
+ {
116
+ name: "toolChoice",
117
+ type: "'auto' | 'none' | 'required' | { type: 'tool'; toolName: string }",
118
+ isOptional: true,
119
+ defaultValue: "'auto'",
120
+ description: "Controls how the agent uses tools during generation.",
121
+ },
122
+ {
123
+ name: "toolsets",
124
+ type: "ToolsetsInput",
125
+ isOptional: true,
126
+ description: "Additional toolsets to make available to the agent during generation.",
127
+ },
128
+ ]}
129
+ />
130
+
131
+ #### MemoryConfig
132
+
133
+ Configuration options for memory management:
134
+
135
+ <PropertiesTable
136
+ content={[
137
+ {
138
+ name: "lastMessages",
139
+ type: "number | false",
140
+ isOptional: true,
141
+ description: "Number of most recent messages to include in context. Set to false to disable.",
142
+ },
143
+ {
144
+ name: "semanticRecall",
145
+ type: "boolean | object",
146
+ isOptional: true,
147
+ description: "Configuration for semantic memory recall. Can be boolean or detailed config.",
148
+ properties: [
149
+ {
150
+ type: "number",
151
+ parameters: [
152
+ {
153
+ name: "topK",
154
+ type: "number",
155
+ isOptional: true,
156
+ description: "Number of most semantically similar messages to retrieve.",
157
+ }
158
+ ]
159
+ },
160
+ {
161
+ type: "number | object",
162
+ parameters: [
163
+ {
164
+ name: "messageRange",
165
+ type: "number | { before: number; after: number }",
166
+ isOptional: true,
167
+ description: "Range of messages to consider for semantic search. Can be a single number or before/after configuration.",
168
+ }
169
+ ]
170
+ }
171
+ ]
172
+ },
173
+ {
174
+ name: "workingMemory",
175
+ type: "object",
176
+ isOptional: true,
177
+ description: "Configuration for working memory.",
178
+ properties: [
179
+ {
180
+ type: "boolean",
181
+ parameters: [
182
+ {
183
+ name: "enabled",
184
+ type: "boolean",
185
+ isOptional: true,
186
+ description: "Whether to enable working memory."
187
+ }
188
+ ]
189
+ },
190
+ {
191
+ type: "string",
192
+ parameters: [
193
+ {
194
+ name: "template",
195
+ type: "string",
196
+ isOptional: true,
197
+ description: "Template to use for working memory.",
198
+ }
199
+ ]
200
+ },
201
+ {
202
+ type: "'text-stream' | 'tool-call'",
203
+ parameters: [
204
+ {
205
+ name: "type",
206
+ type: "'text-stream' | 'tool-call'",
207
+ isOptional: true,
208
+ description: "Type of content to use for working memory.",
209
+ }
210
+ ]
211
+ }
212
+ ]
213
+ },
214
+ {
215
+ name: "threads",
216
+ type: "object",
217
+ isOptional: true,
218
+ description: "Thread-specific memory configuration.",
219
+ properties: [
220
+ {
221
+ type: "boolean",
222
+ parameters: [
223
+ {
224
+ name: "generateTitle",
225
+ type: "boolean",
226
+ isOptional: true,
227
+ description: "Whether to automatically generate titles for new threads.",
228
+ }
229
+ ]
230
+ }
231
+ ]
232
+ }
233
+ ]}
234
+ />
235
+
236
+ #### TelemetrySettings
237
+
238
+ Settings for telemetry collection during generation:
239
+
240
+ <PropertiesTable
241
+ content={[
242
+ {
243
+ name: "isEnabled",
244
+ type: "boolean",
245
+ isOptional: true,
246
+ defaultValue: "false",
247
+ description: "Enable or disable telemetry. Disabled by default while experimental.",
248
+ },
249
+ {
250
+ name: "recordInputs",
251
+ type: "boolean",
252
+ isOptional: true,
253
+ defaultValue: "true",
254
+ description: "Enable or disable input recording. You might want to disable this to avoid recording sensitive information, reduce data transfers, or increase performance.",
255
+ },
256
+ {
257
+ name: "recordOutputs",
258
+ type: "boolean",
259
+ isOptional: true,
260
+ defaultValue: "true",
261
+ description: "Enable or disable output recording. You might want to disable this to avoid recording sensitive information, reduce data transfers, or increase performance.",
262
+ },
263
+ {
264
+ name: "functionId",
265
+ type: "string",
266
+ isOptional: true,
267
+ description: "Identifier for this function. Used to group telemetry data by function.",
268
+ },
269
+ {
270
+ name: "metadata",
271
+ type: "Record<string, AttributeValue>",
272
+ isOptional: true,
273
+ description: "Additional information to include in the telemetry data. AttributeValue can be string, number, boolean, array of these types, or null.",
274
+ },
275
+ {
276
+ name: "tracer",
277
+ type: "Tracer",
278
+ isOptional: true,
279
+ description: "A custom OpenTelemetry tracer instance to use for the telemetry data. See OpenTelemetry documentation for details.",
280
+ }
281
+ ]}
282
+ />
283
+
284
+ ## Returns
285
+
286
+ The return value of the `generate()` method depends on the options provided, specifically the `output` option.
287
+
288
+ ### PropertiesTable for Return Values
289
+
290
+ <PropertiesTable
291
+ content={[
292
+ {
293
+ name: "text",
294
+ type: "string",
295
+ isOptional: true,
296
+ description: "The generated text response. Present when output is 'text' (no schema provided).",
297
+ },
298
+ {
299
+ name: "object",
300
+ type: "object",
301
+ isOptional: true,
302
+ description: "The generated structured response. Present when a schema is provided via `output` or `experimental_output`.",
303
+ },
304
+ {
305
+ name: "toolCalls",
306
+ type: "Array<ToolCall>",
307
+ isOptional: true,
308
+ description: "The tool calls made during the generation process. Present in both text and object modes.",
309
+ }
310
+ ]}
311
+ />
312
+
313
+ #### ToolCall Structure
314
+
315
+ <PropertiesTable
316
+ content={[
317
+ {
318
+ name: "toolName",
319
+ type: "string",
320
+ required: true,
321
+ description: "The name of the tool invoked.",
322
+ },
323
+ {
324
+ name: "args",
325
+ type: "any",
326
+ required: true,
327
+ description: "The arguments passed to the tool.",
328
+ }
329
+ ]}
330
+ />
331
+
332
+ ## Related Methods
333
+
334
+ For real-time streaming responses, see the [`stream()`](./stream.mdx) method documentation.
@@ -0,0 +1,54 @@
1
+ ---
2
+ title: "Reference: getAgent() | Agent Config | Agents | Mastra Docs"
3
+ description: API Reference for getAgent.
4
+ ---
5
+
6
+ # `getAgent()`
7
+
8
+ Retrieve an agent based on the provided configuration
9
+
10
+ ```ts showLineNumbers copy
11
+ async function getAgent({
12
+ connectionId,
13
+ agent,
14
+ apis,
15
+ logger,
16
+ }: {
17
+ connectionId: string;
18
+ agent: Record<string, any>;
19
+ apis: Record<string, IntegrationApi>;
20
+ logger: any;
21
+ }): Promise<(props: { prompt: string }) => Promise<any>> {
22
+ return async (props: { prompt: string }) => {
23
+ return { message: "Hello, world!" };
24
+ };
25
+ }
26
+ ```
27
+
28
+ ## API Signature
29
+
30
+ ### Parameters
31
+
32
+ <PropertiesTable
33
+ content={[
34
+ {
35
+ name: "connectionId",
36
+ type: "string",
37
+ description: "The connection ID to use for the agent's API calls.",
38
+ },
39
+ {
40
+ name: "agent",
41
+ type: "Record<string, any>",
42
+ description: "The agent configuration object.",
43
+ },
44
+ {
45
+ name: "apis",
46
+ type: "Record<string, IntegrationAPI>",
47
+ description: "A map of API names to their respective API objects.",
48
+ },
49
+ ]}
50
+ />
51
+
52
+ ### Returns
53
+
54
+ <PropertiesTable content={[]} />