@mastra/mcp 1.16.0-alpha.1 → 1.16.0

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.
@@ -244,6 +244,57 @@ const res = await agent.stream(prompt, {
244
244
  })
245
245
  ```
246
246
 
247
+ ### `listToolDefinitions()`
248
+
249
+ Returns every server's tools as plain, serializable definitions, grouped by server name and keyed by the server's own tool name (without the `serverName_toolName` namespacing that `listTools()` applies).
250
+
251
+ Unlike `listTools()`, the result contains no functions or references to a live client, so it can be passed through `JSON.stringify` and cached in Redis, a database, or a build artifact. Each definition holds the data from the MCP `tools/list` response (name, description, input schema, output schema, annotations, and `_meta`), plus the server name, version, and instructions captured at discovery time.
252
+
253
+ ```typescript
254
+ const definitions = await mcp.listToolDefinitions()
255
+
256
+ await cache.set('mcp-tools', JSON.stringify(definitions))
257
+ ```
258
+
259
+ ### `listToolDefinitionsWithErrors()`
260
+
261
+ Like `listToolDefinitions()`, but also returns per-server errors for servers that failed to connect. Use this when caching a catalog, so you don't persist a partial manifest that omits a server that was down at discovery time.
262
+
263
+ ```typescript
264
+ const { definitions, errors } = await mcp.listToolDefinitionsWithErrors()
265
+
266
+ if (Object.keys(errors).length === 0) {
267
+ await cache.set('mcp-tools', JSON.stringify(definitions))
268
+ }
269
+ ```
270
+
271
+ ### `toolFromDefinition()`
272
+
273
+ Rebuilds a single executable tool from a cached definition. No connection is opened here. The client connects lazily, the first time the tool is executed.
274
+
275
+ The returned tool behaves exactly like one from `listTools()`, with the same strict-mode metadata, approval policy, structured content handling, tool error handling, and reconnect behavior.
276
+
277
+ ```typescript
278
+ const definitions = JSON.parse(await cache.get('mcp-tools'))
279
+
280
+ const tool = await mcp.toolFromDefinition({
281
+ serverName: 'weather',
282
+ definition: definitions.weather.getForecast,
283
+ })
284
+ ```
285
+
286
+ ### `toolsFromDefinitions()`
287
+
288
+ Rebuilds an entire cached catalog into a namespaced tool map, without connecting. This is the cached counterpart to `listTools()`. It produces the same `serverName_toolName` keys, so you can reconstruct an agent's tool map on a cold start, and connections only open for the servers whose tools are actually called.
289
+
290
+ Servers present in the catalog but no longer configured on the client are skipped, so a stale cached manifest degrades gracefully.
291
+
292
+ ```typescript
293
+ const definitions = JSON.parse(await cache.get('mcp-tools'))
294
+
295
+ new Agent({ id: 'agent', tools: await mcp.toolsFromDefinitions({ definitions }) })
296
+ ```
297
+
247
298
  ### `getServerInstructions()`
248
299
 
249
300
  Returns the instructions currently known for each configured MCP server. Servers that haven't connected yet, or don't advertise instructions, return `undefined`.
@@ -929,7 +929,7 @@ Notification methods (`resources.notifyListChanged()`, `prompts.notifyListChange
929
929
 
930
930
  ## Examples
931
931
 
932
- For practical examples of setting up and deploying an MCPServer, see the [Publishing an MCP Server guide](https://mastra.ai/guides/guide/publishing-mcp-server).
932
+ For a practical example of packaging a stdio server, see [Publish a stdio server package](https://mastra.ai/docs/mcp/overview).
933
933
 
934
934
  The example at the beginning of this page also demonstrates how to instantiate `MCPServer` with both tools and agents.
935
935