@mastra/mcp 0.4.0-alpha.8 → 0.4.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.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +41 -0
- package/dist/_tsup-dts-rollup.d.cts +132 -0
- package/dist/_tsup-dts-rollup.d.ts +132 -0
- package/dist/index.cjs +2154 -5
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2133 -7
- package/package.json +3 -2
- package/src/__fixtures__/server-weather.ts +16 -0
- package/src/__fixtures__/tools.ts +103 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +104 -0
- package/src/server.test.ts +115 -0
- package/src/server.ts +253 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/mcp@0.4.0-alpha.
|
|
2
|
+
> @mastra/mcp@0.4.0-alpha.9 build /home/runner/work/mastra/mastra/packages/mcp
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 17616ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 13130ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m199.82 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 4740ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m200.48 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 4742ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a3b2fb3: send mcp name on error connecting to it
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 0a033fa: Adds MCPServer component
|
|
12
|
+
- Updated dependencies [000a6d4]
|
|
13
|
+
- Updated dependencies [08bb78e]
|
|
14
|
+
- Updated dependencies [ed2f549]
|
|
15
|
+
- Updated dependencies [7e92011]
|
|
16
|
+
- Updated dependencies [9ee4293]
|
|
17
|
+
- Updated dependencies [03f3cd0]
|
|
18
|
+
- Updated dependencies [c0f22b4]
|
|
19
|
+
- Updated dependencies [71d9444]
|
|
20
|
+
- Updated dependencies [157c741]
|
|
21
|
+
- Updated dependencies [8a8a73b]
|
|
22
|
+
- Updated dependencies [0a033fa]
|
|
23
|
+
- Updated dependencies [fe3ae4d]
|
|
24
|
+
- Updated dependencies [9c26508]
|
|
25
|
+
- Updated dependencies [0f4eae3]
|
|
26
|
+
- Updated dependencies [16a8648]
|
|
27
|
+
- Updated dependencies [6f92295]
|
|
28
|
+
- @mastra/core@0.9.0
|
|
29
|
+
|
|
30
|
+
## 0.4.0-alpha.9
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 0a033fa: Adds MCPServer component
|
|
35
|
+
- Updated dependencies [000a6d4]
|
|
36
|
+
- Updated dependencies [ed2f549]
|
|
37
|
+
- Updated dependencies [c0f22b4]
|
|
38
|
+
- Updated dependencies [0a033fa]
|
|
39
|
+
- Updated dependencies [9c26508]
|
|
40
|
+
- Updated dependencies [0f4eae3]
|
|
41
|
+
- Updated dependencies [16a8648]
|
|
42
|
+
- @mastra/core@0.9.0-alpha.8
|
|
43
|
+
|
|
3
44
|
## 0.4.0-alpha.8
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -4,7 +4,32 @@ import { MastraBase } from '@mastra/core/base';
|
|
|
4
4
|
import type { Protocol } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
5
5
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
6
|
import type { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
7
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
7
8
|
import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
9
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
10
|
+
import { Tool } from '@mastra/core/tools';
|
|
11
|
+
import { ToolExecutionContext } from '@mastra/core';
|
|
12
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
|
|
15
|
+
declare type ConvertedTool = {
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
inputSchema: any;
|
|
19
|
+
zodSchema: z.ZodTypeAny;
|
|
20
|
+
execute: any;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export declare function createLogger(server?: Server): Logger;
|
|
24
|
+
|
|
25
|
+
export declare interface Logger {
|
|
26
|
+
info: (message: string, data?: any) => Promise<void>;
|
|
27
|
+
warning: (message: string, data?: any) => Promise<void>;
|
|
28
|
+
error: (message: string, error?: any) => Promise<void>;
|
|
29
|
+
debug: (message: string, data?: any) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare const logger: Logger;
|
|
8
33
|
|
|
9
34
|
export { LoggingLevel }
|
|
10
35
|
export { LoggingLevel as LoggingLevel_alias_1 }
|
|
@@ -88,6 +113,73 @@ declare interface MCPConfigurationOptions {
|
|
|
88
113
|
export { MCPConfigurationOptions }
|
|
89
114
|
export { MCPConfigurationOptions as MCPConfigurationOptions_alias_1 }
|
|
90
115
|
|
|
116
|
+
declare class MCPServer {
|
|
117
|
+
private server;
|
|
118
|
+
private convertedTools;
|
|
119
|
+
private stdioTransport?;
|
|
120
|
+
private sseTransport?;
|
|
121
|
+
/**
|
|
122
|
+
* Get the current stdio transport.
|
|
123
|
+
*/
|
|
124
|
+
getStdioTransport(): StdioServerTransport | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Get the current SSE transport.
|
|
127
|
+
*/
|
|
128
|
+
getSseTransport(): SSEServerTransport | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Get a read-only view of the registered tools (for testing/introspection).
|
|
131
|
+
*/
|
|
132
|
+
tools(): Readonly<Record<string, ConvertedTool>>;
|
|
133
|
+
/**
|
|
134
|
+
* Construct a new MCPServer instance.
|
|
135
|
+
* @param opts.name - Server name
|
|
136
|
+
* @param opts.version - Server version
|
|
137
|
+
* @param opts.tools - Tool definitions to register
|
|
138
|
+
*/
|
|
139
|
+
constructor({ name, version, tools }: {
|
|
140
|
+
name: string;
|
|
141
|
+
version: string;
|
|
142
|
+
tools: ToolsInput;
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Convert and validate all provided tools, logging registration status.
|
|
146
|
+
* @param tools Tool definitions
|
|
147
|
+
* @returns Converted tools registry
|
|
148
|
+
*/
|
|
149
|
+
private convertTools;
|
|
150
|
+
/**
|
|
151
|
+
* Register the ListTools handler for listing all available tools.
|
|
152
|
+
*/
|
|
153
|
+
private registerListToolsHandler;
|
|
154
|
+
/**
|
|
155
|
+
* Register the CallTool handler for executing a tool by name.
|
|
156
|
+
*/
|
|
157
|
+
private registerCallToolHandler;
|
|
158
|
+
/**
|
|
159
|
+
* Start the MCP server using stdio transport (for Windsurf integration).
|
|
160
|
+
*/
|
|
161
|
+
startStdio(): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Handles MCP-over-SSE protocol for user-provided HTTP servers.
|
|
164
|
+
* Call this from your HTTP server for both the SSE and message endpoints.
|
|
165
|
+
*
|
|
166
|
+
* @param url Parsed URL of the incoming request
|
|
167
|
+
* @param ssePath Path for establishing the SSE connection (e.g. '/sse')
|
|
168
|
+
* @param messagePath Path for POSTing client messages (e.g. '/message')
|
|
169
|
+
* @param req Incoming HTTP request
|
|
170
|
+
* @param res HTTP response (must support .write/.end)
|
|
171
|
+
*/
|
|
172
|
+
startSSE({ url, ssePath, messagePath, req, res, }: {
|
|
173
|
+
url: URL;
|
|
174
|
+
ssePath: string;
|
|
175
|
+
messagePath: string;
|
|
176
|
+
req: any;
|
|
177
|
+
res: any;
|
|
178
|
+
}): Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
export { MCPServer }
|
|
181
|
+
export { MCPServer as MCPServer_alias_1 }
|
|
182
|
+
|
|
91
183
|
export declare const server: Server<{
|
|
92
184
|
method: string;
|
|
93
185
|
params?: {
|
|
@@ -140,4 +232,44 @@ declare type SSEClientParameters = {
|
|
|
140
232
|
url: URL;
|
|
141
233
|
} & SSEClientTransportOptions;
|
|
142
234
|
|
|
235
|
+
export declare const weatherTool: Tool<z.ZodObject<{
|
|
236
|
+
location: z.ZodString;
|
|
237
|
+
}, "strip", z.ZodTypeAny, {
|
|
238
|
+
location: string;
|
|
239
|
+
}, {
|
|
240
|
+
location: string;
|
|
241
|
+
}>, z.ZodObject<{
|
|
242
|
+
temperature: z.ZodNumber;
|
|
243
|
+
feelsLike: z.ZodNumber;
|
|
244
|
+
humidity: z.ZodNumber;
|
|
245
|
+
windSpeed: z.ZodNumber;
|
|
246
|
+
windGust: z.ZodNumber;
|
|
247
|
+
conditions: z.ZodString;
|
|
248
|
+
location: z.ZodString;
|
|
249
|
+
}, "strip", z.ZodTypeAny, {
|
|
250
|
+
location: string;
|
|
251
|
+
temperature: number;
|
|
252
|
+
feelsLike: number;
|
|
253
|
+
humidity: number;
|
|
254
|
+
windSpeed: number;
|
|
255
|
+
windGust: number;
|
|
256
|
+
conditions: string;
|
|
257
|
+
}, {
|
|
258
|
+
location: string;
|
|
259
|
+
temperature: number;
|
|
260
|
+
feelsLike: number;
|
|
261
|
+
humidity: number;
|
|
262
|
+
windSpeed: number;
|
|
263
|
+
windGust: number;
|
|
264
|
+
conditions: string;
|
|
265
|
+
}>, ToolExecutionContext<z.ZodObject<{
|
|
266
|
+
location: z.ZodString;
|
|
267
|
+
}, "strip", z.ZodTypeAny, {
|
|
268
|
+
location: string;
|
|
269
|
+
}, {
|
|
270
|
+
location: string;
|
|
271
|
+
}>>>;
|
|
272
|
+
|
|
273
|
+
export declare const writeErrorLog: (message: string, data?: any) => void;
|
|
274
|
+
|
|
143
275
|
export { }
|
|
@@ -4,7 +4,32 @@ import { MastraBase } from '@mastra/core/base';
|
|
|
4
4
|
import type { Protocol } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
5
5
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
6
|
import type { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
7
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
7
8
|
import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
9
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
10
|
+
import { Tool } from '@mastra/core/tools';
|
|
11
|
+
import { ToolExecutionContext } from '@mastra/core';
|
|
12
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
|
|
15
|
+
declare type ConvertedTool = {
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
inputSchema: any;
|
|
19
|
+
zodSchema: z.ZodTypeAny;
|
|
20
|
+
execute: any;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export declare function createLogger(server?: Server): Logger;
|
|
24
|
+
|
|
25
|
+
export declare interface Logger {
|
|
26
|
+
info: (message: string, data?: any) => Promise<void>;
|
|
27
|
+
warning: (message: string, data?: any) => Promise<void>;
|
|
28
|
+
error: (message: string, error?: any) => Promise<void>;
|
|
29
|
+
debug: (message: string, data?: any) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare const logger: Logger;
|
|
8
33
|
|
|
9
34
|
export { LoggingLevel }
|
|
10
35
|
export { LoggingLevel as LoggingLevel_alias_1 }
|
|
@@ -88,6 +113,73 @@ declare interface MCPConfigurationOptions {
|
|
|
88
113
|
export { MCPConfigurationOptions }
|
|
89
114
|
export { MCPConfigurationOptions as MCPConfigurationOptions_alias_1 }
|
|
90
115
|
|
|
116
|
+
declare class MCPServer {
|
|
117
|
+
private server;
|
|
118
|
+
private convertedTools;
|
|
119
|
+
private stdioTransport?;
|
|
120
|
+
private sseTransport?;
|
|
121
|
+
/**
|
|
122
|
+
* Get the current stdio transport.
|
|
123
|
+
*/
|
|
124
|
+
getStdioTransport(): StdioServerTransport | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Get the current SSE transport.
|
|
127
|
+
*/
|
|
128
|
+
getSseTransport(): SSEServerTransport | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Get a read-only view of the registered tools (for testing/introspection).
|
|
131
|
+
*/
|
|
132
|
+
tools(): Readonly<Record<string, ConvertedTool>>;
|
|
133
|
+
/**
|
|
134
|
+
* Construct a new MCPServer instance.
|
|
135
|
+
* @param opts.name - Server name
|
|
136
|
+
* @param opts.version - Server version
|
|
137
|
+
* @param opts.tools - Tool definitions to register
|
|
138
|
+
*/
|
|
139
|
+
constructor({ name, version, tools }: {
|
|
140
|
+
name: string;
|
|
141
|
+
version: string;
|
|
142
|
+
tools: ToolsInput;
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Convert and validate all provided tools, logging registration status.
|
|
146
|
+
* @param tools Tool definitions
|
|
147
|
+
* @returns Converted tools registry
|
|
148
|
+
*/
|
|
149
|
+
private convertTools;
|
|
150
|
+
/**
|
|
151
|
+
* Register the ListTools handler for listing all available tools.
|
|
152
|
+
*/
|
|
153
|
+
private registerListToolsHandler;
|
|
154
|
+
/**
|
|
155
|
+
* Register the CallTool handler for executing a tool by name.
|
|
156
|
+
*/
|
|
157
|
+
private registerCallToolHandler;
|
|
158
|
+
/**
|
|
159
|
+
* Start the MCP server using stdio transport (for Windsurf integration).
|
|
160
|
+
*/
|
|
161
|
+
startStdio(): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Handles MCP-over-SSE protocol for user-provided HTTP servers.
|
|
164
|
+
* Call this from your HTTP server for both the SSE and message endpoints.
|
|
165
|
+
*
|
|
166
|
+
* @param url Parsed URL of the incoming request
|
|
167
|
+
* @param ssePath Path for establishing the SSE connection (e.g. '/sse')
|
|
168
|
+
* @param messagePath Path for POSTing client messages (e.g. '/message')
|
|
169
|
+
* @param req Incoming HTTP request
|
|
170
|
+
* @param res HTTP response (must support .write/.end)
|
|
171
|
+
*/
|
|
172
|
+
startSSE({ url, ssePath, messagePath, req, res, }: {
|
|
173
|
+
url: URL;
|
|
174
|
+
ssePath: string;
|
|
175
|
+
messagePath: string;
|
|
176
|
+
req: any;
|
|
177
|
+
res: any;
|
|
178
|
+
}): Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
export { MCPServer }
|
|
181
|
+
export { MCPServer as MCPServer_alias_1 }
|
|
182
|
+
|
|
91
183
|
export declare const server: Server<{
|
|
92
184
|
method: string;
|
|
93
185
|
params?: {
|
|
@@ -140,4 +232,44 @@ declare type SSEClientParameters = {
|
|
|
140
232
|
url: URL;
|
|
141
233
|
} & SSEClientTransportOptions;
|
|
142
234
|
|
|
235
|
+
export declare const weatherTool: Tool<z.ZodObject<{
|
|
236
|
+
location: z.ZodString;
|
|
237
|
+
}, "strip", z.ZodTypeAny, {
|
|
238
|
+
location: string;
|
|
239
|
+
}, {
|
|
240
|
+
location: string;
|
|
241
|
+
}>, z.ZodObject<{
|
|
242
|
+
temperature: z.ZodNumber;
|
|
243
|
+
feelsLike: z.ZodNumber;
|
|
244
|
+
humidity: z.ZodNumber;
|
|
245
|
+
windSpeed: z.ZodNumber;
|
|
246
|
+
windGust: z.ZodNumber;
|
|
247
|
+
conditions: z.ZodString;
|
|
248
|
+
location: z.ZodString;
|
|
249
|
+
}, "strip", z.ZodTypeAny, {
|
|
250
|
+
location: string;
|
|
251
|
+
temperature: number;
|
|
252
|
+
feelsLike: number;
|
|
253
|
+
humidity: number;
|
|
254
|
+
windSpeed: number;
|
|
255
|
+
windGust: number;
|
|
256
|
+
conditions: string;
|
|
257
|
+
}, {
|
|
258
|
+
location: string;
|
|
259
|
+
temperature: number;
|
|
260
|
+
feelsLike: number;
|
|
261
|
+
humidity: number;
|
|
262
|
+
windSpeed: number;
|
|
263
|
+
windGust: number;
|
|
264
|
+
conditions: string;
|
|
265
|
+
}>, ToolExecutionContext<z.ZodObject<{
|
|
266
|
+
location: z.ZodString;
|
|
267
|
+
}, "strip", z.ZodTypeAny, {
|
|
268
|
+
location: string;
|
|
269
|
+
}, {
|
|
270
|
+
location: string;
|
|
271
|
+
}>>>;
|
|
272
|
+
|
|
273
|
+
export declare const writeErrorLog: (message: string, data?: any) => void;
|
|
274
|
+
|
|
143
275
|
export { }
|