@mcp-use/client 2.3.1-canary.0 → 2.3.1-canary.2
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/code-mode/connector.d.ts +1 -2
- package/dist/code-mode/connector.d.ts.map +1 -1
- package/dist/index-browser.js +83 -13
- package/dist/index-browser.js.map +1 -1
- package/dist/index.js +85 -25
- package/dist/index.js.map +1 -1
- package/dist/react/index.js +134 -17
- package/dist/react/index.js.map +1 -1
- package/dist/react/useMcp-helpers.d.ts +21 -0
- package/dist/react/useMcp-helpers.d.ts.map +1 -1
- package/dist/react/useMcp.d.ts.map +1 -1
- package/dist/transport/base.d.ts +16 -1
- package/dist/transport/base.d.ts.map +1 -1
- package/dist/transport/http.d.ts +1 -1
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/stdio.d.ts +1 -1
- package/dist/transport/stdio.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -16,8 +16,7 @@ export declare class CodeModeConnector extends BaseConnector {
|
|
|
16
16
|
private mcpClient;
|
|
17
17
|
private _tools;
|
|
18
18
|
constructor(client: MCPClient);
|
|
19
|
-
|
|
20
|
-
disconnect(): Promise<void>;
|
|
19
|
+
protected establishTransport(): Promise<void>;
|
|
21
20
|
get publicIdentifier(): Record<string, string>;
|
|
22
21
|
private _createToolsList;
|
|
23
22
|
get tools(): Tool[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/code-mode/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,sBAAsB,0rGAsFlC,CAAC;AAKF;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/code-mode/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,sBAAsB,0rGAsFlC,CAAC;AAKF;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,SAAS;cAOJ,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5D,IAAI,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE7C;IAED,OAAO,CAAC,gBAAgB;IA4DxB,IAAI,KAAK,IAAI,IAAI,EAAE,CAElB;IAEK,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAK1B,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACxB,OAAO,CAAC,cAAc,CAAC;CAyC3B"}
|
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.3.1-canary.
|
|
131
|
+
var VERSION = "2.3.1-canary.2";
|
|
132
132
|
function getPackageVersion() {
|
|
133
133
|
return VERSION;
|
|
134
134
|
}
|
|
@@ -2158,6 +2158,9 @@ var BaseConnector = class {
|
|
|
2158
2158
|
serverInfoCache = null;
|
|
2159
2159
|
authorizationCache;
|
|
2160
2160
|
connected = false;
|
|
2161
|
+
connectPromise = null;
|
|
2162
|
+
disconnectPromise = null;
|
|
2163
|
+
disconnectGeneration = 0;
|
|
2161
2164
|
opts;
|
|
2162
2165
|
notificationHandlers = [];
|
|
2163
2166
|
rootsCache = [];
|
|
@@ -2420,6 +2423,54 @@ var BaseConnector = class {
|
|
|
2420
2423
|
"setupElicitationHandler: Elicitation handler registered successfully"
|
|
2421
2424
|
);
|
|
2422
2425
|
}
|
|
2426
|
+
/**
|
|
2427
|
+
* Establishes the transport connection and creates the SDK client.
|
|
2428
|
+
*
|
|
2429
|
+
* Coalesces concurrent connection attempts, synchronizes with ongoing
|
|
2430
|
+
* disconnections, and guarantees that orphaned processes or transports
|
|
2431
|
+
* are not leaked on failure or rapid disconnect.
|
|
2432
|
+
*
|
|
2433
|
+
* @returns A promise that resolves when the connector is connected.
|
|
2434
|
+
*/
|
|
2435
|
+
async connect() {
|
|
2436
|
+
const generation = this.disconnectGeneration;
|
|
2437
|
+
while (this.disconnectPromise) {
|
|
2438
|
+
await this.disconnectPromise;
|
|
2439
|
+
}
|
|
2440
|
+
if (generation !== this.disconnectGeneration) {
|
|
2441
|
+
throw new Error("Connection cancelled by disconnect");
|
|
2442
|
+
}
|
|
2443
|
+
if (this.connected) {
|
|
2444
|
+
logger.debug("Already connected to MCP implementation");
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
if (this.connectPromise) {
|
|
2448
|
+
return this.connectPromise;
|
|
2449
|
+
}
|
|
2450
|
+
const currentConnect = (async () => {
|
|
2451
|
+
try {
|
|
2452
|
+
await this.establishTransport();
|
|
2453
|
+
if (generation !== this.disconnectGeneration) {
|
|
2454
|
+
throw new Error("Connection cancelled by disconnect");
|
|
2455
|
+
}
|
|
2456
|
+
this.connected = true;
|
|
2457
|
+
} catch (err) {
|
|
2458
|
+
this.connected = false;
|
|
2459
|
+
await this.cleanupResources();
|
|
2460
|
+
throw err;
|
|
2461
|
+
} finally {
|
|
2462
|
+
this.connectPromise = null;
|
|
2463
|
+
}
|
|
2464
|
+
})();
|
|
2465
|
+
this.connectPromise = currentConnect;
|
|
2466
|
+
return this.connectPromise;
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Subclasses override this method to perform transport-specific connection logic.
|
|
2470
|
+
* Default implementation is a no-op for backwards compatibility.
|
|
2471
|
+
*/
|
|
2472
|
+
async establishTransport() {
|
|
2473
|
+
}
|
|
2423
2474
|
/**
|
|
2424
2475
|
* Run one logical MCP operation. HTTP connectors override this host seam to
|
|
2425
2476
|
* finish an SDK-started interactive OAuth flow and retry exactly once.
|
|
@@ -2445,17 +2496,42 @@ var BaseConnector = class {
|
|
|
2445
2496
|
/**
|
|
2446
2497
|
* Disconnects the SDK client and releases transport resources.
|
|
2447
2498
|
*
|
|
2499
|
+
* Coalesces concurrent calls and coordinates with in-flight connections
|
|
2500
|
+
* to ensure no child processes or transports are orphaned.
|
|
2501
|
+
*
|
|
2448
2502
|
* @returns A promise that resolves after cleanup completes.
|
|
2449
2503
|
*/
|
|
2450
2504
|
async disconnect() {
|
|
2451
|
-
|
|
2505
|
+
this.disconnectGeneration++;
|
|
2506
|
+
if (this.disconnectPromise) {
|
|
2507
|
+
return this.disconnectPromise;
|
|
2508
|
+
}
|
|
2509
|
+
if (!this.connected && !this.connectPromise) {
|
|
2452
2510
|
logger.debug("Not connected to MCP implementation");
|
|
2453
2511
|
return;
|
|
2454
2512
|
}
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2513
|
+
const currentDisconnect = (async () => {
|
|
2514
|
+
let connectFailed = false;
|
|
2515
|
+
try {
|
|
2516
|
+
if (this.connectPromise) {
|
|
2517
|
+
try {
|
|
2518
|
+
await this.connectPromise;
|
|
2519
|
+
} catch {
|
|
2520
|
+
connectFailed = true;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
if (!connectFailed) {
|
|
2524
|
+
logger.debug("Disconnecting from MCP implementation");
|
|
2525
|
+
await this.cleanupResources();
|
|
2526
|
+
}
|
|
2527
|
+
this.connected = false;
|
|
2528
|
+
logger.debug("Disconnected from MCP implementation");
|
|
2529
|
+
} finally {
|
|
2530
|
+
this.disconnectPromise = null;
|
|
2531
|
+
}
|
|
2532
|
+
})();
|
|
2533
|
+
this.disconnectPromise = currentDisconnect;
|
|
2534
|
+
return this.disconnectPromise;
|
|
2459
2535
|
}
|
|
2460
2536
|
/** Whether an SDK client currently exists for this connector. */
|
|
2461
2537
|
get isClientConnected() {
|
|
@@ -3152,11 +3228,7 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3152
3228
|
* @returns A promise that resolves after protocol negotiation completes.
|
|
3153
3229
|
* @throws An error with `code: 401` when authentication is required.
|
|
3154
3230
|
*/
|
|
3155
|
-
async
|
|
3156
|
-
if (this.connected) {
|
|
3157
|
-
logger.debug("Already connected to MCP implementation");
|
|
3158
|
-
return;
|
|
3159
|
-
}
|
|
3231
|
+
async establishTransport() {
|
|
3160
3232
|
const baseUrl = this.baseUrl;
|
|
3161
3233
|
logger.debug(`Connecting to MCP implementation via HTTP: ${baseUrl}`);
|
|
3162
3234
|
const oauthProvider = this.oauthProvider;
|
|
@@ -3175,7 +3247,6 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3175
3247
|
} catch (err) {
|
|
3176
3248
|
logger.debug("Streamable HTTP connect failed", err);
|
|
3177
3249
|
const { fallbackReason, is401Error, httpStatusCode } = this.classifyStreamableHttpFailure(err);
|
|
3178
|
-
await this.cleanupResources();
|
|
3179
3250
|
if (is401Error) {
|
|
3180
3251
|
logger.info("Authentication required");
|
|
3181
3252
|
const authError = new Error("Authentication required");
|
|
@@ -3349,7 +3420,6 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3349
3420
|
}
|
|
3350
3421
|
}
|
|
3351
3422
|
};
|
|
3352
|
-
this.connected = true;
|
|
3353
3423
|
this.transportType = "streamable-http";
|
|
3354
3424
|
logger.debug(
|
|
3355
3425
|
`Successfully connected to MCP implementation via streamable HTTP: ${baseUrl}`
|