@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.
@@ -1901,7 +1901,7 @@ var HttpConnector = class extends BaseConnector {
1901
1901
  };
1902
1902
 
1903
1903
  // src/utils/version.ts
1904
- var VERSION = "2.2.1-canary.0";
1904
+ var VERSION = "2.2.1";
1905
1905
  function getPackageVersion() {
1906
1906
  return VERSION;
1907
1907
  }
@@ -4007,6 +4007,12 @@ var BaseMCPClient = class {
4007
4007
  * Map of server names to their active sessions.
4008
4008
  */
4009
4009
  sessions = {};
4010
+ /**
4011
+ * Tracks teardown by session identity so overlapping cleanup paths share the
4012
+ * same disconnect. In particular, createSession() can replace a session while
4013
+ * closeSession() is already disconnecting it.
4014
+ */
4015
+ sessionDisconnects = /* @__PURE__ */ new WeakMap();
4010
4016
  /**
4011
4017
  * List of server names that have active sessions.
4012
4018
  * This array is kept in sync with the sessions map and can be used
@@ -4040,6 +4046,15 @@ var BaseMCPClient = class {
4040
4046
  this.config = config;
4041
4047
  }
4042
4048
  }
4049
+ disconnectSession(session) {
4050
+ const existingDisconnect = this.sessionDisconnects.get(session);
4051
+ if (existingDisconnect) {
4052
+ return existingDisconnect;
4053
+ }
4054
+ const disconnect = Promise.resolve().then(() => session.disconnect());
4055
+ this.sessionDisconnects.set(session, disconnect);
4056
+ return disconnect;
4057
+ }
4043
4058
  /**
4044
4059
  * Creates a client instance from a configuration dictionary.
4045
4060
  *
@@ -4268,7 +4283,7 @@ var BaseMCPClient = class {
4268
4283
  if (previous && previous !== session) {
4269
4284
  try {
4270
4285
  logger.debug(`Disconnecting replaced session for server ${serverName}`);
4271
- await previous.disconnect();
4286
+ await this.disconnectSession(previous);
4272
4287
  } catch (e) {
4273
4288
  logger.error(
4274
4289
  `Error disconnecting replaced session for server '${serverName}': ${e}`
@@ -4453,7 +4468,7 @@ var BaseMCPClient = class {
4453
4468
  }
4454
4469
  try {
4455
4470
  logger.debug(`Closing session for server ${serverName}`);
4456
- await session.disconnect();
4471
+ await this.disconnectSession(session);
4457
4472
  } catch (e) {
4458
4473
  logger.error(`Error closing session for server '${serverName}': ${e}`);
4459
4474
  } finally {