@mastra/mcp 0.4.2-alpha.1 → 0.4.2-alpha.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp",
3
- "version": "0.4.2-alpha.1",
3
+ "version": "0.4.2-alpha.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "exit-hook": "^4.0.0",
28
28
  "fast-deep-equal": "^3.1.3",
29
29
  "uuid": "^11.1.0",
30
- "@mastra/core": "^0.9.2-alpha.1"
30
+ "@mastra/core": "^0.9.2-alpha.3"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@ai-sdk/anthropic": "^1.1.15",
package/src/client.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MastraBase } from '@mastra/core/base';
2
2
  import { createTool } from '@mastra/core/tools';
3
- import { jsonSchemaToModel } from '@mastra/core/utils';
3
+ import { isZodType, resolveSerializedZodOutput } from '@mastra/core/utils';
4
4
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
5
5
  import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
6
6
  import type { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
@@ -14,6 +14,8 @@ import type { ClientCapabilities, LoggingLevel } from '@modelcontextprotocol/sdk
14
14
  import { CallToolResultSchema, ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
15
15
 
16
16
  import { asyncExitHook, gracefulExit } from 'exit-hook';
17
+ import jsonSchemaToZod from 'json-schema-to-zod';
18
+ import type { JsonSchema } from 'json-schema-to-zod';
17
19
  import { z } from 'zod';
18
20
 
19
21
  // Re-export MCP SDK LoggingLevel for convenience
@@ -320,17 +322,25 @@ export class InternalMastraMCPClient extends MastraBase {
320
322
  });
321
323
  }
322
324
 
325
+ private convertInputSchema(
326
+ inputSchema: Awaited<ReturnType<Client['listTools']>>['tools'][0]['inputSchema'] | JsonSchema,
327
+ ): z.ZodType {
328
+ return isZodType(inputSchema)
329
+ ? inputSchema
330
+ : resolveSerializedZodOutput(jsonSchemaToZod(inputSchema as JsonSchema));
331
+ }
332
+
323
333
  async tools() {
324
334
  this.log('debug', `Requesting tools from MCP server`);
325
335
  const { tools } = await this.client.listTools({ timeout: this.timeout });
326
336
  const toolsRes: Record<string, any> = {};
327
337
  tools.forEach(tool => {
328
338
  this.log('debug', `Processing tool: ${tool.name}`);
329
- const s = jsonSchemaToModel(tool.inputSchema);
339
+
330
340
  const mastraTool = createTool({
331
341
  id: `${this.name}_${tool.name}`,
332
342
  description: tool.description || '',
333
- inputSchema: s,
343
+ inputSchema: this.convertInputSchema(tool.inputSchema),
334
344
  execute: async ({ context }) => {
335
345
  try {
336
346
  this.log('debug', `Executing tool: ${tool.name}`, { toolArgs: context });