@mastra/mcp 0.0.1-alpha.9 → 0.1.0-alpha.29

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 CHANGED
@@ -1,5 +1,163 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 0.1.0-alpha.29
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [7365b6c]
8
+ - @mastra/core@0.2.0-alpha.87
9
+
10
+ ## 0.1.0-alpha.28
11
+
12
+ ### Minor Changes
13
+
14
+ - 5916f9d: Update deps from fixed to ^
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [6fa4bd2]
19
+ - Updated dependencies [e2e76de]
20
+ - Updated dependencies [7f24c29]
21
+ - Updated dependencies [67637ba]
22
+ - Updated dependencies [04f3171]
23
+ - @mastra/core@0.2.0-alpha.86
24
+
25
+ ## 0.0.1-alpha.27
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [e9d1b47]
30
+ - @mastra/core@0.2.0-alpha.85
31
+
32
+ ## 0.0.1-alpha.26
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [2f17a5f]
37
+ - Updated dependencies [cb290ee]
38
+ - Updated dependencies [b4d7416]
39
+ - Updated dependencies [38b7f66]
40
+ - @mastra/core@0.2.0-alpha.84
41
+
42
+ ## 0.0.1-alpha.25
43
+
44
+ ### Patch Changes
45
+
46
+ - 9625602: Use mastra core splitted bundles in other packages
47
+ - Updated dependencies [30322ce]
48
+ - Updated dependencies [78eec7c]
49
+ - Updated dependencies [9625602]
50
+ - Updated dependencies [8769a62]
51
+ - @mastra/core@0.2.0-alpha.83
52
+
53
+ ## 0.0.1-alpha.24
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [73d112c]
58
+ - @mastra/core@0.1.27-alpha.82
59
+
60
+ ## 0.0.1-alpha.23
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies [9fb3039]
65
+ - @mastra/core@0.1.27-alpha.81
66
+
67
+ ## 0.0.1-alpha.22
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies [327ece7]
72
+ - @mastra/core@0.1.27-alpha.80
73
+
74
+ ## 0.0.1-alpha.21
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [21fe536]
79
+ - @mastra/core@0.1.27-alpha.79
80
+
81
+ ## 0.0.1-alpha.20
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies [685108a]
86
+ - Updated dependencies [685108a]
87
+ - @mastra/core@0.1.27-alpha.78
88
+
89
+ ## 0.0.1-alpha.19
90
+
91
+ ### Patch Changes
92
+
93
+ - 8468b7f: @mastra/mcp tsup bundling
94
+ - Updated dependencies [8105fae]
95
+ - @mastra/core@0.1.27-alpha.77
96
+
97
+ ## 0.0.1-alpha.18
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [ae7bf94]
102
+ - Updated dependencies [ae7bf94]
103
+ - @mastra/core@0.1.27-alpha.76
104
+
105
+ ## 0.0.1-alpha.17
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies [23dcb23]
110
+ - @mastra/core@0.1.27-alpha.75
111
+
112
+ ## 0.0.1-alpha.16
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies [7b87567]
117
+ - @mastra/core@0.1.27-alpha.74
118
+
119
+ ## 0.0.1-alpha.15
120
+
121
+ ### Patch Changes
122
+
123
+ - Updated dependencies [3427b95]
124
+ - @mastra/core@0.1.27-alpha.73
125
+
126
+ ## 0.0.1-alpha.14
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies [e4d4ede]
131
+ - Updated dependencies [06b2c0a]
132
+ - @mastra/core@0.1.27-alpha.72
133
+
134
+ ## 0.0.1-alpha.13
135
+
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [d9c8dd0]
139
+ - @mastra/core@0.1.27-alpha.71
140
+
141
+ ## 0.0.1-alpha.12
142
+
143
+ ### Patch Changes
144
+
145
+ - bdaf834: publish packages
146
+
147
+ ## 0.0.1-alpha.11
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies [dd6d87f]
152
+ - Updated dependencies [04434b6]
153
+ - @mastra/core@0.1.27-alpha.70
154
+
155
+ ## 0.0.1-alpha.10
156
+
157
+ ### Patch Changes
158
+
159
+ - 0d5a03d: Vector store modules
160
+
3
161
  ## 0.0.1-alpha.9
4
162
 
5
163
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # @mastra/mcp
2
+
3
+ Model Context Protocol (MCP) client implementation for Mastra, providing seamless integration with MCP-compatible AI models and tools.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/mcp
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ The `@mastra/mcp` package provides a client implementation for the Model Context Protocol (MCP), enabling Mastra to communicate with MCP-compatible AI models and tools. It wraps the official `@modelcontextprotocol/sdk` and provides Mastra-specific functionality.
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { MastraMCPClient } from '@mastra/mcp';
19
+
20
+ // Create a client
21
+ const client = new MastraMCPClient({
22
+ name: 'my-mcp-client',
23
+ version: '1.0.0', // optional
24
+ server: {
25
+ // StdioServerParameters
26
+ command: 'your-mcp-server-command',
27
+ args: ['--your', 'args'],
28
+ },
29
+ capabilities: {}, // optional ClientCapabilities
30
+ });
31
+
32
+ // Connect to the MCP server
33
+ await client.connect();
34
+
35
+ // List available resources
36
+ const resources = await client.resources();
37
+
38
+ // Get available tools
39
+ const tools = await client.tools();
40
+
41
+ // Disconnect when done
42
+ await client.disconnect();
43
+ ```
44
+
45
+ ## Configuration
46
+
47
+ ### Required Parameters
48
+
49
+ - `name`: Name of the MCP client instance
50
+ - `server`: StdioServerParameters object containing:
51
+ - `command`: Command to start the MCP server
52
+ - `args`: Array of command arguments
53
+
54
+ ### Optional Parameters
55
+
56
+ - `version`: Client version (default: '1.0.0')
57
+ - `capabilities`: ClientCapabilities object for specifying supported features
58
+
59
+ ## Features
60
+
61
+ - Standard MCP client implementation
62
+ - Automatic tool conversion to Mastra format
63
+ - Resource discovery and management
64
+ - Stdio-based transport layer
65
+ - Automatic error handling and logging
66
+ - Tool execution with context
67
+
68
+ ## Methods
69
+
70
+ ### `connect()`
71
+
72
+ Establishes connection with the MCP server.
73
+
74
+ ### `disconnect()`
75
+
76
+ Closes the connection with the MCP server.
77
+
78
+ ### `resources()`
79
+
80
+ Lists available resources from the MCP server.
81
+
82
+ ### `tools()`
83
+
84
+ Retrieves and converts MCP tools to Mastra-compatible format.
85
+
86
+ ## Tool Conversion
87
+
88
+ The package automatically converts MCP tools to Mastra's format:
89
+
90
+ ```typescript
91
+ const tools = await client.tools();
92
+ // Returns: { [toolName: string]: MastraTool }
93
+
94
+ // Each tool includes:
95
+ // - Converted JSON schema
96
+ // - Mastra-compatible execution wrapper
97
+ // - Error handling
98
+ // - Automatic context passing
99
+ ```
100
+
101
+ ## Error Handling
102
+
103
+ The client includes comprehensive error handling:
104
+
105
+ - Connection errors
106
+ - Tool execution errors
107
+ - Resource listing errors
108
+ - Schema conversion errors
109
+
110
+ ## Related Links
111
+
112
+ - [Model Context Protocol Specification](https://github.com/modelcontextprotocol/spec)
113
+ - [@modelcontextprotocol/sdk Documentation](https://github.com/modelcontextprotocol/sdk)
package/dist/index.d.ts CHANGED
@@ -1,2 +1,42 @@
1
- export * from './client';
2
- //# sourceMappingURL=index.d.ts.map
1
+ import * as zod from 'zod';
2
+ import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
3
+ import { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
4
+
5
+ declare class MastraMCPClient {
6
+ name: string;
7
+ private transport;
8
+ private client;
9
+ constructor({ name, version, server, capabilities, }: {
10
+ name: string;
11
+ server: StdioServerParameters;
12
+ capabilities?: ClientCapabilities;
13
+ version?: string;
14
+ });
15
+ connect(): Promise<void>;
16
+ disconnect(): Promise<void>;
17
+ resources(): Promise<zod.objectOutputType<zod.objectUtil.extendShape<zod.objectUtil.extendShape<{
18
+ _meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
19
+ }, {
20
+ nextCursor: zod.ZodOptional<zod.ZodString>;
21
+ }>, {
22
+ resources: zod.ZodArray<zod.ZodObject<{
23
+ uri: zod.ZodString;
24
+ name: zod.ZodString;
25
+ description: zod.ZodOptional<zod.ZodString>;
26
+ mimeType: zod.ZodOptional<zod.ZodString>;
27
+ }, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
28
+ uri: zod.ZodString;
29
+ name: zod.ZodString;
30
+ description: zod.ZodOptional<zod.ZodString>;
31
+ mimeType: zod.ZodOptional<zod.ZodString>;
32
+ }, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
33
+ uri: zod.ZodString;
34
+ name: zod.ZodString;
35
+ description: zod.ZodOptional<zod.ZodString>;
36
+ mimeType: zod.ZodOptional<zod.ZodString>;
37
+ }, zod.ZodTypeAny, "passthrough">>, "many">;
38
+ }>, zod.ZodTypeAny, "passthrough">>;
39
+ tools(): Promise<Record<string, any>>;
40
+ }
41
+
42
+ export { MastraMCPClient };
package/dist/index.js CHANGED
@@ -1,8 +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';
1
6
 
2
- 'use strict'
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
+ };
3
69
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./mcp.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./mcp.cjs.development.js')
8
- }
70
+ export { MastraMCPClient };
package/package.json CHANGED
@@ -1,18 +1,13 @@
1
1
  {
2
2
  "name": "@mastra/mcp",
3
- "version": "0.0.1-alpha.9",
3
+ "version": "0.1.0-alpha.29",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
- "module": "dist/mcp.esm.js",
8
7
  "types": "dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
10
  "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/mcp.esm.js"
14
- },
15
- "require": {
16
11
  "types": "./dist/index.d.ts",
17
12
  "default": "./dist/index.js"
18
13
  }
@@ -27,21 +22,19 @@
27
22
  "date-fns": "^4.1.0",
28
23
  "dotenv": "^16.3.1",
29
24
  "zod": "^3.24.1",
30
- "@mastra/core": "0.1.27-alpha.69"
25
+ "@mastra/core": "^0.2.0-alpha.87"
31
26
  },
32
27
  "devDependencies": {
33
28
  "@babel/preset-env": "^7.26.0",
34
29
  "@babel/preset-typescript": "^7.26.0",
35
30
  "@tsconfig/recommended": "^1.0.7",
36
- "@types/jsdom": "^21.1.7",
37
31
  "@types/node": "^22.9.0",
38
- "@types/pg": "^8.11.10",
39
- "dts-cli": "^2.0.5",
40
- "vitest": "^2.1.8"
32
+ "tsup": "^8.0.1",
33
+ "vitest": "^3.0.4"
41
34
  },
42
35
  "scripts": {
43
- "build": "dts build",
44
- "build:dev": "dts watch",
36
+ "build": "tsup src/index.ts --format esm --dts --clean --treeshake",
37
+ "dev": "tsup src/index.ts --format esm --dts --clean --treeshake --watch",
45
38
  "test": "vitest run"
46
39
  }
47
40
  }
@@ -1,4 +1,5 @@
1
- import { Agent } from '@mastra/core';
1
+ import { Agent } from '@mastra/core/agent';
2
+ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2
3
 
3
4
  import { MastraMCPClient } from './client.js';
4
5
 
package/src/client.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { createTool, jsonSchemaToModel } from '@mastra/core';
1
+ import { createTool } from '@mastra/core/tools';
2
+ import { jsonSchemaToModel } from '@mastra/core/utils';
2
3
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
3
- import { StdioClientTransport, StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
4
- import { ClientCapabilities, ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
4
+ import { StdioClientTransport, type StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
5
+ import { type ClientCapabilities, ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
5
6
 
6
7
  export class MastraMCPClient {
7
8
  name: string;
package/tsconfig.json CHANGED
@@ -1,10 +1,5 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "moduleResolution": "bundler",
5
- "outDir": "./dist",
6
- "rootDir": "./src"
7
- },
2
+ "extends": "../../tsconfig.node.json",
8
3
  "include": ["src/**/*"],
9
4
  "exclude": ["node_modules", "**/*.test.ts"]
10
5
  }
package/dist/client.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
2
- import { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
3
- export declare class MastraMCPClient {
4
- name: string;
5
- private transport;
6
- private client;
7
- constructor({ name, version, server, capabilities, }: {
8
- name: string;
9
- server: StdioServerParameters;
10
- capabilities?: ClientCapabilities;
11
- version?: string;
12
- });
13
- connect(): Promise<void>;
14
- disconnect(): Promise<void>;
15
- resources(): Promise<import("zod").objectOutputType<import("zod").objectUtil.extendShape<import("zod").objectUtil.extendShape<{
16
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
17
- }, {
18
- nextCursor: import("zod").ZodOptional<import("zod").ZodString>;
19
- }>, {
20
- resources: import("zod").ZodArray<import("zod").ZodObject<{
21
- uri: import("zod").ZodString;
22
- name: import("zod").ZodString;
23
- description: import("zod").ZodOptional<import("zod").ZodString>;
24
- mimeType: import("zod").ZodOptional<import("zod").ZodString>;
25
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
26
- uri: import("zod").ZodString;
27
- name: import("zod").ZodString;
28
- description: import("zod").ZodOptional<import("zod").ZodString>;
29
- mimeType: import("zod").ZodOptional<import("zod").ZodString>;
30
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
31
- uri: import("zod").ZodString;
32
- name: import("zod").ZodString;
33
- description: import("zod").ZodOptional<import("zod").ZodString>;
34
- mimeType: import("zod").ZodOptional<import("zod").ZodString>;
35
- }, import("zod").ZodTypeAny, "passthrough">>, "many">;
36
- }>, import("zod").ZodTypeAny, "passthrough">>;
37
- tools(): Promise<Record<string, any>>;
38
- }
39
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAA6B,MAAM,oCAAoC,CAAC;AAEnG,qBAAa,eAAe;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,MAAM,CAAS;gBACX,EACV,IAAI,EACJ,OAAiB,EACjB,MAAM,EACN,YAAiB,GAClB,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,qBAAqB,CAAC;QAC9B,YAAY,CAAC,EAAE,kBAAkB,CAAC;QAClC,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;IAeK,OAAO;IAIP,UAAU;IAIV,SAAS;;;;;;;;;;;;;;;;;;;;;;IAIT,KAAK;CAgCZ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}