@mastra/mcp 0.4.2-alpha.0 → 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 +8 -8
- package/CHANGELOG.md +25 -0
- package/dist/_tsup-dts-rollup.d.cts +13 -9
- package/dist/_tsup-dts-rollup.d.ts +13 -9
- package/dist/index.cjs +1818 -1816
- package/dist/index.js +1807 -1805
- package/package.json +2 -2
- package/src/client.ts +31 -19
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
|
|
@@ -89,13 +91,20 @@ function convertLogLevelToLoggerMethod(level: LoggingLevel): 'debug' | 'info' |
|
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
export type InternalMastraMCPClientOptions = {
|
|
95
|
+
name: string;
|
|
96
|
+
server: MastraMCPServerDefinition;
|
|
97
|
+
capabilities?: ClientCapabilities;
|
|
98
|
+
version?: string;
|
|
99
|
+
timeout?: number;
|
|
100
|
+
};
|
|
101
|
+
|
|
92
102
|
export class InternalMastraMCPClient extends MastraBase {
|
|
93
103
|
name: string;
|
|
94
104
|
private client: Client;
|
|
95
105
|
private readonly timeout: number;
|
|
96
106
|
private logHandler?: LogHandler;
|
|
97
107
|
private enableServerLogs?: boolean;
|
|
98
|
-
private static hasWarned = false;
|
|
99
108
|
private serverConfig: MastraMCPServerDefinition;
|
|
100
109
|
private transport?: Transport;
|
|
101
110
|
|
|
@@ -105,21 +114,8 @@ export class InternalMastraMCPClient extends MastraBase {
|
|
|
105
114
|
server,
|
|
106
115
|
capabilities = {},
|
|
107
116
|
timeout = DEFAULT_REQUEST_TIMEOUT_MSEC,
|
|
108
|
-
}: {
|
|
109
|
-
name: string;
|
|
110
|
-
server: MastraMCPServerDefinition;
|
|
111
|
-
capabilities?: ClientCapabilities;
|
|
112
|
-
version?: string;
|
|
113
|
-
timeout?: number;
|
|
114
|
-
}) {
|
|
117
|
+
}: InternalMastraMCPClientOptions) {
|
|
115
118
|
super({ name: 'MastraMCPClient' });
|
|
116
|
-
if (!InternalMastraMCPClient.hasWarned) {
|
|
117
|
-
// eslint-disable-next-line no-console
|
|
118
|
-
console.warn(
|
|
119
|
-
'[DEPRECATION] MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead.',
|
|
120
|
-
);
|
|
121
|
-
InternalMastraMCPClient.hasWarned = true;
|
|
122
|
-
}
|
|
123
119
|
this.name = name;
|
|
124
120
|
this.timeout = timeout;
|
|
125
121
|
this.logHandler = server.logger;
|
|
@@ -326,17 +322,25 @@ export class InternalMastraMCPClient extends MastraBase {
|
|
|
326
322
|
});
|
|
327
323
|
}
|
|
328
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
|
+
|
|
329
333
|
async tools() {
|
|
330
334
|
this.log('debug', `Requesting tools from MCP server`);
|
|
331
335
|
const { tools } = await this.client.listTools({ timeout: this.timeout });
|
|
332
336
|
const toolsRes: Record<string, any> = {};
|
|
333
337
|
tools.forEach(tool => {
|
|
334
338
|
this.log('debug', `Processing tool: ${tool.name}`);
|
|
335
|
-
|
|
339
|
+
|
|
336
340
|
const mastraTool = createTool({
|
|
337
341
|
id: `${this.name}_${tool.name}`,
|
|
338
342
|
description: tool.description || '',
|
|
339
|
-
inputSchema:
|
|
343
|
+
inputSchema: this.convertInputSchema(tool.inputSchema),
|
|
340
344
|
execute: async ({ context }) => {
|
|
341
345
|
try {
|
|
342
346
|
this.log('debug', `Executing tool: ${tool.name}`, { toolArgs: context });
|
|
@@ -374,4 +378,12 @@ export class InternalMastraMCPClient extends MastraBase {
|
|
|
374
378
|
/**
|
|
375
379
|
* @deprecated MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead.
|
|
376
380
|
*/
|
|
377
|
-
|
|
381
|
+
|
|
382
|
+
export class MastraMCPClient extends InternalMastraMCPClient {
|
|
383
|
+
constructor(args: InternalMastraMCPClientOptions) {
|
|
384
|
+
super(args);
|
|
385
|
+
this.logger.warn(
|
|
386
|
+
'[DEPRECATION] MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead.',
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
}
|