@mastra/mcp 2.9.0-alpha.2 → 2.9.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.
package/dist/index.js CHANGED
@@ -19148,6 +19148,7 @@ onListChanged: async (serverName, handler) => {
19148
19148
  errorId: "MCP_CLIENT_GET_TOOLS_FAILED",
19149
19149
  logMessage: "Failed to list tools from server:"
19150
19150
  }, options);
19151
+ const keySources = /* @__PURE__ */ new Map();
19151
19152
  for (const { serverName, value, error, duration } of settled) {
19152
19153
  durations[serverName] = duration;
19153
19154
  if (error !== void 0) {
@@ -19155,7 +19156,7 @@ onListChanged: async (serverName, handler) => {
19155
19156
  errorDetails[serverName] = error;
19156
19157
  continue;
19157
19158
  }
19158
- for (const [toolName, toolConfig] of Object.entries(value)) connectedTools[`${serverName}_${toolName}`] = toolConfig;
19159
+ for (const [toolName, toolConfig] of Object.entries(value)) this.setNamespacedTool(connectedTools, keySources, serverName, toolName, toolConfig);
19159
19160
  }
19160
19161
  const result = {
19161
19162
  tools: connectedTools,
@@ -19327,16 +19328,18 @@ onListChanged: async (serverName, handler) => {
19327
19328
  async toolsFromDefinitions({ definitions: catalog }) {
19328
19329
  const configuredServers = new Set(Object.keys(this.serverConfigs));
19329
19330
  const tools = {};
19331
+ const keySources = /* @__PURE__ */ new Map();
19330
19332
  for (const [serverName, definitions] of Object.entries(catalog)) {
19331
19333
  if (!configuredServers.has(serverName)) {
19332
19334
  this.logger.warn("Skipping cached MCP tool definitions for a server that is no longer configured", { serverName });
19333
19335
  continue;
19334
19336
  }
19335
19337
  for (const [toolName, definition] of Object.entries(modelVisibleDefinitions(definitions))) try {
19336
- tools[`${serverName}_${toolName}`] = await this.toolFromDefinition({
19338
+ const tool = await this.toolFromDefinition({
19337
19339
  serverName,
19338
19340
  definition
19339
19341
  });
19342
+ this.setNamespacedTool(tools, keySources, serverName, toolName, tool);
19340
19343
  } catch (error) {
19341
19344
  if (!(error instanceof MastraError && error.id === "MCP_CLIENT_INVALID_TOOL_INPUT_SCHEMA")) throw error;
19342
19345
  }
@@ -19397,6 +19400,28 @@ onListChanged: async (serverName, handler) => {
19397
19400
  } : result;
19398
19401
  }
19399
19402
  /**
19403
+ * Stores a tool under its `serverName_toolName` key. Server and tool names can both contain `_`,
19404
+ * so two different pairs can produce one key (`local` + `x_status` and `local_x` + `status`).
19405
+ * The later pair keeps the key, as before; this logs a warning instead of dropping a tool silently.
19406
+ */
19407
+ setNamespacedTool(tools, keySources, serverName, toolName, tool) {
19408
+ const key = `${serverName}_${toolName}`;
19409
+ const replaced = keySources.get(key);
19410
+ if (replaced) this.logger.warn(`MCP tool key "${key}" from server "${serverName}" (tool "${toolName}") replaces the tool from server "${replaced.serverName}" (tool "${replaced.toolName}"), which produces the same key. Only the tool from "${serverName}" is kept. Rename one of the servers in \`servers\` to keep both.`, {
19411
+ key,
19412
+ replaced,
19413
+ replacedBy: {
19414
+ serverName,
19415
+ toolName
19416
+ }
19417
+ });
19418
+ keySources.set(key, {
19419
+ serverName,
19420
+ toolName
19421
+ });
19422
+ tools[key] = tool;
19423
+ }
19424
+ /**
19400
19425
  * Runs a per-server discovery `operation` against every configured server
19401
19426
  * concurrently, isolating and logging per-server failures. Results are
19402
19427
  * returned in configuration order (`Object.keys(serverConfigs)`) so callers