@mastra/mcp 0.10.5 → 0.10.6-alpha.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,23 +1,23 @@
1
1
 
2
- > @mastra/mcp@0.10.5-alpha.2 build /home/runner/work/mastra/mastra/packages/mcp
2
+ > @mastra/mcp@0.10.6-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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 21277ms
9
+ TSC ⚡️ Build success in 22958ms
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 30216ms
16
+ DTS ⚡️ Build success in 30106ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 88.67 KB
21
- ESM ⚡️ Build success in 2174ms
22
- CJS dist/index.cjs 89.35 KB
23
- CJS ⚡️ Build success in 2174ms
20
+ CJS dist/index.cjs 89.38 KB
21
+ CJS ⚡️ Build success in 2235ms
22
+ ESM dist/index.js 88.70 KB
23
+ ESM ⚡️ Build success in 2236ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 0.10.6-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - f5ec3a4: Fix tool calling args for mcp server to ensure validatedArgs are not undefined
8
+ - ab3bbff: Add support for extra arguments in mcp
9
+ - Updated dependencies [2873c7f]
10
+ - Updated dependencies [1c1c6a1]
11
+ - Updated dependencies [565cc0c]
12
+ - @mastra/core@0.10.11-alpha.2
13
+
3
14
  ## 0.10.5
4
15
 
5
16
  ### Patch Changes
@@ -296,7 +307,6 @@
296
307
  Added a new `getResources()` method to the MCPClient class that allows clients to retrieve resources from connected MCP servers. Resources are data or content exposed by MCP servers that can be accessed by clients.
297
308
 
298
309
  The implementation includes:
299
-
300
310
  - Direct access to resources from all connected MCP servers, grouped by server name
301
311
  - Robust error handling that allows partial results when some servers fail
302
312
  - Comprehensive test coverage with real server implementation
@@ -375,7 +385,6 @@
375
385
  Added a new `getResources()` method to the MCPClient class that allows clients to retrieve resources from connected MCP servers. Resources are data or content exposed by MCP servers that can be accessed by clients.
376
386
 
377
387
  The implementation includes:
378
-
379
388
  - Direct access to resources from all connected MCP servers, grouped by server name
380
389
  - Robust error handling that allows partial results when some servers fail
381
390
  - Comprehensive test coverage with real server implementation
@@ -20,6 +20,7 @@ import { objectOutputType } from 'zod';
20
20
  import { objectUtil } from 'zod';
21
21
  import type { Prompt } from '@modelcontextprotocol/sdk/types.js';
22
22
  import type { PromptMessage } from '@modelcontextprotocol/sdk/types.js';
23
+ import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
23
24
  import type { Resource } from '@modelcontextprotocol/sdk/types.js';
24
25
  import type { ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
25
26
  import { ResourceUpdatedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
@@ -504,6 +505,11 @@ export { MCPConfigurationOptions }
504
505
  export { MCPConfigurationOptions as MCPConfigurationOptions_alias_1 }
505
506
  export { MCPConfigurationOptions as MCPConfigurationOptions_alias_2 }
506
507
 
508
+ declare type MCPRequestHandlerExtra = RequestHandlerExtra<any, any>;
509
+ export { MCPRequestHandlerExtra }
510
+ export { MCPRequestHandlerExtra as MCPRequestHandlerExtra_alias_1 }
511
+ export { MCPRequestHandlerExtra as MCPRequestHandlerExtra_alias_2 }
512
+
507
513
  declare class MCPServer extends MCPServerBase {
508
514
  private server;
509
515
  private stdioTransport?;
@@ -740,6 +746,7 @@ declare type MCPTool = {
740
746
  outputSchema?: InternalCoreTool['outputSchema'];
741
747
  execute: (params: any, options: Parameters<NonNullable<InternalCoreTool['execute']>>[1] & {
742
748
  elicitation: ElicitationActions;
749
+ extra: MCPRequestHandlerExtra;
743
750
  }) => Promise<any>;
744
751
  };
745
752
  export { MCPTool }
@@ -20,6 +20,7 @@ import { objectOutputType } from 'zod';
20
20
  import { objectUtil } from 'zod';
21
21
  import type { Prompt } from '@modelcontextprotocol/sdk/types.js';
22
22
  import type { PromptMessage } from '@modelcontextprotocol/sdk/types.js';
23
+ import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
23
24
  import type { Resource } from '@modelcontextprotocol/sdk/types.js';
24
25
  import type { ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
25
26
  import { ResourceUpdatedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
@@ -504,6 +505,11 @@ export { MCPConfigurationOptions }
504
505
  export { MCPConfigurationOptions as MCPConfigurationOptions_alias_1 }
505
506
  export { MCPConfigurationOptions as MCPConfigurationOptions_alias_2 }
506
507
 
508
+ declare type MCPRequestHandlerExtra = RequestHandlerExtra<any, any>;
509
+ export { MCPRequestHandlerExtra }
510
+ export { MCPRequestHandlerExtra as MCPRequestHandlerExtra_alias_1 }
511
+ export { MCPRequestHandlerExtra as MCPRequestHandlerExtra_alias_2 }
512
+
507
513
  declare class MCPServer extends MCPServerBase {
508
514
  private server;
509
515
  private stdioTransport?;
@@ -740,6 +746,7 @@ declare type MCPTool = {
740
746
  outputSchema?: InternalCoreTool['outputSchema'];
741
747
  execute: (params: any, options: Parameters<NonNullable<InternalCoreTool['execute']>>[1] & {
742
748
  elicitation: ElicitationActions;
749
+ extra: MCPRequestHandlerExtra;
743
750
  }) => Promise<any>;
744
751
  };
745
752
  export { MCPTool }
package/dist/index.cjs CHANGED
@@ -1018,7 +1018,7 @@ var MCPConfiguration = class extends MCPClient {
1018
1018
  }
1019
1019
  };
1020
1020
 
1021
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/utils/stream.js
1021
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/utils/stream.js
1022
1022
  var StreamingApi = class {
1023
1023
  writer;
1024
1024
  encoder;
@@ -1085,7 +1085,7 @@ var StreamingApi = class {
1085
1085
  }
1086
1086
  };
1087
1087
 
1088
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/helper/streaming/utils.js
1088
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/helper/streaming/utils.js
1089
1089
  var isOldBunVersion = () => {
1090
1090
  const version = typeof Bun !== "undefined" ? Bun.version : void 0;
1091
1091
  if (version === void 0) {
@@ -1096,7 +1096,7 @@ var isOldBunVersion = () => {
1096
1096
  return result;
1097
1097
  };
1098
1098
 
1099
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/utils/html.js
1099
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/utils/html.js
1100
1100
  var HtmlEscapedCallbackPhase = {
1101
1101
  Stringify: 1};
1102
1102
  var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
@@ -1127,7 +1127,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
1127
1127
  }
1128
1128
  };
1129
1129
 
1130
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/helper/streaming/sse.js
1130
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/helper/streaming/sse.js
1131
1131
  var SSEStreamingApi = class extends StreamingApi {
1132
1132
  constructor(writable, readable) {
1133
1133
  super(writable, readable);
@@ -1523,7 +1523,7 @@ var MCPServer = class extends mcp.MCPServerBase {
1523
1523
  })
1524
1524
  };
1525
1525
  });
1526
- serverInstance.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
1526
+ serverInstance.setRequestHandler(types_js.CallToolRequestSchema, async (request, extra) => {
1527
1527
  const startTime = Date.now();
1528
1528
  try {
1529
1529
  const tool = this.convertedTools[request.params.name];
@@ -1559,7 +1559,8 @@ var MCPServer = class extends mcp.MCPServerBase {
1559
1559
  const result = await tool.execute(validation?.value, {
1560
1560
  messages: [],
1561
1561
  toolCallId: "",
1562
- elicitation: sessionElicitation
1562
+ elicitation: sessionElicitation,
1563
+ extra
1563
1564
  });
1564
1565
  this.logger.debug(`CallTool: Tool '${request.params.name}' executed successfully with result:`, result);
1565
1566
  const duration = Date.now() - startTime;
@@ -2480,7 +2481,7 @@ var MCPServer = class extends mcp.MCPServerBase {
2480
2481
  */
2481
2482
  async executeTool(toolId, args, executionContext) {
2482
2483
  const tool = this.convertedTools[toolId];
2483
- let validatedArgs;
2484
+ let validatedArgs = args;
2484
2485
  try {
2485
2486
  if (!tool) {
2486
2487
  this.logger.warn(`ExecuteTool: Unknown tool '${toolId}' requested on MCPServer '${this.name}'.`);
package/dist/index.d.cts CHANGED
@@ -15,6 +15,7 @@ export { MCPServerResources } from './_tsup-dts-rollup.cjs';
15
15
  export { MCPServerPromptMessagesCallback } from './_tsup-dts-rollup.cjs';
16
16
  export { MCPServerPrompts } from './_tsup-dts-rollup.cjs';
17
17
  export { ElicitationActions } from './_tsup-dts-rollup.cjs';
18
+ export { MCPRequestHandlerExtra } from './_tsup-dts-rollup.cjs';
18
19
  export { MCPTool } from './_tsup-dts-rollup.cjs';
19
20
  export { Resource } from './_tsup-dts-rollup.cjs';
20
21
  export { ResourceTemplate } from './_tsup-dts-rollup.cjs';
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export { MCPServerResources } from './_tsup-dts-rollup.js';
15
15
  export { MCPServerPromptMessagesCallback } from './_tsup-dts-rollup.js';
16
16
  export { MCPServerPrompts } from './_tsup-dts-rollup.js';
17
17
  export { ElicitationActions } from './_tsup-dts-rollup.js';
18
+ export { MCPRequestHandlerExtra } from './_tsup-dts-rollup.js';
18
19
  export { MCPTool } from './_tsup-dts-rollup.js';
19
20
  export { Resource } from './_tsup-dts-rollup.js';
20
21
  export { ResourceTemplate } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -1012,7 +1012,7 @@ var MCPConfiguration = class extends MCPClient {
1012
1012
  }
1013
1013
  };
1014
1014
 
1015
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/utils/stream.js
1015
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/utils/stream.js
1016
1016
  var StreamingApi = class {
1017
1017
  writer;
1018
1018
  encoder;
@@ -1079,7 +1079,7 @@ var StreamingApi = class {
1079
1079
  }
1080
1080
  };
1081
1081
 
1082
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/helper/streaming/utils.js
1082
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/helper/streaming/utils.js
1083
1083
  var isOldBunVersion = () => {
1084
1084
  const version = typeof Bun !== "undefined" ? Bun.version : void 0;
1085
1085
  if (version === void 0) {
@@ -1090,7 +1090,7 @@ var isOldBunVersion = () => {
1090
1090
  return result;
1091
1091
  };
1092
1092
 
1093
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/utils/html.js
1093
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/utils/html.js
1094
1094
  var HtmlEscapedCallbackPhase = {
1095
1095
  Stringify: 1};
1096
1096
  var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
@@ -1121,7 +1121,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
1121
1121
  }
1122
1122
  };
1123
1123
 
1124
- // ../../node_modules/.pnpm/hono@4.8.1/node_modules/hono/dist/helper/streaming/sse.js
1124
+ // ../../node_modules/.pnpm/hono@4.8.4/node_modules/hono/dist/helper/streaming/sse.js
1125
1125
  var SSEStreamingApi = class extends StreamingApi {
1126
1126
  constructor(writable, readable) {
1127
1127
  super(writable, readable);
@@ -1517,7 +1517,7 @@ var MCPServer = class extends MCPServerBase {
1517
1517
  })
1518
1518
  };
1519
1519
  });
1520
- serverInstance.setRequestHandler(CallToolRequestSchema, async (request) => {
1520
+ serverInstance.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
1521
1521
  const startTime = Date.now();
1522
1522
  try {
1523
1523
  const tool = this.convertedTools[request.params.name];
@@ -1553,7 +1553,8 @@ var MCPServer = class extends MCPServerBase {
1553
1553
  const result = await tool.execute(validation?.value, {
1554
1554
  messages: [],
1555
1555
  toolCallId: "",
1556
- elicitation: sessionElicitation
1556
+ elicitation: sessionElicitation,
1557
+ extra
1557
1558
  });
1558
1559
  this.logger.debug(`CallTool: Tool '${request.params.name}' executed successfully with result:`, result);
1559
1560
  const duration = Date.now() - startTime;
@@ -2474,7 +2475,7 @@ var MCPServer = class extends MCPServerBase {
2474
2475
  */
2475
2476
  async executeTool(toolId, args, executionContext) {
2476
2477
  const tool = this.convertedTools[toolId];
2477
- let validatedArgs;
2478
+ let validatedArgs = args;
2478
2479
  try {
2479
2480
  if (!tool) {
2480
2481
  this.logger.warn(`ExecuteTool: Unknown tool '${toolId}' requested on MCPServer '${this.name}'.`);
@@ -10,9 +10,9 @@ case `uname` in
10
10
  esac
11
11
 
12
12
  if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.1_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_9ed2428c73777463a3d92e2c0ddae976/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.1_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_9ed2428c73777463a3d92e2c0ddae976/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
13
+ export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.2_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_bcb3b08cf6e48f0a4d90e52d1b155bc5/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.2_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_bcb3b08cf6e48f0a4d90e52d1b155bc5/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
14
14
  else
15
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.1_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_9ed2428c73777463a3d92e2c0ddae976/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.1_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_9ed2428c73777463a3d92e2c0ddae976/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
15
+ export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.2_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_bcb3b08cf6e48f0a4d90e52d1b155bc5/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.2_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_bcb3b08cf6e48f0a4d90e52d1b155bc5/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
16
16
  fi
17
17
  if [ -x "$basedir/node" ]; then
18
18
  exec "$basedir/node" "$basedir/../vitest/vitest.mjs" "$@"
@@ -11,7 +11,7 @@
11
11
  "@ai-sdk/react": "^1.2.12",
12
12
  "@mastra/client-js": "workspace:*",
13
13
  "@mastra/mcp": "workspace:*",
14
- "dotenv": "^16.5.0",
14
+ "dotenv": "^16.6.1",
15
15
  "zod": "^3.25.67"
16
16
  },
17
17
  "devDependencies": {
@@ -21,7 +21,7 @@
21
21
  "get-port": "^7.1.0",
22
22
  "mastra": "workspace:*",
23
23
  "typescript": "^5.8.2",
24
- "vitest": "^3.2.3"
24
+ "vitest": "^3.2.4"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@mastra/core": "^0.10.0-alpha.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp",
3
- "version": "0.10.5",
3
+ "version": "0.10.6-alpha.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -43,15 +43,15 @@
43
43
  "ai": "4.3.16",
44
44
  "eslint": "^9.29.0",
45
45
  "hono-mcp-server-sse-transport": "0.0.7",
46
- "hono": "^4.7.11",
46
+ "hono": "^4.8.4",
47
47
  "tsup": "^8.5.0",
48
48
  "tsx": "^4.19.4",
49
49
  "typescript": "^5.8.3",
50
- "vitest": "^3.2.3",
50
+ "vitest": "^3.2.4",
51
51
  "zod": "^3.25.67",
52
52
  "zod-to-json-schema": "^3.24.5",
53
- "@internal/lint": "0.0.14",
54
- "@mastra/core": "0.10.7"
53
+ "@internal/lint": "0.0.17",
54
+ "@mastra/core": "0.10.11-alpha.2"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -24,7 +24,7 @@ import { weatherTool } from '../__fixtures__/tools';
24
24
  import { InternalMastraMCPClient } from '../client/client';
25
25
  import { MCPClient } from '../client/configuration';
26
26
  import { MCPServer } from './server';
27
- import type { MCPServerResources, MCPServerResourceContent } from './types';
27
+ import type { MCPServerResources, MCPServerResourceContent, MCPRequestHandlerExtra } from './types';
28
28
 
29
29
  const PORT = 9100 + Math.floor(Math.random() * 1000);
30
30
  let server: MCPServer;
@@ -937,12 +937,32 @@ describe('MCPServer', () => {
937
937
  let server: MCPServer;
938
938
  let client: MCPClient;
939
939
  const PORT = 9200 + Math.floor(Math.random() * 1000);
940
+ const TOKEN = `<random-token>`;
940
941
 
941
942
  beforeAll(async () => {
942
943
  server = new MCPServer({
943
944
  name: 'Test MCP Server',
944
945
  version: '0.1.0',
945
- tools: { weatherTool },
946
+ tools: {
947
+ weatherTool,
948
+ testAuthTool: {
949
+ description: 'Test tool to validate auth information from extra params',
950
+ parameters: z.object({
951
+ message: z.string().describe('Message to show to user'),
952
+ }),
953
+ execute: async (context, options) => {
954
+ const extra = options.extra as MCPRequestHandlerExtra;
955
+
956
+ return {
957
+ message: context.message,
958
+ sessionId: extra?.sessionId || null,
959
+ authInfo: extra?.authInfo || null,
960
+ requestId: extra?.requestId || null,
961
+ hasExtra: !!extra,
962
+ };
963
+ },
964
+ },
965
+ },
946
966
  });
947
967
 
948
968
  httpServer = http.createServer(async (req: http.IncomingMessage, res: http.ServerResponse) => {
@@ -964,6 +984,9 @@ describe('MCPServer', () => {
964
984
  servers: {
965
985
  local: {
966
986
  url: new URL(`http://localhost:${PORT}/http`),
987
+ requestInit: {
988
+ headers: { Authorization: `Bearer ${TOKEN}` },
989
+ },
967
990
  },
968
991
  },
969
992
  });
@@ -1008,6 +1031,60 @@ describe('MCPServer', () => {
1008
1031
  expect(toolResult).toHaveProperty('windSpeed');
1009
1032
  expect(toolResult).toHaveProperty('windGust');
1010
1033
  });
1034
+
1035
+ it('should pass auth information through extra parameter', async () => {
1036
+ const mockExtra: MCPRequestHandlerExtra = {
1037
+ signal: new AbortController().signal,
1038
+ sessionId: 'test-session-id',
1039
+ authInfo: {
1040
+ token: TOKEN,
1041
+ clientId: 'test-client-id',
1042
+ scopes: ['read'],
1043
+ },
1044
+ requestId: 'test-request-id',
1045
+ sendNotification: vi.fn(),
1046
+ sendRequest: vi.fn(),
1047
+ };
1048
+
1049
+ const mockRequest = {
1050
+ jsonrpc: '2.0' as const,
1051
+ id: 'test-request-1',
1052
+ method: 'tools/call' as const,
1053
+ params: {
1054
+ name: 'testAuthTool',
1055
+ arguments: {
1056
+ message: 'test auth',
1057
+ },
1058
+ },
1059
+ };
1060
+
1061
+ const serverInstance = server.getServer();
1062
+
1063
+ // @ts-ignore - this is a private property, but we need to access it to test the request handler
1064
+ const requestHandlers = serverInstance._requestHandlers;
1065
+ const callToolHandler = requestHandlers.get('tools/call');
1066
+
1067
+ expect(callToolHandler).toBeDefined();
1068
+
1069
+ const result = await callToolHandler(mockRequest, mockExtra);
1070
+
1071
+ expect(result).toBeDefined();
1072
+ expect(result.isError).toBe(false);
1073
+ expect(result.content).toBeInstanceOf(Array);
1074
+ expect(result.content.length).toBeGreaterThan(0);
1075
+
1076
+ const toolOutput = result.content[0];
1077
+ expect(toolOutput.type).toBe('text');
1078
+ const toolResult = JSON.parse(toolOutput.text);
1079
+
1080
+ expect(toolResult.message).toBe('test auth');
1081
+ expect(toolResult.hasExtra).toBe(true);
1082
+ expect(toolResult.sessionId).toBe('test-session-id');
1083
+ expect(toolResult.authInfo).toBeDefined();
1084
+ expect(toolResult.authInfo.token).toBe(TOKEN);
1085
+ expect(toolResult.authInfo.clientId).toBe('test-client-id');
1086
+ expect(toolResult.requestId).toBe('test-request-id');
1087
+ });
1011
1088
  });
1012
1089
 
1013
1090
  describe('MCPServer Hono SSE Transport', () => {
@@ -231,7 +231,7 @@ export class MCPServer extends MCPServerBase {
231
231
  });
232
232
 
233
233
  // Call tool handler
234
- serverInstance.setRequestHandler(CallToolRequestSchema, async request => {
234
+ serverInstance.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
235
235
  const startTime = Date.now();
236
236
  try {
237
237
  const tool = this.convertedTools[request.params.name] as MCPTool;
@@ -272,6 +272,7 @@ export class MCPServer extends MCPServerBase {
272
272
  messages: [],
273
273
  toolCallId: '',
274
274
  elicitation: sessionElicitation,
275
+ extra,
275
276
  });
276
277
 
277
278
  this.logger.debug(`CallTool: Tool '${request.params.name}' executed successfully with result:`, result);
@@ -1335,7 +1336,7 @@ export class MCPServer extends MCPServerBase {
1335
1336
  executionContext?: { messages?: any[]; toolCallId?: string },
1336
1337
  ): Promise<any> {
1337
1338
  const tool = this.convertedTools[toolId];
1338
- let validatedArgs: any;
1339
+ let validatedArgs = args;
1339
1340
  try {
1340
1341
  if (!tool) {
1341
1342
  this.logger.warn(`ExecuteTool: Unknown tool '${toolId}' requested on MCPServer '${this.name}'.`);
@@ -1,4 +1,5 @@
1
1
  import type { InternalCoreTool } from '@mastra/core';
2
+ import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
2
3
  import type {
3
4
  ElicitRequest,
4
5
  ElicitResult,
@@ -39,15 +40,19 @@ export type ElicitationActions = {
39
40
  sendRequest: (request: ElicitRequest['params']) => Promise<ElicitResult>;
40
41
  };
41
42
 
43
+ export type MCPRequestHandlerExtra = RequestHandlerExtra<any, any>;
44
+
42
45
  export type MCPTool = {
43
46
  id?: InternalCoreTool['id'];
44
47
  description?: InternalCoreTool['description'];
45
48
  parameters: InternalCoreTool['parameters'];
46
49
  outputSchema?: InternalCoreTool['outputSchema'];
47
- // Patch type to include elicitation in execute options
48
50
  execute: (
49
51
  params: any,
50
- options: Parameters<NonNullable<InternalCoreTool['execute']>>[1] & { elicitation: ElicitationActions },
52
+ options: Parameters<NonNullable<InternalCoreTool['execute']>>[1] & {
53
+ elicitation: ElicitationActions;
54
+ extra: MCPRequestHandlerExtra;
55
+ },
51
56
  ) => Promise<any>;
52
57
  };
53
58
 
@@ -1,21 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/mastra/mastra/packages/cli/dist/node_modules:/home/runner/work/mastra/mastra/packages/cli/node_modules:/home/runner/work/mastra/mastra/packages/node_modules:/home/runner/work/mastra/mastra/node_modules:/home/runner/work/mastra/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/home/runner/work/mastra/mastra/packages/cli/dist/node_modules:/home/runner/work/mastra/mastra/packages/cli/node_modules:/home/runner/work/mastra/mastra/packages/node_modules:/home/runner/work/mastra/mastra/node_modules:/home/runner/work/mastra/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../mastra/dist/index.js" "$@"
19
- else
20
- exec node "$basedir/../mastra/dist/index.js" "$@"
21
- fi