@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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +17 -0
- package/dist/_tsup-dts-rollup.d.cts +1 -0
- package/dist/_tsup-dts-rollup.d.ts +1 -0
- package/dist/index.cjs +1802 -1800
- package/dist/index.js +1803 -1801
- package/package.json +2 -2
- package/src/client.ts +13 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "0.4.2-alpha.
|
|
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.
|
|
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 {
|
|
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
|
-
|
|
339
|
+
|
|
330
340
|
const mastraTool = createTool({
|
|
331
341
|
id: `${this.name}_${tool.name}`,
|
|
332
342
|
description: tool.description || '',
|
|
333
|
-
inputSchema:
|
|
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 });
|