@mcp-use/client 2.2.1-canary.0 → 2.2.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
@@ -1526,7 +1526,7 @@ init_connector_telemetry();
1526
1526
  init_logging();
1527
1527
 
1528
1528
  // src/utils/version.ts
1529
- var VERSION = "2.2.1-canary.0";
1529
+ var VERSION = "2.2.1";
1530
1530
  function getPackageVersion() {
1531
1531
  return VERSION;
1532
1532
  }
@@ -4143,6 +4143,12 @@ var BaseMCPClient = class {
4143
4143
  * Map of server names to their active sessions.
4144
4144
  */
4145
4145
  sessions = {};
4146
+ /**
4147
+ * Tracks teardown by session identity so overlapping cleanup paths share the
4148
+ * same disconnect. In particular, createSession() can replace a session while
4149
+ * closeSession() is already disconnecting it.
4150
+ */
4151
+ sessionDisconnects = /* @__PURE__ */ new WeakMap();
4146
4152
  /**
4147
4153
  * List of server names that have active sessions.
4148
4154
  * This array is kept in sync with the sessions map and can be used
@@ -4176,6 +4182,15 @@ var BaseMCPClient = class {
4176
4182
  this.config = config;
4177
4183
  }
4178
4184
  }
4185
+ disconnectSession(session) {
4186
+ const existingDisconnect = this.sessionDisconnects.get(session);
4187
+ if (existingDisconnect) {
4188
+ return existingDisconnect;
4189
+ }
4190
+ const disconnect = Promise.resolve().then(() => session.disconnect());
4191
+ this.sessionDisconnects.set(session, disconnect);
4192
+ return disconnect;
4193
+ }
4179
4194
  /**
4180
4195
  * Creates a client instance from a configuration dictionary.
4181
4196
  *
@@ -4404,7 +4419,7 @@ var BaseMCPClient = class {
4404
4419
  if (previous && previous !== session) {
4405
4420
  try {
4406
4421
  logger.debug(`Disconnecting replaced session for server ${serverName}`);
4407
- await previous.disconnect();
4422
+ await this.disconnectSession(previous);
4408
4423
  } catch (e) {
4409
4424
  logger.error(
4410
4425
  `Error disconnecting replaced session for server '${serverName}': ${e}`
@@ -4589,7 +4604,7 @@ var BaseMCPClient = class {
4589
4604
  }
4590
4605
  try {
4591
4606
  logger.debug(`Closing session for server ${serverName}`);
4592
- await session.disconnect();
4607
+ await this.disconnectSession(session);
4593
4608
  } catch (e) {
4594
4609
  logger.error(`Error closing session for server '${serverName}': ${e}`);
4595
4610
  } finally {