@mastra/mcp 0.1.0-alpha.43 → 0.1.0-alpha.44
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/CHANGELOG.md +7 -0
- package/dist/_tsup-dts-rollup.d.ts +51 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +70 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { objectInputType } from 'zod';
|
|
3
|
+
import { objectOutputType } from 'zod';
|
|
4
|
+
import { objectUtil } from 'zod';
|
|
5
|
+
import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
6
|
+
import { ZodArray } from 'zod';
|
|
7
|
+
import { ZodObject } from 'zod';
|
|
8
|
+
import { ZodOptional } from 'zod';
|
|
9
|
+
import { ZodString } from 'zod';
|
|
10
|
+
import { ZodTypeAny } from 'zod';
|
|
11
|
+
|
|
12
|
+
declare class MastraMCPClient {
|
|
13
|
+
name: string;
|
|
14
|
+
private transport;
|
|
15
|
+
private client;
|
|
16
|
+
constructor({ name, version, server, capabilities, }: {
|
|
17
|
+
name: string;
|
|
18
|
+
server: StdioServerParameters;
|
|
19
|
+
capabilities?: ClientCapabilities;
|
|
20
|
+
version?: string;
|
|
21
|
+
});
|
|
22
|
+
connect(): Promise<void>;
|
|
23
|
+
disconnect(): Promise<void>;
|
|
24
|
+
resources(): Promise<objectOutputType<objectUtil.extendShape<objectUtil.extendShape< {
|
|
25
|
+
_meta: ZodOptional<ZodObject< {}, "passthrough", ZodTypeAny, objectOutputType< {}, ZodTypeAny, "passthrough">, objectInputType< {}, ZodTypeAny, "passthrough">>>;
|
|
26
|
+
}, {
|
|
27
|
+
nextCursor: ZodOptional<ZodString>;
|
|
28
|
+
}>, {
|
|
29
|
+
resources: ZodArray<ZodObject< {
|
|
30
|
+
uri: ZodString;
|
|
31
|
+
name: ZodString;
|
|
32
|
+
description: ZodOptional<ZodString>;
|
|
33
|
+
mimeType: ZodOptional<ZodString>;
|
|
34
|
+
}, "passthrough", ZodTypeAny, objectOutputType< {
|
|
35
|
+
uri: ZodString;
|
|
36
|
+
name: ZodString;
|
|
37
|
+
description: ZodOptional<ZodString>;
|
|
38
|
+
mimeType: ZodOptional<ZodString>;
|
|
39
|
+
}, ZodTypeAny, "passthrough">, objectInputType< {
|
|
40
|
+
uri: ZodString;
|
|
41
|
+
name: ZodString;
|
|
42
|
+
description: ZodOptional<ZodString>;
|
|
43
|
+
mimeType: ZodOptional<ZodString>;
|
|
44
|
+
}, ZodTypeAny, "passthrough">>, "many">;
|
|
45
|
+
}>, ZodTypeAny, "passthrough">>;
|
|
46
|
+
tools(): Promise<Record<string, any>>;
|
|
47
|
+
}
|
|
48
|
+
export { MastraMCPClient }
|
|
49
|
+
export { MastraMCPClient as MastraMCPClient_alias_1 }
|
|
50
|
+
|
|
51
|
+
export { }
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MastraMCPClient_alias_1 as MastraMCPClient } from './_tsup-dts-rollup.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createTool } from '@mastra/core/tools';
|
|
2
|
+
import { jsonSchemaToModel } from '@mastra/core/utils';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
5
|
+
import { ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
|
|
7
|
+
// src/client.ts
|
|
8
|
+
var MastraMCPClient = class {
|
|
9
|
+
name;
|
|
10
|
+
transport;
|
|
11
|
+
client;
|
|
12
|
+
constructor({
|
|
13
|
+
name,
|
|
14
|
+
version = "1.0.0",
|
|
15
|
+
server,
|
|
16
|
+
capabilities = {}
|
|
17
|
+
}) {
|
|
18
|
+
this.name = name;
|
|
19
|
+
this.transport = new StdioClientTransport(server);
|
|
20
|
+
this.client = new Client(
|
|
21
|
+
{
|
|
22
|
+
name,
|
|
23
|
+
version
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
capabilities
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
async connect() {
|
|
31
|
+
return await this.client.connect(this.transport);
|
|
32
|
+
}
|
|
33
|
+
async disconnect() {
|
|
34
|
+
return await this.client.close();
|
|
35
|
+
}
|
|
36
|
+
async resources() {
|
|
37
|
+
return await this.client.request({ method: "resources/list" }, ListResourcesResultSchema);
|
|
38
|
+
}
|
|
39
|
+
async tools() {
|
|
40
|
+
const { tools } = await this.client.listTools();
|
|
41
|
+
const toolsRes = {};
|
|
42
|
+
tools.forEach((tool) => {
|
|
43
|
+
const s = jsonSchemaToModel(tool.inputSchema);
|
|
44
|
+
const mastraTool = createTool({
|
|
45
|
+
id: `${this.name}_${tool.name}`,
|
|
46
|
+
description: tool.description,
|
|
47
|
+
inputSchema: s,
|
|
48
|
+
execute: async ({ context }) => {
|
|
49
|
+
try {
|
|
50
|
+
const res = await this.client.callTool({
|
|
51
|
+
name: tool.name,
|
|
52
|
+
arguments: context
|
|
53
|
+
});
|
|
54
|
+
return res;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.log("Error calling tool", tool.name);
|
|
57
|
+
console.error(e);
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (tool.name) {
|
|
63
|
+
toolsRes[tool.name] = mastraTool;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return toolsRes;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { MastraMCPClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@modelcontextprotocol/sdk": "^1.1.1",
|
|
22
22
|
"date-fns": "^4.1.0",
|
|
23
23
|
"zod": "^3.24.1",
|
|
24
|
-
"@mastra/core": "^0.2.0-alpha.
|
|
24
|
+
"@mastra/core": "^0.2.0-alpha.102"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@ai-sdk/anthropic": "^1.1.6",
|