@mastra/mcp 0.1.1 → 0.2.0

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.
@@ -1,18 +1,19 @@
1
-
2
- > @mastra/mcp@0.1.1-alpha.0 build C:\Users\Ward\projects\mastra\mastra\packages\mcp
3
- > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.3.6
8
- TSC Build start
9
- TSC ⚡️ Build success in 4014ms
10
- DTS Build start
11
- CLI Target: es2022
12
- Analysis will use the bundled TypeScript version 5.7.3
13
- Writing package typings: C:\Users\Ward\projects\mastra\mastra\packages\mcp\dist\_tsup-dts-rollup.d.ts
14
- DTS ⚡️ Build success in 3403ms
15
- CLI Cleaning output folder
16
- ESM Build start
17
- ESM dist\index.js 1.77 KB
18
- ESM ⚡️ Build success in 154ms
1
+
2
+ 
3
+ > @mastra/mcp@0.2.0 build /Users/ward/projects/mastra/mastra/packages/mcp
4
+ > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
5
+
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.3.6
9
+ TSC Build start
10
+ TSC ⚡️ Build success in 2103ms
11
+ DTS Build start
12
+ CLI Target: es2022
13
+ Analysis will use the bundled TypeScript version 5.7.3
14
+ Writing package typings: /Users/ward/projects/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.ts
15
+ DTS ⚡️ Build success in 1310ms
16
+ CLI Cleaning output folder
17
+ ESM Build start
18
+ ESM dist/index.js 2.19 KB
19
+ ESM ⚡️ Build success in 120ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5b7d6fa: Added support for SSE MCP servers in the Mastra MCP client
8
+
9
+ ## 0.2.0-alpha.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 5b7d6fa: Added support for SSE MCP servers in the Mastra MCP client
14
+
3
15
  ## 0.1.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -17,18 +17,29 @@ The `@mastra/mcp` package provides a client implementation for the Model Context
17
17
  ```typescript
18
18
  import { MastraMCPClient } from '@mastra/mcp';
19
19
 
20
- // Create a client
21
- const client = new MastraMCPClient({
22
- name: 'my-mcp-client',
20
+ // Create a client with stdio server
21
+ const stdioClient = new MastraMCPClient({
22
+ name: 'my-stdio-client',
23
23
  version: '1.0.0', // optional
24
24
  server: {
25
- // StdioServerParameters
26
25
  command: 'your-mcp-server-command',
27
26
  args: ['--your', 'args'],
28
27
  },
29
28
  capabilities: {}, // optional ClientCapabilities
30
29
  });
31
30
 
31
+ // Or create a client with SSE server
32
+ const sseClient = new MastraMCPClient({
33
+ name: 'my-sse-client',
34
+ version: '1.0.0',
35
+ server: {
36
+ url: new URL('https://your-mcp-server.com/sse'),
37
+ requestInit: {
38
+ headers: { 'Authorization': 'Bearer your-token' }
39
+ }
40
+ }
41
+ });
42
+
32
43
  // Connect to the MCP server
33
44
  await client.connect();
34
45
 
@@ -47,9 +58,16 @@ await client.disconnect();
47
58
  ### Required Parameters
48
59
 
49
60
  - `name`: Name of the MCP client instance
50
- - `server`: StdioServerParameters object containing:
61
+ - `server`: Either a StdioServerParameters or SSEClientParameters object:
62
+
63
+ #### StdioServerParameters
51
64
  - `command`: Command to start the MCP server
52
65
  - `args`: Array of command arguments
66
+
67
+ #### SSEClientParameters
68
+ - `url`: URL instance pointing to the SSE server
69
+ - `requestInit`: Optional fetch request configuration
70
+ - `eventSourceInit`: Optional EventSource configuration
53
71
 
54
72
  ### Optional Parameters
55
73
 
@@ -61,7 +79,9 @@ await client.disconnect();
61
79
  - Standard MCP client implementation
62
80
  - Automatic tool conversion to Mastra format
63
81
  - Resource discovery and management
64
- - Stdio-based transport layer
82
+ - Multiple transport layers:
83
+ - Stdio-based for local servers
84
+ - SSE-based for remote servers
65
85
  - Automatic error handling and logging
66
86
  - Tool execution with context
67
87
 
@@ -1,13 +1,7 @@
1
1
  import type { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
2
- import { objectInputType } from 'zod';
3
- import { objectOutputType } from 'zod';
4
- import { objectUtil } from 'zod';
2
+ import type { Protocol } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
+ import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
5
4
  import type { 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
5
 
12
6
  declare class MastraMCPClient {
13
7
  name: string;
@@ -15,37 +9,20 @@ declare class MastraMCPClient {
15
9
  private client;
16
10
  constructor({ name, version, server, capabilities, }: {
17
11
  name: string;
18
- server: StdioServerParameters;
12
+ server: StdioServerParameters | SSEClientParameters;
19
13
  capabilities?: ClientCapabilities;
20
14
  version?: string;
21
15
  });
22
16
  connect(): Promise<void>;
23
17
  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">>;
18
+ resources(): Promise<ReturnType<Protocol<any, any, any>['request']>>;
46
19
  tools(): Promise<Record<string, any>>;
47
20
  }
48
21
  export { MastraMCPClient }
49
22
  export { MastraMCPClient as MastraMCPClient_alias_1 }
50
23
 
24
+ declare type SSEClientParameters = {
25
+ url: URL;
26
+ } & ConstructorParameters<typeof SSEClientTransport>[1];
27
+
51
28
  export { }
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createTool } from '@mastra/core/tools';
2
2
  import { jsonSchemaToModel } from '@mastra/core/utils';
3
3
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
+ import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
4
5
  import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
5
6
  import { ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
6
7
 
@@ -16,7 +17,14 @@ var MastraMCPClient = class {
16
17
  capabilities = {}
17
18
  }) {
18
19
  this.name = name;
19
- this.transport = new StdioClientTransport(server);
20
+ if (`url` in server) {
21
+ this.transport = new SSEClientTransport(server.url, {
22
+ requestInit: server.requestInit,
23
+ eventSourceInit: server.eventSourceInit
24
+ });
25
+ } else {
26
+ this.transport = new StdioClientTransport(server);
27
+ }
20
28
  this.client = new Client(
21
29
  {
22
30
  name,
@@ -33,6 +41,7 @@ var MastraMCPClient = class {
33
41
  async disconnect() {
34
42
  return await this.client.close();
35
43
  }
44
+ // TODO: do the type magic to return the right method type. Right now we get infinitely deep infered type errors from Zod without using "any"
36
45
  async resources() {
37
46
  return await this.client.request({ method: "resources/list" }, ListResourcesResultSchema);
38
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/client.ts CHANGED
@@ -1,14 +1,21 @@
1
1
  import { createTool } from '@mastra/core/tools';
2
2
  import { jsonSchemaToModel } from '@mastra/core/utils';
3
3
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
+ import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
4
5
  import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
5
6
  import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
6
- import { ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
7
+ import type { Protocol } from '@modelcontextprotocol/sdk/shared/protocol.js';
8
+ import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
7
9
  import type { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
10
+ import { ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
11
+
12
+ type SSEClientParameters = {
13
+ url: URL;
14
+ } & ConstructorParameters<typeof SSEClientTransport>[1];
8
15
 
9
16
  export class MastraMCPClient {
10
17
  name: string;
11
- private transport: StdioClientTransport;
18
+ private transport: Transport;
12
19
  private client: Client;
13
20
  constructor({
14
21
  name,
@@ -17,12 +24,20 @@ export class MastraMCPClient {
17
24
  capabilities = {},
18
25
  }: {
19
26
  name: string;
20
- server: StdioServerParameters;
27
+ server: StdioServerParameters | SSEClientParameters;
21
28
  capabilities?: ClientCapabilities;
22
29
  version?: string;
23
30
  }) {
24
31
  this.name = name;
25
- this.transport = new StdioClientTransport(server);
32
+
33
+ if (`url` in server) {
34
+ this.transport = new SSEClientTransport(server.url, {
35
+ requestInit: server.requestInit,
36
+ eventSourceInit: server.eventSourceInit,
37
+ });
38
+ } else {
39
+ this.transport = new StdioClientTransport(server);
40
+ }
26
41
 
27
42
  this.client = new Client(
28
43
  {
@@ -43,7 +58,9 @@ export class MastraMCPClient {
43
58
  return await this.client.close();
44
59
  }
45
60
 
46
- async resources() {
61
+ // TODO: do the type magic to return the right method type. Right now we get infinitely deep infered type errors from Zod without using "any"
62
+
63
+ async resources(): Promise<ReturnType<Protocol<any, any, any>['request']>> {
47
64
  return await this.client.request({ method: 'resources/list' }, ListResourcesResultSchema);
48
65
  }
49
66
 
@@ -1,4 +0,0 @@
1
-
2
- > @mastra/mcp@0.1.0 lint C:\Users\Ward\projects\mastra\mastra\packages\mcp
3
- > eslint .
4
-