@mcp-use/client 2.2.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/.tsbuildinfo +1 -1
- package/dist/core/base.d.ts +10 -1
- package/dist/core/base.d.ts.map +1 -1
- package/dist/core/skills.d.ts +8 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/index-browser.js +31 -3
- package/dist/index-browser.js.map +1 -1
- package/dist/index.js +31 -3
- package/dist/index.js.map +1 -1
- package/dist/react/index.js +31 -3
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -1901,7 +1901,7 @@ var HttpConnector = class extends BaseConnector {
|
|
|
1901
1901
|
};
|
|
1902
1902
|
|
|
1903
1903
|
// src/utils/version.ts
|
|
1904
|
-
var VERSION = "2.2.
|
|
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
|
*
|
|
@@ -4185,7 +4200,9 @@ var BaseMCPClient = class {
|
|
|
4185
4200
|
* lifecycle of connections and provide methods for calling tools, listing
|
|
4186
4201
|
* resources, and more.
|
|
4187
4202
|
*
|
|
4188
|
-
* If a session already exists for the server, it will be replaced with a new
|
|
4203
|
+
* If a session already exists for the server, it will be replaced with a new
|
|
4204
|
+
* one and the previous session is disconnected; any previously returned
|
|
4205
|
+
* reference to it becomes unusable.
|
|
4189
4206
|
*
|
|
4190
4207
|
* @param serverName - The name of the server as defined in the client configuration
|
|
4191
4208
|
* @param autoInitialize - Whether to automatically initialize the session (default: true)
|
|
@@ -4258,10 +4275,21 @@ var BaseMCPClient = class {
|
|
|
4258
4275
|
await completeOAuthFlow(oauthProvider, httpConfig.url);
|
|
4259
4276
|
session = await openSession();
|
|
4260
4277
|
}
|
|
4278
|
+
const previous = this.sessions[serverName];
|
|
4261
4279
|
this.sessions[serverName] = session;
|
|
4262
4280
|
if (!this.activeSessions.includes(serverName)) {
|
|
4263
4281
|
this.activeSessions.push(serverName);
|
|
4264
4282
|
}
|
|
4283
|
+
if (previous && previous !== session) {
|
|
4284
|
+
try {
|
|
4285
|
+
logger.debug(`Disconnecting replaced session for server ${serverName}`);
|
|
4286
|
+
await this.disconnectSession(previous);
|
|
4287
|
+
} catch (e) {
|
|
4288
|
+
logger.error(
|
|
4289
|
+
`Error disconnecting replaced session for server '${serverName}': ${e}`
|
|
4290
|
+
);
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4265
4293
|
return session;
|
|
4266
4294
|
}
|
|
4267
4295
|
/**
|
|
@@ -4440,7 +4468,7 @@ var BaseMCPClient = class {
|
|
|
4440
4468
|
}
|
|
4441
4469
|
try {
|
|
4442
4470
|
logger.debug(`Closing session for server ${serverName}`);
|
|
4443
|
-
await
|
|
4471
|
+
await this.disconnectSession(session);
|
|
4444
4472
|
} catch (e) {
|
|
4445
4473
|
logger.error(`Error closing session for server '${serverName}': ${e}`);
|
|
4446
4474
|
} finally {
|