@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/core/base.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ export declare abstract class BaseMCPClient {
|
|
|
40
40
|
* Map of server names to their active sessions.
|
|
41
41
|
*/
|
|
42
42
|
protected sessions: Record<string, MCPSession>;
|
|
43
|
+
/**
|
|
44
|
+
* Tracks teardown by session identity so overlapping cleanup paths share the
|
|
45
|
+
* same disconnect. In particular, createSession() can replace a session while
|
|
46
|
+
* closeSession() is already disconnecting it.
|
|
47
|
+
*/
|
|
48
|
+
private readonly sessionDisconnects;
|
|
43
49
|
/**
|
|
44
50
|
* List of server names that have active sessions.
|
|
45
51
|
* This array is kept in sync with the sessions map and can be used
|
|
@@ -69,6 +75,7 @@ export declare abstract class BaseMCPClient {
|
|
|
69
75
|
* ```
|
|
70
76
|
*/
|
|
71
77
|
constructor(config?: MCPClientConfigShape);
|
|
78
|
+
private disconnectSession;
|
|
72
79
|
/**
|
|
73
80
|
* Creates a client instance from a configuration dictionary.
|
|
74
81
|
*
|
|
@@ -214,7 +221,9 @@ export declare abstract class BaseMCPClient {
|
|
|
214
221
|
* lifecycle of connections and provide methods for calling tools, listing
|
|
215
222
|
* resources, and more.
|
|
216
223
|
*
|
|
217
|
-
* If a session already exists for the server, it will be replaced with a new
|
|
224
|
+
* If a session already exists for the server, it will be replaced with a new
|
|
225
|
+
* one and the previous session is disconnected; any previously returned
|
|
226
|
+
* reference to it becomes unusable.
|
|
218
227
|
*
|
|
219
228
|
* @param serverName - The name of the server as defined in the client configuration
|
|
220
229
|
* @param autoInitialize - Whether to automatically initialize the session (default: true)
|
package/dist/core/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/core/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAEhB,oBAAoB,EACpB,YAAY,EACb,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAiBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,8BAAsB,aAAa;IACjC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,oBAAoB,CAAM;IAE5C;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAM;IAEpD;;;;;;;;;OASG;IACI,cAAc,EAAE,MAAM,EAAE,CAAM;IAErC;;;;;;;;;;;;;;;;OAgBG;gBACS,MAAM,CAAC,EAAE,oBAAoB;IAMzC;;;;;;;;;;;;;;;;;;OAkBG;WACW,QAAQ,CAAC,IAAI,EAAE,oBAAoB,GAAG,aAAa;IAKjE;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,IAAI;IAMhE;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtD;;;;;;;;;;;;;;;;;OAiBG;IACI,cAAc,IAAI,MAAM,EAAE;IA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;;;;;;;;;;;OAsBG;IACI,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAQxD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;IAUrD;;;;;;;;;;;;;;;;;;;OAmBG;IACI,oBAAoB,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAMzD;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4B5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACU,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB9C,yCAAyC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
|
package/dist/core/skills.d.ts
CHANGED
|
@@ -18,22 +18,30 @@ export interface Skill {
|
|
|
18
18
|
}
|
|
19
19
|
/** Paginated result returned by `skills/list`. */
|
|
20
20
|
export interface SkillsListResult {
|
|
21
|
+
/** Skills on this page, in server order. */
|
|
21
22
|
skills: Skill[];
|
|
23
|
+
/** Cursor for the next page, absent on the final page. */
|
|
22
24
|
nextCursor?: string;
|
|
23
25
|
}
|
|
24
26
|
/** Result returned by `skills/get`. */
|
|
25
27
|
export interface SkillGetResult {
|
|
28
|
+
/** The requested skill. */
|
|
26
29
|
skill: Skill;
|
|
27
30
|
}
|
|
28
31
|
/** One child returned by `resources/directory/read`. */
|
|
29
32
|
export interface SkillDirectoryEntry {
|
|
33
|
+
/** Resource URI of the child. */
|
|
30
34
|
uri: string;
|
|
35
|
+
/** Display name of the child when the server provides one. */
|
|
31
36
|
name?: string;
|
|
37
|
+
/** MIME type of the child when the server provides one. */
|
|
32
38
|
mimeType?: string;
|
|
33
39
|
}
|
|
34
40
|
/** Paginated result returned by `resources/directory/read`. */
|
|
35
41
|
export interface SkillDirectoryReadResult {
|
|
42
|
+
/** Directory children on this page, in server order. */
|
|
36
43
|
resources: SkillDirectoryEntry[];
|
|
44
|
+
/** Cursor for the next page, absent on the final page. */
|
|
37
45
|
nextCursor?: string;
|
|
38
46
|
}
|
|
39
47
|
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,eAAO,MAAM,mBAAmB,EAAG,gCAAyC,CAAC;AAE7E,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,yEAAyE;AACzE,MAAM,WAAW,KAAK;IACpB,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,yEAAyE;IACzE,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,+DAA+D;AAC/D,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,eAAO,MAAM,mBAAmB,EAAG,gCAAyC,CAAC;AAE7E,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,yEAAyE;AACzE,MAAM,WAAW,KAAK;IACpB,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,yEAAyE;IACzE,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,2BAA2B;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IAClC,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,+DAA+D;AAC/D,MAAM,WAAW,wBAAwB;IACvC,wDAAwD;IACxD,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/index-browser.js
CHANGED
|
@@ -128,7 +128,7 @@ var Logger = class {
|
|
|
128
128
|
var logger = Logger.get();
|
|
129
129
|
|
|
130
130
|
// src/utils/version.ts
|
|
131
|
-
var VERSION = "2.2.
|
|
131
|
+
var VERSION = "2.2.1";
|
|
132
132
|
function getPackageVersion() {
|
|
133
133
|
return VERSION;
|
|
134
134
|
}
|
|
@@ -4023,6 +4023,12 @@ var BaseMCPClient = class {
|
|
|
4023
4023
|
* Map of server names to their active sessions.
|
|
4024
4024
|
*/
|
|
4025
4025
|
sessions = {};
|
|
4026
|
+
/**
|
|
4027
|
+
* Tracks teardown by session identity so overlapping cleanup paths share the
|
|
4028
|
+
* same disconnect. In particular, createSession() can replace a session while
|
|
4029
|
+
* closeSession() is already disconnecting it.
|
|
4030
|
+
*/
|
|
4031
|
+
sessionDisconnects = /* @__PURE__ */ new WeakMap();
|
|
4026
4032
|
/**
|
|
4027
4033
|
* List of server names that have active sessions.
|
|
4028
4034
|
* This array is kept in sync with the sessions map and can be used
|
|
@@ -4056,6 +4062,15 @@ var BaseMCPClient = class {
|
|
|
4056
4062
|
this.config = config;
|
|
4057
4063
|
}
|
|
4058
4064
|
}
|
|
4065
|
+
disconnectSession(session) {
|
|
4066
|
+
const existingDisconnect = this.sessionDisconnects.get(session);
|
|
4067
|
+
if (existingDisconnect) {
|
|
4068
|
+
return existingDisconnect;
|
|
4069
|
+
}
|
|
4070
|
+
const disconnect = Promise.resolve().then(() => session.disconnect());
|
|
4071
|
+
this.sessionDisconnects.set(session, disconnect);
|
|
4072
|
+
return disconnect;
|
|
4073
|
+
}
|
|
4059
4074
|
/**
|
|
4060
4075
|
* Creates a client instance from a configuration dictionary.
|
|
4061
4076
|
*
|
|
@@ -4201,7 +4216,9 @@ var BaseMCPClient = class {
|
|
|
4201
4216
|
* lifecycle of connections and provide methods for calling tools, listing
|
|
4202
4217
|
* resources, and more.
|
|
4203
4218
|
*
|
|
4204
|
-
* If a session already exists for the server, it will be replaced with a new
|
|
4219
|
+
* If a session already exists for the server, it will be replaced with a new
|
|
4220
|
+
* one and the previous session is disconnected; any previously returned
|
|
4221
|
+
* reference to it becomes unusable.
|
|
4205
4222
|
*
|
|
4206
4223
|
* @param serverName - The name of the server as defined in the client configuration
|
|
4207
4224
|
* @param autoInitialize - Whether to automatically initialize the session (default: true)
|
|
@@ -4274,10 +4291,21 @@ var BaseMCPClient = class {
|
|
|
4274
4291
|
await completeOAuthFlow(oauthProvider, httpConfig.url);
|
|
4275
4292
|
session = await openSession();
|
|
4276
4293
|
}
|
|
4294
|
+
const previous = this.sessions[serverName];
|
|
4277
4295
|
this.sessions[serverName] = session;
|
|
4278
4296
|
if (!this.activeSessions.includes(serverName)) {
|
|
4279
4297
|
this.activeSessions.push(serverName);
|
|
4280
4298
|
}
|
|
4299
|
+
if (previous && previous !== session) {
|
|
4300
|
+
try {
|
|
4301
|
+
logger.debug(`Disconnecting replaced session for server ${serverName}`);
|
|
4302
|
+
await this.disconnectSession(previous);
|
|
4303
|
+
} catch (e) {
|
|
4304
|
+
logger.error(
|
|
4305
|
+
`Error disconnecting replaced session for server '${serverName}': ${e}`
|
|
4306
|
+
);
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4281
4309
|
return session;
|
|
4282
4310
|
}
|
|
4283
4311
|
/**
|
|
@@ -4456,7 +4484,7 @@ var BaseMCPClient = class {
|
|
|
4456
4484
|
}
|
|
4457
4485
|
try {
|
|
4458
4486
|
logger.debug(`Closing session for server ${serverName}`);
|
|
4459
|
-
await
|
|
4487
|
+
await this.disconnectSession(session);
|
|
4460
4488
|
} catch (e) {
|
|
4461
4489
|
logger.error(`Error closing session for server '${serverName}': ${e}`);
|
|
4462
4490
|
} finally {
|