@mastra/mcp-docs-server 0.0.1-alpha.1

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 (246) 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%2Fclient-js.md +302 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fcomposio.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +11 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fstabilityai.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +59 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +24 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +12 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  46. package/.docs/organized/changelogs/create-mastra.md +302 -0
  47. package/.docs/organized/changelogs/mastra.md +302 -0
  48. package/.docs/organized/code-examples/agent.md +385 -0
  49. package/.docs/organized/code-examples/ai-sdk-useChat.md +377 -0
  50. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  51. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  52. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  53. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  54. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  55. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  56. package/.docs/organized/code-examples/integrations.md +184 -0
  57. package/.docs/organized/code-examples/mcp-configuration.md +341 -0
  58. package/.docs/organized/code-examples/memory-todo-agent.md +161 -0
  59. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  60. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  61. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  62. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  63. package/.docs/organized/code-examples/quick-start.md +127 -0
  64. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  65. package/.docs/organized/code-examples/weather-agent.md +352 -0
  66. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  67. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  68. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  69. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  70. package/.docs/raw/agents/00-overview.mdx +185 -0
  71. package/.docs/raw/agents/01-agent-memory.mdx +610 -0
  72. package/.docs/raw/agents/02-adding-tools.mdx +224 -0
  73. package/.docs/raw/agents/03-adding-voice.mdx +170 -0
  74. package/.docs/raw/deployment/deployment.mdx +156 -0
  75. package/.docs/raw/deployment/logging-and-tracing.mdx +242 -0
  76. package/.docs/raw/deployment/server.mdx +114 -0
  77. package/.docs/raw/evals/00-overview.mdx +106 -0
  78. package/.docs/raw/evals/01-supported-evals.mdx +31 -0
  79. package/.docs/raw/evals/02-custom-eval.mdx +187 -0
  80. package/.docs/raw/faq/index.mdx +63 -0
  81. package/.docs/raw/frameworks/01-next-js.mdx +238 -0
  82. package/.docs/raw/frameworks/02-ai-sdk.mdx +218 -0
  83. package/.docs/raw/getting-started/installation.mdx +436 -0
  84. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  85. package/.docs/raw/guides/01-chef-michel.mdx +242 -0
  86. package/.docs/raw/guides/02-stock-agent.mdx +182 -0
  87. package/.docs/raw/guides/03-recruiter.mdx +187 -0
  88. package/.docs/raw/index.mdx +22 -0
  89. package/.docs/raw/local-dev/creating-projects.mdx +74 -0
  90. package/.docs/raw/local-dev/integrations.mdx +127 -0
  91. package/.docs/raw/local-dev/mastra-dev.mdx +65 -0
  92. package/.docs/raw/rag/chunking-and-embedding.mdx +128 -0
  93. package/.docs/raw/rag/overview.mdx +85 -0
  94. package/.docs/raw/rag/retrieval.mdx +362 -0
  95. package/.docs/raw/rag/vector-databases.mdx +271 -0
  96. package/.docs/raw/reference/agents/createTool.mdx +190 -0
  97. package/.docs/raw/reference/agents/generate.mdx +327 -0
  98. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  99. package/.docs/raw/reference/agents/stream.mdx +361 -0
  100. package/.docs/raw/reference/cli/build.mdx +48 -0
  101. package/.docs/raw/reference/cli/deploy.mdx +22 -0
  102. package/.docs/raw/reference/cli/dev.mdx +97 -0
  103. package/.docs/raw/reference/cli/init.mdx +43 -0
  104. package/.docs/raw/reference/client-js/agents.mdx +90 -0
  105. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  106. package/.docs/raw/reference/client-js/index.mdx +127 -0
  107. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  108. package/.docs/raw/reference/client-js/memory.mdx +94 -0
  109. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  110. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  111. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  112. package/.docs/raw/reference/client-js/workflows.mdx +137 -0
  113. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  114. package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
  115. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  116. package/.docs/raw/reference/deployer/netlify.mdx +88 -0
  117. package/.docs/raw/reference/deployer/vercel.mdx +97 -0
  118. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  119. package/.docs/raw/reference/evals/bias.mdx +186 -0
  120. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  121. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  122. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  123. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  124. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  125. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  126. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  127. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  128. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  129. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  130. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  131. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  132. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  133. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  134. package/.docs/raw/reference/index.mdx +8 -0
  135. package/.docs/raw/reference/memory/Memory.mdx +186 -0
  136. package/.docs/raw/reference/memory/createThread.mdx +93 -0
  137. package/.docs/raw/reference/memory/getThreadById.mdx +43 -0
  138. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +45 -0
  139. package/.docs/raw/reference/memory/query.mdx +164 -0
  140. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  141. package/.docs/raw/reference/observability/logger.mdx +55 -0
  142. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  143. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  144. package/.docs/raw/reference/observability/providers/index.mdx +15 -0
  145. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  146. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  147. package/.docs/raw/reference/observability/providers/langsmith.mdx +46 -0
  148. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  149. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  150. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  151. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  152. package/.docs/raw/reference/rag/astra.mdx +258 -0
  153. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  154. package/.docs/raw/reference/rag/chunk.mdx +237 -0
  155. package/.docs/raw/reference/rag/document.mdx +129 -0
  156. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  157. package/.docs/raw/reference/rag/extract-params.mdx +72 -0
  158. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  159. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  160. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  161. package/.docs/raw/reference/rag/pg.mdx +477 -0
  162. package/.docs/raw/reference/rag/pinecone.mdx +249 -0
  163. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  164. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  165. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  166. package/.docs/raw/reference/rag/upstash.mdx +198 -0
  167. package/.docs/raw/reference/rag/vectorize.mdx +253 -0
  168. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  169. package/.docs/raw/reference/storage/postgresql.mdx +48 -0
  170. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  171. package/.docs/raw/reference/tools/client.mdx +180 -0
  172. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  173. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  174. package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
  175. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  176. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  177. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  178. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  179. package/.docs/raw/reference/voice/google.mdx +198 -0
  180. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  181. package/.docs/raw/reference/voice/murf.mdx +251 -0
  182. package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
  183. package/.docs/raw/reference/voice/openai.mdx +168 -0
  184. package/.docs/raw/reference/voice/playai.mdx +159 -0
  185. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  186. package/.docs/raw/reference/workflows/after.mdx +88 -0
  187. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  188. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  189. package/.docs/raw/reference/workflows/else.mdx +72 -0
  190. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  191. package/.docs/raw/reference/workflows/if.mdx +107 -0
  192. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  193. package/.docs/raw/reference/workflows/start.mdx +84 -0
  194. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  195. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  196. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  197. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  198. package/.docs/raw/reference/workflows/suspend.mdx +80 -0
  199. package/.docs/raw/reference/workflows/then.mdx +74 -0
  200. package/.docs/raw/reference/workflows/until.mdx +165 -0
  201. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  202. package/.docs/raw/reference/workflows/while.mdx +168 -0
  203. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  204. package/.docs/raw/workflows/00-overview.mdx +168 -0
  205. package/.docs/raw/workflows/control-flow.mdx +712 -0
  206. package/.docs/raw/workflows/dynamic-workflows.mdx +232 -0
  207. package/.docs/raw/workflows/steps.mdx +98 -0
  208. package/.docs/raw/workflows/suspend-and-resume.mdx +196 -0
  209. package/.docs/raw/workflows/variables.mdx +248 -0
  210. package/LICENSE +44 -0
  211. package/README.md +129 -0
  212. package/dist/index.d.ts +3 -0
  213. package/dist/index.js +19 -0
  214. package/dist/prepare-docs/code-examples.d.ts +4 -0
  215. package/dist/prepare-docs/code-examples.js +91 -0
  216. package/dist/prepare-docs/copy-raw.d.ts +1 -0
  217. package/dist/prepare-docs/copy-raw.js +41 -0
  218. package/dist/prepare-docs/index.d.ts +1 -0
  219. package/dist/prepare-docs/index.js +8 -0
  220. package/dist/prepare-docs/package-changes.d.ts +4 -0
  221. package/dist/prepare-docs/package-changes.js +92 -0
  222. package/dist/prepare-docs/prepare.d.ts +1 -0
  223. package/dist/prepare-docs/prepare.js +13 -0
  224. package/dist/sse.d.ts +1 -0
  225. package/dist/sse.js +9 -0
  226. package/dist/stdio.d.ts +1 -0
  227. package/dist/stdio.js +8 -0
  228. package/dist/tools/__tests__/blog.test.d.ts +1 -0
  229. package/dist/tools/__tests__/blog.test.js +48 -0
  230. package/dist/tools/__tests__/changes.test.d.ts +1 -0
  231. package/dist/tools/__tests__/changes.test.js +36 -0
  232. package/dist/tools/__tests__/docs.test.d.ts +1 -0
  233. package/dist/tools/__tests__/docs.test.js +46 -0
  234. package/dist/tools/__tests__/examples.test.d.ts +1 -0
  235. package/dist/tools/__tests__/examples.test.js +52 -0
  236. package/dist/tools/blog.d.ts +15 -0
  237. package/dist/tools/blog.js +73 -0
  238. package/dist/tools/changes.d.ts +11 -0
  239. package/dist/tools/changes.js +69 -0
  240. package/dist/tools/docs.d.ts +11 -0
  241. package/dist/tools/docs.js +176 -0
  242. package/dist/tools/examples.d.ts +11 -0
  243. package/dist/tools/examples.js +61 -0
  244. package/dist/utils.d.ts +6 -0
  245. package/dist/utils.js +9 -0
  246. package/package.json +66 -0
@@ -0,0 +1,180 @@
1
+ ---
2
+ title: "Reference: MastraMCPClient | Tool Discovery | Mastra Docs"
3
+ description: API Reference for MastraMCPClient - A client implementation for the Model Context Protocol.
4
+ ---
5
+
6
+ # MastraMCPClient
7
+
8
+ The `MastraMCPClient` class provides a client implementation for interacting with Model Context Protocol (MCP) servers. It handles connection management, resource discovery, and tool execution through the MCP protocol.
9
+
10
+ ## Constructor
11
+
12
+ Creates a new instance of the MastraMCPClient.
13
+
14
+ ```typescript
15
+ constructor({
16
+ name,
17
+ version = '1.0.0',
18
+ server,
19
+ capabilities = {},
20
+ }: {
21
+ name: string;
22
+ server: StdioServerParameters | SSEClientParameters;
23
+ capabilities?: ClientCapabilities;
24
+ version?: string;
25
+ })
26
+ ```
27
+
28
+ ### Parameters
29
+
30
+ <PropertiesTable
31
+ content={[
32
+ {
33
+ name: "name",
34
+ type: "string",
35
+ description: "The name identifier for this client instance.",
36
+ },
37
+ {
38
+ name: "version",
39
+ type: "string",
40
+ isOptional: true,
41
+ defaultValue: "1.0.0",
42
+ description: "The version of the client.",
43
+ },
44
+ {
45
+ name: "server",
46
+ type: "StdioServerParameters | SSEClientParameters",
47
+ description:
48
+ "Configuration parameters for either a stdio server connection or an SSE server connection.",
49
+ },
50
+ {
51
+ name: "capabilities",
52
+ type: "ClientCapabilities",
53
+ isOptional: true,
54
+ defaultValue: "{}",
55
+ description: "Optional capabilities configuration for the client.",
56
+ },
57
+ ]}
58
+ />
59
+
60
+ ## Methods
61
+
62
+ ### connect()
63
+
64
+ Establishes a connection with the MCP server.
65
+
66
+ ```typescript
67
+ async connect(): Promise<void>
68
+ ```
69
+
70
+ ### disconnect()
71
+
72
+ Closes the connection with the MCP server.
73
+
74
+ ```typescript
75
+ async disconnect(): Promise<void>
76
+ ```
77
+
78
+ ### resources()
79
+
80
+ Retrieves the list of available resources from the server.
81
+
82
+ ```typescript
83
+ async resources(): Promise<ListResourcesResult>
84
+ ```
85
+
86
+ ### tools()
87
+
88
+ Fetches and initializes available tools from the server, converting them into Mastra-compatible tool formats.
89
+
90
+ ```typescript
91
+ async tools(): Promise<Record<string, Tool>>
92
+ ```
93
+
94
+ Returns an object mapping tool names to their corresponding Mastra tool implementations.
95
+
96
+ ## Examples
97
+
98
+ ### Using with Mastra Agent
99
+
100
+ #### Example with Stdio Server
101
+
102
+ ```typescript
103
+ import { Agent } from "@mastra/core/agent";
104
+ import { MastraMCPClient } from "@mastra/mcp";
105
+ import { openai } from "@ai-sdk/openai";
106
+
107
+ // Initialize the MCP client using mcp/fetch as an example https://hub.docker.com/r/mcp/fetch
108
+ // Visit https://github.com/docker/mcp-servers for other reference docker mcp servers
109
+ const fetchClient = new MastraMCPClient({
110
+ name: "fetch",
111
+ server: {
112
+ command: "docker",
113
+ args: ["run", "-i", "--rm", "mcp/fetch"],
114
+ },
115
+ });
116
+
117
+ // Create a Mastra Agent
118
+ const agent = new Agent({
119
+ name: "Fetch agent",
120
+ instructions:
121
+ "You are able to fetch data from URLs on demand and discuss the response data with the user.",
122
+ model: openai("gpt-4o-mini"),
123
+ });
124
+
125
+ try {
126
+ // Connect to the MCP server
127
+ await fetchClient.connect();
128
+
129
+ // Gracefully handle process exits so the docker subprocess is cleaned up
130
+ process.on("exit", () => {
131
+ fetchClient.disconnect();
132
+ });
133
+
134
+ // Get available tools
135
+ const tools = await fetchClient.tools();
136
+
137
+ // Use the agent with the MCP tools
138
+ const response = await agent.generate(
139
+ "Tell me about mastra.ai/docs. Tell me generally what this page is and the content it includes.",
140
+ {
141
+ toolsets: {
142
+ fetch: tools,
143
+ },
144
+ },
145
+ );
146
+
147
+ console.log("\n\n" + response.text);
148
+ } catch (error) {
149
+ console.error("Error:", error);
150
+ } finally {
151
+ // Always disconnect when done
152
+ await fetchClient.disconnect();
153
+ }
154
+ ```
155
+
156
+ #### Example with SSE Server
157
+
158
+ ```typescript
159
+ // Initialize the MCP client using an SSE server
160
+ const sseClient = new MastraMCPClient({
161
+ name: "sse-client",
162
+ server: {
163
+ url: new URL("https://your-mcp-server.com/sse"),
164
+ // Optional fetch request configuration
165
+ requestInit: {
166
+ headers: {
167
+ Authorization: "Bearer your-token",
168
+ },
169
+ },
170
+ },
171
+ });
172
+
173
+ // The rest of the usage is identical to the stdio example
174
+ ```
175
+
176
+ ## Related Information
177
+
178
+ - For managing multiple MCP servers in your application, see the [MCPConfiguration documentation](./configuration)
179
+ - For more details about the Model Context Protocol, see the [@modelcontextprotocol/sdk documentation](https://github.com/modelcontextprotocol/typescript-sdk).
180
+
@@ -0,0 +1,141 @@
1
+ ---
2
+ title: "Reference: createDocumentChunkerTool() | Tools | Mastra Docs"
3
+ description: Documentation for the Document Chunker Tool in Mastra, which splits documents into smaller chunks for efficient processing and retrieval.
4
+ ---
5
+
6
+ # createDocumentChunkerTool()
7
+
8
+ The `createDocumentChunkerTool()` function creates a tool for splitting documents into smaller chunks for efficient processing and retrieval. It supports different chunking strategies and configurable parameters.
9
+
10
+ ## Basic Usage
11
+
12
+ ```typescript
13
+ import { createDocumentChunkerTool, MDocument } from "@mastra/rag";
14
+
15
+ const document = new MDocument({
16
+ text: "Your document content here...",
17
+ metadata: { source: "user-manual" }
18
+ });
19
+
20
+ const chunker = createDocumentChunkerTool({
21
+ doc: document,
22
+ params: {
23
+ strategy: "recursive",
24
+ size: 512,
25
+ overlap: 50,
26
+ separator: "\n"
27
+ }
28
+ });
29
+
30
+ const { chunks } = await chunker.execute();
31
+ ```
32
+
33
+ ## Parameters
34
+
35
+ <PropertiesTable
36
+ content={[
37
+ {
38
+ name: "doc",
39
+ type: "MDocument",
40
+ description: "The document to be chunked",
41
+ isOptional: false,
42
+ },
43
+ {
44
+ name: "params",
45
+ type: "ChunkParams",
46
+ description: "Configuration parameters for chunking",
47
+ isOptional: true,
48
+ defaultValue: "Default chunking parameters",
49
+ }
50
+ ]}
51
+ />
52
+
53
+ ### ChunkParams
54
+
55
+ <PropertiesTable
56
+ content={[
57
+ {
58
+ name: "strategy",
59
+ type: "'recursive'",
60
+ description: "The chunking strategy to use",
61
+ isOptional: true,
62
+ defaultValue: "'recursive'",
63
+ },
64
+ {
65
+ name: "size",
66
+ type: "number",
67
+ description: "Target size of each chunk in tokens/characters",
68
+ isOptional: true,
69
+ defaultValue: "512",
70
+ },
71
+ {
72
+ name: "overlap",
73
+ type: "number",
74
+ description: "Number of overlapping tokens/characters between chunks",
75
+ isOptional: true,
76
+ defaultValue: "50",
77
+ },
78
+ {
79
+ name: "separator",
80
+ type: "string",
81
+ description: "Character(s) to use as chunk separator",
82
+ isOptional: true,
83
+ defaultValue: "'\\n'",
84
+ }
85
+ ]}
86
+ />
87
+
88
+ ## Returns
89
+
90
+ <PropertiesTable
91
+ content={[
92
+ {
93
+ name: "chunks",
94
+ type: "DocumentChunk[]",
95
+ description: "Array of document chunks with their content and metadata",
96
+ }
97
+ ]}
98
+ />
99
+
100
+ ## Example with Custom Parameters
101
+
102
+ ```typescript
103
+ const technicalDoc = new MDocument({
104
+ text: longDocumentContent,
105
+ metadata: {
106
+ type: "technical",
107
+ version: "1.0"
108
+ }
109
+ });
110
+
111
+ const chunker = createDocumentChunkerTool({
112
+ doc: technicalDoc,
113
+ params: {
114
+ strategy: "recursive",
115
+ size: 1024, // Larger chunks
116
+ overlap: 100, // More overlap
117
+ separator: "\n\n" // Split on double newlines
118
+ }
119
+ });
120
+
121
+ const { chunks } = await chunker.execute();
122
+
123
+ // Process the chunks
124
+ chunks.forEach((chunk, index) => {
125
+ console.log(`Chunk ${index + 1} length: ${chunk.content.length}`);
126
+ });
127
+ ```
128
+
129
+ ## Tool Details
130
+
131
+ The chunker is created as a Mastra tool with the following properties:
132
+
133
+ - **Tool ID**: `Document Chunker {strategy} {size}`
134
+ - **Description**: `Chunks document using {strategy} strategy with size {size} and {overlap} overlap`
135
+ - **Input Schema**: Empty object (no additional inputs required)
136
+ - **Output Schema**: Object containing the chunks array
137
+
138
+ ## Related
139
+
140
+ - [MDocument](../rag/document.mdx)
141
+ - [createVectorQueryTool](./vector-query-tool)
@@ -0,0 +1,154 @@
1
+ ---
2
+ title: "Reference: createGraphRAGTool() | RAG | Mastra Tools Docs"
3
+ description: Documentation for the Graph RAG Tool in Mastra, which enhances RAG by building a graph of semantic relationships between documents.
4
+ ---
5
+
6
+ # createGraphRAGTool()
7
+
8
+ The `createGraphRAGTool()` creates a tool that enhances RAG by building a graph of semantic relationships between documents. It uses the `GraphRAG` system under the hood to provide graph-based retrieval, finding relevant content through both direct similarity and connected relationships.
9
+
10
+ ## Usage Example
11
+
12
+ ```typescript
13
+ import { openai } from "@ai-sdk/openai";
14
+ import { createGraphRAGTool } from "@mastra/rag";
15
+
16
+ const graphTool = createGraphRAGTool({
17
+ vectorStoreName: "pinecone",
18
+ indexName: "docs",
19
+ model: openai.embedding('text-embedding-3-small'),
20
+ graphOptions: {
21
+ dimension: 1536,
22
+ threshold: 0.7,
23
+ randomWalkSteps: 100,
24
+ restartProb: 0.15
25
+ }
26
+ });
27
+ ```
28
+
29
+ ## Parameters
30
+
31
+ <PropertiesTable
32
+ content={[
33
+ {
34
+ name: "vectorStoreName",
35
+ type: "string",
36
+ description: "Name of the vector store to query",
37
+ isOptional: false,
38
+ },
39
+ {
40
+ name: "indexName",
41
+ type: "string",
42
+ description: "Name of the index within the vector store",
43
+ isOptional: false,
44
+ },
45
+ {
46
+ name: "model",
47
+ type: "EmbeddingModel",
48
+ description: "Embedding model to use for vector search",
49
+ isOptional: false,
50
+ },
51
+ {
52
+ name: "graphOptions",
53
+ type: "GraphOptions",
54
+ description: "Configuration for the graph-based retrieval",
55
+ isOptional: true,
56
+ defaultValue: "Default graph options",
57
+ },
58
+ {
59
+ name: "description",
60
+ type: "string",
61
+ description: "Custom description for the tool. By default: 'Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns'",
62
+ isOptional: true,
63
+ }
64
+ ]}
65
+ />
66
+
67
+ ### GraphOptions
68
+
69
+ <PropertiesTable
70
+ content={[
71
+ {
72
+ name: "dimension",
73
+ type: "number",
74
+ description: "Dimension of the embedding vectors",
75
+ isOptional: true,
76
+ defaultValue: "1536",
77
+ },
78
+ {
79
+ name: "threshold",
80
+ type: "number",
81
+ description: "Similarity threshold for creating edges between nodes (0-1)",
82
+ isOptional: true,
83
+ defaultValue: "0.7",
84
+ },
85
+ {
86
+ name: "randomWalkSteps",
87
+ type: "number",
88
+ description: "Number of steps in random walk for graph traversal",
89
+ isOptional: true,
90
+ defaultValue: "100",
91
+ },
92
+ {
93
+ name: "restartProb",
94
+ type: "number",
95
+ description: "Probability of restarting random walk from query node",
96
+ isOptional: true,
97
+ defaultValue: "0.15",
98
+ }
99
+ ]}
100
+ />
101
+
102
+ ## Returns
103
+ The tool returns an object with:
104
+
105
+ <PropertiesTable
106
+ content={[
107
+ {
108
+ name: "relevantContext",
109
+ type: "string",
110
+ description: "Combined text from the most relevant document chunks, retrieved using graph-based ranking",
111
+ }
112
+ ]}
113
+ />
114
+
115
+ ## Default Tool Description
116
+
117
+ The default description focuses on:
118
+ - Analyzing relationships between documents
119
+ - Finding patterns and connections
120
+ - Answering complex queries
121
+
122
+ ## Advanced Example
123
+
124
+ ```typescript
125
+ const graphTool = createGraphRAGTool({
126
+ vectorStoreName: "pinecone",
127
+ indexName: "docs",
128
+ model: openai.embedding('text-embedding-3-small'),
129
+ graphOptions: {
130
+ dimension: 1536,
131
+ threshold: 0.8, // Higher similarity threshold
132
+ randomWalkSteps: 200, // More exploration steps
133
+ restartProb: 0.2 // Higher restart probability
134
+ }
135
+ });
136
+ ```
137
+
138
+ ## Example with Custom Description
139
+
140
+ ```typescript
141
+ const graphTool = createGraphRAGTool({
142
+ vectorStoreName: "pinecone",
143
+ indexName: "docs",
144
+ model: openai.embedding('text-embedding-3-small'),
145
+ description: "Analyze document relationships to find complex patterns and connections in our company's historical data"
146
+ });
147
+ ```
148
+
149
+ This example shows how to customize the tool description for a specific use case while maintaining its core purpose of relationship analysis.
150
+
151
+ ## Related
152
+
153
+ - [createVectorQueryTool](./vector-query-tool)
154
+ - [GraphRAG](../rag/graph-rag)
@@ -0,0 +1,206 @@
1
+ ---
2
+ title: "Reference: MCPConfiguration | Tool Management | Mastra Docs"
3
+ description: API Reference for MCPConfiguration - A class for managing multiple Model Context Protocol servers and their tools.
4
+ ---
5
+
6
+ # MCPConfiguration
7
+
8
+ The `MCPConfiguration` class provides a way to manage multiple MCP server connections and their tools in a Mastra application. It handles connection lifecycle, tool namespacing, and provides convenient access to tools across all configured servers.
9
+
10
+ ## Constructor
11
+
12
+ Creates a new instance of the MCPConfiguration class.
13
+
14
+ ```typescript
15
+ constructor({
16
+ id?: string;
17
+ servers: Record<string, MastraMCPServerDefinition>
18
+ }: {
19
+ servers: {
20
+ [serverName: string]: {
21
+ // For stdio-based servers
22
+ command?: string;
23
+ args?: string[];
24
+ env?: Record<string, string>;
25
+ // For SSE-based servers
26
+ url?: URL;
27
+ requestInit?: RequestInit;
28
+ }
29
+ }
30
+ })
31
+ ```
32
+
33
+ ### Parameters
34
+
35
+ <PropertiesTable
36
+ content={[
37
+ {
38
+ name: "id",
39
+ type: "string",
40
+ description:
41
+ "Optional unique identifier for the configuration instance. Use this to prevent memory leaks when creating multiple instances with identical configurations.",
42
+ },
43
+ {
44
+ name: "servers",
45
+ type: "Record<string, MastraMCPServerDefinition>",
46
+ description:
47
+ "A map of server configurations, where each key is a unique server identifier and the value is the server configuration.",
48
+ },
49
+ ]}
50
+ />
51
+
52
+ ## Methods
53
+
54
+ ### getTools()
55
+
56
+ Retrieves all tools from all configured servers, with tool names namespaced by their server name (in the format `serverName_toolName`) to prevent conflicts.
57
+ Intended to be passed onto an Agent definition.
58
+
59
+ ```ts
60
+ new Agent({ tools: await mcp.getTools() });
61
+ ```
62
+
63
+ ### getToolsets()
64
+
65
+ Returns an object mapping namespaced tool names (in the format `serverName.toolName`) to their tool implementations.
66
+ Intended to be passed dynamically into the generate or stream method.
67
+
68
+ ```typescript
69
+ const res = await agent.stream(prompt, {
70
+ toolsets: await mcp.getToolsets(),
71
+ });
72
+ ```
73
+
74
+ ## Examples
75
+
76
+ ### Basic Usage
77
+
78
+ ```typescript
79
+ import { MCPConfiguration } from "@mastra/mcp";
80
+ import { Agent } from "@mastra/core/agent";
81
+ import { openai } from "@ai-sdk/openai";
82
+
83
+ const mcp = new MCPConfiguration({
84
+ servers: {
85
+ stockPrice: {
86
+ command: "npx",
87
+ args: ["tsx", "stock-price.ts"],
88
+ env: {
89
+ API_KEY: "your-api-key",
90
+ },
91
+ },
92
+ weather: {
93
+ url: new URL("http://localhost:8080/sse"),
94
+ },
95
+ },
96
+ });
97
+
98
+ // Create an agent with access to all tools
99
+ const agent = new Agent({
100
+ name: "Multi-tool Agent",
101
+ instructions: "You have access to multiple tool servers.",
102
+ model: openai("gpt-4"),
103
+ tools: await mcp.getTools(),
104
+ });
105
+ ```
106
+
107
+ ### Using Toolsets in generate() or stream()
108
+
109
+ ```typescript
110
+ import { Agent } from "@mastra/core/agent";
111
+ import { MCPConfiguration } from "@mastra/mcp";
112
+ import { openai } from "@ai-sdk/openai";
113
+
114
+ // Create the agent first, without any tools
115
+ const agent = new Agent({
116
+ name: "Multi-tool Agent",
117
+ instructions: "You help users check stocks and weather.",
118
+ model: openai("gpt-4"),
119
+ });
120
+
121
+ // Later, configure MCP with user-specific settings
122
+ const mcp = new MCPConfiguration({
123
+ servers: {
124
+ stockPrice: {
125
+ command: "npx",
126
+ args: ["tsx", "stock-price.ts"],
127
+ env: {
128
+ API_KEY: "user-123-api-key",
129
+ },
130
+ },
131
+ weather: {
132
+ url: new URL("http://localhost:8080/sse"),
133
+ requestInit: {
134
+ headers: {
135
+ Authorization: `Bearer user-123-token`,
136
+ },
137
+ },
138
+ },
139
+ },
140
+ });
141
+
142
+ // Pass all toolsets to stream() or generate()
143
+ const response = await agent.stream(
144
+ "How is AAPL doing and what is the weather?",
145
+ {
146
+ toolsets: await mcp.getToolsets(),
147
+ },
148
+ );
149
+ ```
150
+
151
+ ## Resource Management
152
+
153
+ The `MCPConfiguration` class includes built-in memory leak prevention for managing multiple instances:
154
+
155
+ 1. Creating multiple instances with identical configurations without an `id` will throw an error to prevent memory leaks
156
+ 2. If you need multiple instances with identical configurations, provide a unique `id` for each instance
157
+ 3. Call `await configuration.disconnect()` before recreating an instance with the same configuration
158
+ 4. If you only need one instance, consider moving the configuration to a higher scope to avoid recreation
159
+
160
+ For example, if you try to create multiple instances with the same configuration without an `id`:
161
+
162
+ ```typescript
163
+ // First instance - OK
164
+ const mcp1 = new MCPConfiguration({
165
+ servers: {
166
+ /* ... */
167
+ },
168
+ });
169
+
170
+ // Second instance with same config - Will throw an error
171
+ const mcp2 = new MCPConfiguration({
172
+ servers: {
173
+ /* ... */
174
+ },
175
+ });
176
+
177
+ // To fix, either:
178
+ // 1. Add unique IDs
179
+ const mcp3 = new MCPConfiguration({
180
+ id: "instance-1",
181
+ servers: {
182
+ /* ... */
183
+ },
184
+ });
185
+
186
+ // 2. Or disconnect before recreating
187
+ await mcp1.disconnect();
188
+ const mcp4 = new MCPConfiguration({
189
+ servers: {
190
+ /* ... */
191
+ },
192
+ });
193
+ ```
194
+
195
+ ## Server Lifecycle
196
+
197
+ MCPConfiguration handles server connections gracefully:
198
+
199
+ 1. Automatic connection management for multiple servers
200
+ 2. Graceful server shutdown to prevent error messages during development
201
+ 3. Proper cleanup of resources when disconnecting
202
+
203
+ ## Related Information
204
+
205
+ - For details about individual MCP client configuration, see the [MastraMCPClient documentation](./client)
206
+ - For more about the Model Context Protocol, see the [@modelcontextprotocol/sdk documentation](https://github.com/modelcontextprotocol/typescript-sdk)