@mastra/mcp 0.5.0-alpha.1 → 0.5.0-alpha.3

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,23 +1,23 @@
1
1
 
2
- > @mastra/mcp@0.5.0-alpha.1 build /home/runner/work/mastra/mastra/packages/mcp
2
+ > @mastra/mcp@0.5.0-alpha.3 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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 16327ms
9
+ TSC ⚡️ Build success in 17533ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 13131ms
16
+ DTS ⚡️ Build success in 11255ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 26.18 KB
21
- CJS ⚡️ Build success in 1047ms
22
- ESM dist/index.js 25.82 KB
23
- ESM ⚡️ Build success in 1047ms
20
+ ESM dist/index.js 26.20 KB
21
+ ESM ⚡️ Build success in 693ms
22
+ CJS dist/index.cjs 26.57 KB
23
+ CJS ⚡️ Build success in 693ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 0.5.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - bb1e2c8: Make sure mcp handlers can only be registered once
8
+
9
+ ## 0.5.0-alpha.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [3171b5b]
14
+ - Updated dependencies [973e5ac]
15
+ - Updated dependencies [9e1eff5]
16
+ - @mastra/core@0.9.4-alpha.2
17
+
3
18
  ## 0.5.0-alpha.1
4
19
 
5
20
  ### Minor Changes
@@ -189,6 +189,8 @@ declare class MCPServer extends MCPServerBase {
189
189
  private stdioTransport?;
190
190
  private sseTransport?;
191
191
  private streamableHTTPTransport?;
192
+ private listToolsHandlerIsRegistered;
193
+ private callToolHandlerIsRegistered;
192
194
  /**
193
195
  * Get the current stdio transport.
194
196
  */
@@ -189,6 +189,8 @@ declare class MCPServer extends MCPServerBase {
189
189
  private stdioTransport?;
190
190
  private sseTransport?;
191
191
  private streamableHTTPTransport?;
192
+ private listToolsHandlerIsRegistered;
193
+ private callToolHandlerIsRegistered;
192
194
  /**
193
195
  * Get the current stdio transport.
194
196
  */
package/dist/index.cjs CHANGED
@@ -482,6 +482,8 @@ var MCPServer = class extends mcp.MCPServerBase {
482
482
  stdioTransport;
483
483
  sseTransport;
484
484
  streamableHTTPTransport;
485
+ listToolsHandlerIsRegistered = false;
486
+ callToolHandlerIsRegistered = false;
485
487
  /**
486
488
  * Get the current stdio transport.
487
489
  */
@@ -555,6 +557,10 @@ var MCPServer = class extends mcp.MCPServerBase {
555
557
  * Register the ListTools handler for listing all available tools.
556
558
  */
557
559
  registerListToolsHandler() {
560
+ if (this.listToolsHandlerIsRegistered) {
561
+ return;
562
+ }
563
+ this.listToolsHandlerIsRegistered = true;
558
564
  this.server.setRequestHandler(types_js.ListToolsRequestSchema, async () => {
559
565
  this.logger.debug("Handling ListTools request");
560
566
  return {
@@ -570,6 +576,10 @@ var MCPServer = class extends mcp.MCPServerBase {
570
576
  * Register the CallTool handler for executing a tool by name.
571
577
  */
572
578
  registerCallToolHandler() {
579
+ if (this.callToolHandlerIsRegistered) {
580
+ return;
581
+ }
582
+ this.callToolHandlerIsRegistered = true;
573
583
  this.server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
574
584
  const startTime = Date.now();
575
585
  try {
@@ -749,6 +759,8 @@ var MCPServer = class extends mcp.MCPServerBase {
749
759
  * Close the MCP server and all its connections
750
760
  */
751
761
  async close() {
762
+ this.callToolHandlerIsRegistered = false;
763
+ this.listToolsHandlerIsRegistered = false;
752
764
  try {
753
765
  if (this.stdioTransport) {
754
766
  await this.stdioTransport.close?.();
package/dist/index.js CHANGED
@@ -475,6 +475,8 @@ var MCPServer = class extends MCPServerBase {
475
475
  stdioTransport;
476
476
  sseTransport;
477
477
  streamableHTTPTransport;
478
+ listToolsHandlerIsRegistered = false;
479
+ callToolHandlerIsRegistered = false;
478
480
  /**
479
481
  * Get the current stdio transport.
480
482
  */
@@ -548,6 +550,10 @@ var MCPServer = class extends MCPServerBase {
548
550
  * Register the ListTools handler for listing all available tools.
549
551
  */
550
552
  registerListToolsHandler() {
553
+ if (this.listToolsHandlerIsRegistered) {
554
+ return;
555
+ }
556
+ this.listToolsHandlerIsRegistered = true;
551
557
  this.server.setRequestHandler(ListToolsRequestSchema, async () => {
552
558
  this.logger.debug("Handling ListTools request");
553
559
  return {
@@ -563,6 +569,10 @@ var MCPServer = class extends MCPServerBase {
563
569
  * Register the CallTool handler for executing a tool by name.
564
570
  */
565
571
  registerCallToolHandler() {
572
+ if (this.callToolHandlerIsRegistered) {
573
+ return;
574
+ }
575
+ this.callToolHandlerIsRegistered = true;
566
576
  this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
567
577
  const startTime = Date.now();
568
578
  try {
@@ -742,6 +752,8 @@ var MCPServer = class extends MCPServerBase {
742
752
  * Close the MCP server and all its connections
743
753
  */
744
754
  async close() {
755
+ this.callToolHandlerIsRegistered = false;
756
+ this.listToolsHandlerIsRegistered = false;
745
757
  try {
746
758
  if (this.stdioTransport) {
747
759
  await this.stdioTransport.close?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp",
3
- "version": "0.5.0-alpha.1",
3
+ "version": "0.5.0-alpha.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "fast-deep-equal": "^3.1.3",
29
29
  "json-schema-to-zod": "^2.6.0",
30
30
  "uuid": "^11.1.0",
31
- "@mastra/core": "^0.9.4-alpha.1"
31
+ "@mastra/core": "^0.9.4-alpha.2"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "zod": "^3.0.0"
package/src/server.ts CHANGED
@@ -19,6 +19,8 @@ export class MCPServer extends MCPServerBase {
19
19
  private stdioTransport?: StdioServerTransport;
20
20
  private sseTransport?: SSEServerTransport;
21
21
  private streamableHTTPTransport?: StreamableHTTPServerTransport;
22
+ private listToolsHandlerIsRegistered: boolean = false;
23
+ private callToolHandlerIsRegistered: boolean = false;
22
24
 
23
25
  /**
24
26
  * Get the current stdio transport.
@@ -105,6 +107,10 @@ export class MCPServer extends MCPServerBase {
105
107
  * Register the ListTools handler for listing all available tools.
106
108
  */
107
109
  private registerListToolsHandler() {
110
+ if (this.listToolsHandlerIsRegistered) {
111
+ return;
112
+ }
113
+ this.listToolsHandlerIsRegistered = true;
108
114
  this.server.setRequestHandler(ListToolsRequestSchema, async () => {
109
115
  this.logger.debug('Handling ListTools request');
110
116
  return {
@@ -121,6 +127,10 @@ export class MCPServer extends MCPServerBase {
121
127
  * Register the CallTool handler for executing a tool by name.
122
128
  */
123
129
  private registerCallToolHandler() {
130
+ if (this.callToolHandlerIsRegistered) {
131
+ return;
132
+ }
133
+ this.callToolHandlerIsRegistered = true;
124
134
  this.server.setRequestHandler(CallToolRequestSchema, async request => {
125
135
  const startTime = Date.now();
126
136
  try {
@@ -323,6 +333,8 @@ export class MCPServer extends MCPServerBase {
323
333
  * Close the MCP server and all its connections
324
334
  */
325
335
  async close() {
336
+ this.callToolHandlerIsRegistered = false;
337
+ this.listToolsHandlerIsRegistered = false;
326
338
  try {
327
339
  if (this.stdioTransport) {
328
340
  await this.stdioTransport.close?.();