@mastra/mcp 1.4.2 → 1.5.0-alpha.1

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/dist/index.js CHANGED
@@ -425,6 +425,7 @@ var InternalMastraMCPClient = class extends MastraBase {
425
425
  sigTermHandler;
426
426
  sigHupHandler;
427
427
  _roots;
428
+ requireToolApproval;
428
429
  /** Provides access to resource operations (list, read, subscribe, etc.) */
429
430
  resources;
430
431
  /** Provides access to prompt operations (list, get, notifications) */
@@ -450,11 +451,15 @@ var InternalMastraMCPClient = class extends MastraBase {
450
451
  this.enableServerLogs = server.enableServerLogs ?? true;
451
452
  this.serverConfig = server;
452
453
  this.enableProgressTracking = !!server.enableProgressTracking;
454
+ this.requireToolApproval = server.requireToolApproval;
453
455
  this._roots = server.roots ?? [];
454
456
  const hasRoots = this._roots.length > 0 || !!capabilities.roots;
455
457
  const clientCapabilities = {
456
458
  ...capabilities,
457
- elicitation: {},
459
+ // Merge elicitation capabilities instead of overwriting
460
+ elicitation: {
461
+ ...capabilities.elicitation ?? {}
462
+ },
458
463
  // Auto-enable roots capability if roots are provided
459
464
  ...hasRoots ? { roots: { listChanged: true, ...capabilities.roots ?? {} } } : {}
460
465
  };
@@ -896,6 +901,18 @@ var InternalMastraMCPClient = class extends MastraBase {
896
901
  for (const tool of tools) {
897
902
  this.log("debug", `Processing tool: ${tool.name}`);
898
903
  try {
904
+ let requireApproval;
905
+ let needsApprovalFn;
906
+ if (typeof this.requireToolApproval === "function") {
907
+ const serverApprovalFn = this.requireToolApproval;
908
+ const toolName = tool.name;
909
+ requireApproval = true;
910
+ needsApprovalFn = (args, ctx = {}) => {
911
+ return serverApprovalFn({ toolName, args, ...ctx });
912
+ };
913
+ } else if (this.requireToolApproval === true) {
914
+ requireApproval = true;
915
+ }
899
916
  const mastraTool = createTool({
900
917
  id: `${this.name}_${tool.name}`,
901
918
  description: tool.description || "",
@@ -904,6 +921,7 @@ var InternalMastraMCPClient = class extends MastraBase {
904
921
  // already validates structuredContent against the tool's outputSchema using AJV.
905
922
  // Passing it here causes Zod to strip unrecognized keys from the CallToolResult
906
923
  // envelope, returning {} for tools without structuredContent.
924
+ requireApproval,
907
925
  mcpMetadata: {
908
926
  serverName: this.name,
909
927
  serverVersion: this.client.getServerVersion()?.version
@@ -963,6 +981,9 @@ var InternalMastraMCPClient = class extends MastraBase {
963
981
  });
964
982
  }
965
983
  });
984
+ if (needsApprovalFn) {
985
+ mastraTool.needsApprovalFn = needsApprovalFn;
986
+ }
966
987
  if (tool.name) {
967
988
  toolsRes[tool.name] = mastraTool;
968
989
  }
@@ -1800,7 +1821,8 @@ To fix this you have three different options:
1800
1821
  const mcpClient = new InternalMastraMCPClient({
1801
1822
  name,
1802
1823
  server: config,
1803
- timeout: config.timeout ?? this.defaultTimeout
1824
+ timeout: config.timeout ?? this.defaultTimeout,
1825
+ capabilities: config.capabilities
1804
1826
  });
1805
1827
  mcpClient.__setLogger(this.logger);
1806
1828
  this.mcpClientsById.set(name, mcpClient);
@@ -2040,7 +2062,7 @@ function createSimpleTokenProvider(accessToken, options) {
2040
2062
  });
2041
2063
  }
2042
2064
 
2043
- // ../../node_modules/.pnpm/hono@4.12.8/node_modules/hono/dist/utils/stream.js
2065
+ // ../../node_modules/.pnpm/hono@4.12.12/node_modules/hono/dist/utils/stream.js
2044
2066
  var StreamingApi = class {
2045
2067
  writer;
2046
2068
  encoder;
@@ -2117,7 +2139,7 @@ var StreamingApi = class {
2117
2139
  }
2118
2140
  };
2119
2141
 
2120
- // ../../node_modules/.pnpm/hono@4.12.8/node_modules/hono/dist/helper/streaming/utils.js
2142
+ // ../../node_modules/.pnpm/hono@4.12.12/node_modules/hono/dist/helper/streaming/utils.js
2121
2143
  var isOldBunVersion = () => {
2122
2144
  const version = typeof Bun !== "undefined" ? Bun.version : void 0;
2123
2145
  if (version === void 0) {
@@ -2128,7 +2150,7 @@ var isOldBunVersion = () => {
2128
2150
  return result;
2129
2151
  };
2130
2152
 
2131
- // ../../node_modules/.pnpm/hono@4.12.8/node_modules/hono/dist/utils/html.js
2153
+ // ../../node_modules/.pnpm/hono@4.12.12/node_modules/hono/dist/utils/html.js
2132
2154
  var HtmlEscapedCallbackPhase = {
2133
2155
  Stringify: 1};
2134
2156
  var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
@@ -2159,7 +2181,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
2159
2181
  }
2160
2182
  };
2161
2183
 
2162
- // ../../node_modules/.pnpm/hono@4.12.8/node_modules/hono/dist/helper/streaming/sse.js
2184
+ // ../../node_modules/.pnpm/hono@4.12.12/node_modules/hono/dist/helper/streaming/sse.js
2163
2185
  var SSEStreamingApi = class extends StreamingApi {
2164
2186
  constructor(writable, readable) {
2165
2187
  super(writable, readable);