@mastra/mcp 0.3.8 → 0.3.9
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 +5 -5
- package/CHANGELOG.md +14 -0
- package/dist/_tsup-dts-rollup.d.cts +47 -3
- package/dist/_tsup-dts-rollup.d.ts +47 -3
- package/package.json +3 -3
- package/src/__fixtures__/stock-price.ts +102 -17
- package/src/__fixtures__/weather.ts +101 -20
- package/src/client.test.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/mcp@0.3.
|
|
2
|
+
> @mastra/mcp@0.3.9-alpha.0 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 9639ms
|
|
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 6523ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
20
|
[32mCJS[39m [1mdist/index.cjs [22m[32m7.27 KB[39m
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 350ms
|
|
22
22
|
[32mESM[39m [1mdist/index.js [22m[32m7.24 KB[39m
|
|
23
|
-
[32mESM[39m ⚡️ Build success in
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 350ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 0.3.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a06aadc]
|
|
8
|
+
- @mastra/core@0.8.2
|
|
9
|
+
|
|
10
|
+
## 0.3.9-alpha.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [a06aadc]
|
|
15
|
+
- @mastra/core@0.8.2-alpha.0
|
|
16
|
+
|
|
3
17
|
## 0.3.8
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import { FastMCP } from 'fastmcp';
|
|
3
2
|
import { MastraBase } from '@mastra/core/base';
|
|
4
3
|
import type { Protocol } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
4
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
5
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
6
6
|
import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
7
7
|
|
|
@@ -49,9 +49,53 @@ declare class MCPConfiguration extends MastraBase {
|
|
|
49
49
|
export { MCPConfiguration }
|
|
50
50
|
export { MCPConfiguration as MCPConfiguration_alias_1 }
|
|
51
51
|
|
|
52
|
-
export declare const server:
|
|
52
|
+
export declare const server: Server<{
|
|
53
|
+
method: string;
|
|
54
|
+
params?: {
|
|
55
|
+
[x: string]: unknown;
|
|
56
|
+
_meta?: {
|
|
57
|
+
[x: string]: unknown;
|
|
58
|
+
progressToken?: string | number | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
method: string;
|
|
63
|
+
params?: {
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
_meta?: {
|
|
66
|
+
[x: string]: unknown;
|
|
67
|
+
} | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
[x: string]: unknown;
|
|
71
|
+
_meta?: {
|
|
72
|
+
[x: string]: unknown;
|
|
73
|
+
} | undefined;
|
|
74
|
+
}>;
|
|
53
75
|
|
|
54
|
-
export declare const server_alias_1:
|
|
76
|
+
export declare const server_alias_1: Server<{
|
|
77
|
+
method: string;
|
|
78
|
+
params?: {
|
|
79
|
+
[x: string]: unknown;
|
|
80
|
+
_meta?: {
|
|
81
|
+
[x: string]: unknown;
|
|
82
|
+
progressToken?: string | number | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
} | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
method: string;
|
|
87
|
+
params?: {
|
|
88
|
+
[x: string]: unknown;
|
|
89
|
+
_meta?: {
|
|
90
|
+
[x: string]: unknown;
|
|
91
|
+
} | undefined;
|
|
92
|
+
} | undefined;
|
|
93
|
+
}, {
|
|
94
|
+
[x: string]: unknown;
|
|
95
|
+
_meta?: {
|
|
96
|
+
[x: string]: unknown;
|
|
97
|
+
} | undefined;
|
|
98
|
+
}>;
|
|
55
99
|
|
|
56
100
|
declare type SSEClientParameters = {
|
|
57
101
|
url: URL;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import { FastMCP } from 'fastmcp';
|
|
3
2
|
import { MastraBase } from '@mastra/core/base';
|
|
4
3
|
import type { Protocol } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
4
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
5
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
6
6
|
import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
7
7
|
|
|
@@ -49,9 +49,53 @@ declare class MCPConfiguration extends MastraBase {
|
|
|
49
49
|
export { MCPConfiguration }
|
|
50
50
|
export { MCPConfiguration as MCPConfiguration_alias_1 }
|
|
51
51
|
|
|
52
|
-
export declare const server:
|
|
52
|
+
export declare const server: Server<{
|
|
53
|
+
method: string;
|
|
54
|
+
params?: {
|
|
55
|
+
[x: string]: unknown;
|
|
56
|
+
_meta?: {
|
|
57
|
+
[x: string]: unknown;
|
|
58
|
+
progressToken?: string | number | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
method: string;
|
|
63
|
+
params?: {
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
_meta?: {
|
|
66
|
+
[x: string]: unknown;
|
|
67
|
+
} | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
[x: string]: unknown;
|
|
71
|
+
_meta?: {
|
|
72
|
+
[x: string]: unknown;
|
|
73
|
+
} | undefined;
|
|
74
|
+
}>;
|
|
53
75
|
|
|
54
|
-
export declare const server_alias_1:
|
|
76
|
+
export declare const server_alias_1: Server<{
|
|
77
|
+
method: string;
|
|
78
|
+
params?: {
|
|
79
|
+
[x: string]: unknown;
|
|
80
|
+
_meta?: {
|
|
81
|
+
[x: string]: unknown;
|
|
82
|
+
progressToken?: string | number | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
} | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
method: string;
|
|
87
|
+
params?: {
|
|
88
|
+
[x: string]: unknown;
|
|
89
|
+
_meta?: {
|
|
90
|
+
[x: string]: unknown;
|
|
91
|
+
} | undefined;
|
|
92
|
+
} | undefined;
|
|
93
|
+
}, {
|
|
94
|
+
[x: string]: unknown;
|
|
95
|
+
_meta?: {
|
|
96
|
+
[x: string]: unknown;
|
|
97
|
+
} | undefined;
|
|
98
|
+
}>;
|
|
55
99
|
|
|
56
100
|
declare type SSEClientParameters = {
|
|
57
101
|
url: URL;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
"date-fns": "^4.1.0",
|
|
27
27
|
"exit-hook": "^4.0.0",
|
|
28
28
|
"uuid": "^11.1.0",
|
|
29
|
-
"@mastra/core": "^0.8.
|
|
29
|
+
"@mastra/core": "^0.8.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@ai-sdk/anthropic": "^1.1.15",
|
|
33
33
|
"@microsoft/api-extractor": "^7.52.1",
|
|
34
34
|
"@types/node": "^20.17.27",
|
|
35
35
|
"eslint": "^9.23.0",
|
|
36
|
-
"fastmcp": "^1.20.4",
|
|
37
36
|
"tsup": "^8.4.0",
|
|
38
37
|
"typescript": "^5.8.2",
|
|
39
38
|
"vitest": "^3.0.9",
|
|
40
39
|
"zod": "^3.24.2",
|
|
40
|
+
"zod-to-json-schema": "^3.22.4",
|
|
41
41
|
"@internal/lint": "0.0.1"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
2
4
|
import { z } from 'zod';
|
|
5
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
6
|
|
|
4
7
|
const getStockPrice = async (symbol: string) => {
|
|
5
8
|
// Return mock data for testing
|
|
@@ -9,35 +12,117 @@ const getStockPrice = async (symbol: string) => {
|
|
|
9
12
|
};
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
const server = new
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const server = new Server(
|
|
16
|
+
{
|
|
17
|
+
name: 'Stock Price Server',
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
capabilities: {
|
|
22
|
+
tools: {},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
);
|
|
16
26
|
|
|
17
|
-
const
|
|
18
|
-
symbol: z.string(),
|
|
27
|
+
const stockInputSchema = z.object({
|
|
28
|
+
symbol: z.string().describe('Stock symbol'),
|
|
19
29
|
});
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
const stockTool = {
|
|
22
32
|
name: 'getStockPrice',
|
|
23
33
|
description: "Fetches the last day's closing stock price for a given symbol",
|
|
24
|
-
|
|
25
|
-
execute: async (args: z.infer<typeof stockSchema>) => {
|
|
34
|
+
execute: async (args: z.infer<typeof stockInputSchema>) => {
|
|
26
35
|
try {
|
|
27
36
|
const priceData = await getStockPrice(args.symbol);
|
|
28
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: 'text',
|
|
41
|
+
text: JSON.stringify(priceData),
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
isError: false,
|
|
45
|
+
};
|
|
29
46
|
} catch (error) {
|
|
30
47
|
if (error instanceof Error) {
|
|
31
|
-
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{
|
|
51
|
+
type: 'text',
|
|
52
|
+
text: `Stock price fetch failed: ${error.message}`,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
isError: true,
|
|
56
|
+
};
|
|
32
57
|
}
|
|
33
|
-
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: 'An unknown error occurred.',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
isError: true,
|
|
66
|
+
};
|
|
34
67
|
}
|
|
35
68
|
},
|
|
36
|
-
}
|
|
69
|
+
};
|
|
37
70
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
// Set up request handlers
|
|
72
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
73
|
+
tools: [
|
|
74
|
+
{
|
|
75
|
+
name: stockTool.name,
|
|
76
|
+
description: stockTool.description,
|
|
77
|
+
inputSchema: zodToJsonSchema(stockInputSchema),
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
server.setRequestHandler(CallToolRequestSchema, async request => {
|
|
83
|
+
try {
|
|
84
|
+
switch (request.params.name) {
|
|
85
|
+
case 'getStockPrice': {
|
|
86
|
+
const args = stockInputSchema.parse(request.params.arguments);
|
|
87
|
+
return await stockTool.execute(args);
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
return {
|
|
91
|
+
content: [
|
|
92
|
+
{
|
|
93
|
+
type: 'text',
|
|
94
|
+
text: `Unknown tool: ${request.params.name}`,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
isError: true,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error instanceof z.ZodError) {
|
|
102
|
+
return {
|
|
103
|
+
content: [
|
|
104
|
+
{
|
|
105
|
+
type: 'text',
|
|
106
|
+
text: `Invalid arguments: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
isError: true,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
content: [
|
|
114
|
+
{
|
|
115
|
+
type: 'text',
|
|
116
|
+
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
isError: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
41
122
|
});
|
|
42
123
|
|
|
124
|
+
// Start the server
|
|
125
|
+
const transport = new StdioServerTransport();
|
|
126
|
+
await server.connect(transport);
|
|
127
|
+
|
|
43
128
|
export { server };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
2
4
|
import { z } from 'zod';
|
|
5
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
6
|
|
|
4
7
|
const getWeather = async (location: string) => {
|
|
5
8
|
// Return mock data for testing
|
|
@@ -14,39 +17,117 @@ const getWeather = async (location: string) => {
|
|
|
14
17
|
};
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
const server = new
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const server = new Server(
|
|
21
|
+
{
|
|
22
|
+
name: 'Weather Server',
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
capabilities: {
|
|
27
|
+
tools: {},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
);
|
|
21
31
|
|
|
22
|
-
const
|
|
32
|
+
const weatherInputSchema = z.object({
|
|
23
33
|
location: z.string().describe('City name'),
|
|
24
34
|
});
|
|
25
35
|
|
|
26
|
-
|
|
36
|
+
const weatherTool = {
|
|
27
37
|
name: 'getWeather',
|
|
28
38
|
description: 'Get current weather for a location',
|
|
29
|
-
|
|
30
|
-
execute: async (args: z.infer<typeof weatherSchema>) => {
|
|
39
|
+
execute: async (args: z.infer<typeof weatherInputSchema>) => {
|
|
31
40
|
try {
|
|
32
41
|
const weatherData = await getWeather(args.location);
|
|
33
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: 'text',
|
|
46
|
+
text: JSON.stringify(weatherData),
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
isError: false,
|
|
50
|
+
};
|
|
34
51
|
} catch (error) {
|
|
35
52
|
if (error instanceof Error) {
|
|
36
|
-
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{
|
|
56
|
+
type: 'text',
|
|
57
|
+
text: `Weather fetch failed: ${error.message}`,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
isError: true,
|
|
61
|
+
};
|
|
37
62
|
}
|
|
38
|
-
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'text',
|
|
67
|
+
text: 'An unknown error occurred.',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
isError: true,
|
|
71
|
+
};
|
|
39
72
|
}
|
|
40
73
|
},
|
|
41
|
-
}
|
|
74
|
+
};
|
|
42
75
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
76
|
+
// Set up request handlers
|
|
77
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
78
|
+
tools: [
|
|
79
|
+
{
|
|
80
|
+
name: weatherTool.name,
|
|
81
|
+
description: weatherTool.description,
|
|
82
|
+
inputSchema: zodToJsonSchema(weatherInputSchema),
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
server.setRequestHandler(CallToolRequestSchema, async request => {
|
|
88
|
+
try {
|
|
89
|
+
switch (request.params.name) {
|
|
90
|
+
case 'getWeather': {
|
|
91
|
+
const args = weatherInputSchema.parse(request.params.arguments);
|
|
92
|
+
return await weatherTool.execute(args);
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
return {
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'text',
|
|
99
|
+
text: `Unknown tool: ${request.params.name}`,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
isError: true,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (error instanceof z.ZodError) {
|
|
107
|
+
return {
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
type: 'text',
|
|
111
|
+
text: `Invalid arguments: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
isError: true,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
content: [
|
|
119
|
+
{
|
|
120
|
+
type: 'text',
|
|
121
|
+
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
isError: true,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
50
127
|
});
|
|
51
128
|
|
|
129
|
+
// Start the server
|
|
130
|
+
const transport = new StdioServerTransport();
|
|
131
|
+
await server.connect(transport);
|
|
132
|
+
|
|
52
133
|
export { server };
|
package/src/client.test.ts
CHANGED
|
@@ -38,7 +38,7 @@ describe.skip('MastraMCPClient', () => {
|
|
|
38
38
|
// The MCP server tools are now available to your Mastra Agents
|
|
39
39
|
const tools = await everArtClient.tools();
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
await agent.generate('Can you make me a picture of a dog?', {
|
|
42
42
|
toolsets: {
|
|
43
43
|
everart: tools,
|
|
44
44
|
},
|