@mastra/mcp 2.2.1-alpha.0 → 2.3.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
@@ -23241,7 +23241,7 @@ var InternalMastraMCPClient = class extends MastraBase {
23241
23241
  /**
23242
23242
  * @internal
23243
23243
  */
23244
- constructor({ name, version = "1.0.0", server, timeout = DEFAULT_REQUEST_TIMEOUT_MSEC }) {
23244
+ constructor({ name, version = "1.0.0", clientInfo, server, timeout = DEFAULT_REQUEST_TIMEOUT_MSEC }) {
23245
23245
  super({ name: "MastraMCPClient" });
23246
23246
  this.name = name;
23247
23247
  this.timeout = timeout;
@@ -23262,8 +23262,8 @@ var InternalMastraMCPClient = class extends MastraBase {
23262
23262
  }
23263
23263
  };
23264
23264
  this.client = new Client({
23265
- name,
23266
- version
23265
+ name: clientInfo?.name ?? name,
23266
+ version: clientInfo?.version ?? version
23267
23267
  }, {
23268
23268
  capabilities: clientCapabilities,
23269
23269
  ...server.jsonSchemaValidator ? { jsonSchemaValidator: server.jsonSchemaValidator } : {},
@@ -24870,6 +24870,7 @@ var MCPClient = class extends MastraBase {
24870
24870
  serverConfigs = {};
24871
24871
  id;
24872
24872
  defaultTimeout;
24873
+ defaultClientInfo;
24873
24874
  mcpClientsById = /* @__PURE__ */ new Map();
24874
24875
  disconnectPromise = null;
24875
24876
  authFlowsByServer = /* @__PURE__ */ new Map();
@@ -24912,12 +24913,13 @@ var MCPClient = class extends MastraBase {
24912
24913
  constructor(args) {
24913
24914
  super({ name: "MCPClient" });
24914
24915
  this.defaultTimeout = args.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
24916
+ this.defaultClientInfo = args.clientInfo && { ...args.clientInfo };
24915
24917
  this.serverConfigs = args.servers;
24916
24918
  this.id = args.id ?? this.makeId();
24917
24919
  if (args.id) {
24918
24920
  this.id = args.id;
24919
24921
  const cached = mcpClientInstances.get(this.id);
24920
- if (cached && !equal(cached.serverConfigs, args.servers)) {
24922
+ if (cached && (!equal(cached.serverConfigs, args.servers) || !equal(cached.defaultClientInfo, args.clientInfo))) {
24921
24923
  const existingInstance = mcpClientInstances.get(this.id);
24922
24924
  if (existingInstance) {
24923
24925
  existingInstance.disconnect();
@@ -25343,7 +25345,10 @@ onListChanged: async (serverName, handler) => {
25343
25345
  if (!mcpClientInstances.has(this.id)) mcpClientInstances.set(this.id, this);
25344
25346
  }
25345
25347
  makeId() {
25346
- const text = JSON.stringify(this.serverConfigs).normalize("NFKC");
25348
+ const text = JSON.stringify(this.defaultClientInfo === void 0 ? this.serverConfigs : {
25349
+ servers: this.serverConfigs,
25350
+ clientInfo: this.defaultClientInfo
25351
+ }).normalize("NFKC");
25347
25352
  return createHash("sha256").update("MCPClient").update(text).digest("hex");
25348
25353
  }
25349
25354
  /**
@@ -25365,7 +25370,7 @@ onListChanged: async (serverName, handler) => {
25365
25370
  if (this.disconnectPromise) return this.disconnectPromise;
25366
25371
  this.disconnectPromise = (async () => {
25367
25372
  try {
25368
- mcpClientInstances.delete(this.id);
25373
+ if (mcpClientInstances.get(this.id) === this) mcpClientInstances.delete(this.id);
25369
25374
  const pendingFlows = Array.from(this.authFlowsByServer.values());
25370
25375
  for (const controller of this.authAbortControllersByServer.values()) controller.abort();
25371
25376
  await Promise.allSettled(Array.from(this.authCallbackServersByServer.values()).map((server) => server.close()));
@@ -25996,7 +26001,11 @@ onListChanged: async (serverName, handler) => {
25996
26001
  const mcpClient = new InternalMastraMCPClient({
25997
26002
  name,
25998
26003
  server: config,
25999
- timeout: config.timeout ?? this.defaultTimeout
26004
+ timeout: config.timeout ?? this.defaultTimeout,
26005
+ clientInfo: {
26006
+ name: config.clientInfo?.name ?? this.defaultClientInfo?.name,
26007
+ version: config.clientInfo?.version ?? this.defaultClientInfo?.version
26008
+ }
26000
26009
  });
26001
26010
  mcpClient.__setLogger(this.logger);
26002
26011
  this.mcpClientsById.set(name, mcpClient);