@mcp-use/client 2.3.1 → 2.3.2-canary.0

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.
@@ -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";
131
+ var VERSION = "2.3.2-canary.0";
132
132
  function getPackageVersion() {
133
133
  return VERSION;
134
134
  }
@@ -2164,7 +2164,6 @@ var BaseConnector = class {
2164
2164
  opts;
2165
2165
  notificationHandlers = [];
2166
2166
  rootsCache = [];
2167
- activeProgressHandlers = /* @__PURE__ */ new Set();
2168
2167
  /**
2169
2168
  * Creates a connector with shared SDK and callback options.
2170
2169
  *
@@ -2201,9 +2200,6 @@ var BaseConnector = class {
2201
2200
  */
2202
2201
  onNotification(handler) {
2203
2202
  this.notificationHandlers.push(handler);
2204
- if (this.client) {
2205
- this.setupNotificationHandler();
2206
- }
2207
2203
  }
2208
2204
  /** Forward a normalized notification to every registered consumer. */
2209
2205
  async forwardNotification(notification) {
@@ -2256,40 +2252,13 @@ var BaseConnector = class {
2256
2252
  ]) {
2257
2253
  const originalHandler = handlersMap.get(method);
2258
2254
  if (originalHandler) {
2259
- handlersMap.set(method, async (notification) => {
2260
- await originalHandler(notification);
2255
+ handlersMap.set(method, async (notification, ...args) => {
2256
+ await originalHandler(notification, ...args);
2261
2257
  await this.forwardNotification(notification);
2262
2258
  });
2263
2259
  }
2264
2260
  }
2265
2261
  }
2266
- /**
2267
- * Forward v2 MRTR progress whose retry request IDs are not associated with
2268
- * the original call callback by the current SDK beta.
2269
- *
2270
- * ponytail: fallback is enabled only when exactly one progress-aware call is
2271
- * active; remove it when the upstream SDK propagates handlers to MRTR rounds.
2272
- */
2273
- setupRoundProgressForwarding() {
2274
- if (!this.client) return;
2275
- const sdkClient = this.client;
2276
- const original = sdkClient._onnotification.bind(this.client);
2277
- sdkClient._onnotification = async (message) => {
2278
- if (message && typeof message === "object" && message.method === "notifications/progress") {
2279
- this.forwardRoundProgress(message.params);
2280
- }
2281
- await original?.(message);
2282
- };
2283
- }
2284
- /** Forward progress parsed from a transport stream to the active call. */
2285
- forwardRoundProgress(params) {
2286
- if (this.activeProgressHandlers.size === 1) {
2287
- const [handler] = this.activeProgressHandlers;
2288
- handler?.(
2289
- params
2290
- );
2291
- }
2292
- }
2293
2262
  /**
2294
2263
  * Auto-refresh tools cache when server sends tools/list_changed notification
2295
2264
  */
@@ -2642,17 +2611,11 @@ var BaseConnector = class {
2642
2611
  );
2643
2612
  }
2644
2613
  logger.debug(`Calling tool '${name}' with args`, args);
2645
- const progressHandler = enhancedOptions?.onprogress;
2646
- if (progressHandler) this.activeProgressHandlers.add(progressHandler);
2647
- try {
2648
- const res = await this.executeRequest(
2649
- () => this.client.callTool({ name, arguments: args }, enhancedOptions)
2650
- );
2651
- logger.debug(`Tool '${name}' returned`, res);
2652
- return res;
2653
- } finally {
2654
- if (progressHandler) this.activeProgressHandlers.delete(progressHandler);
2655
- }
2614
+ const res = await this.executeRequest(
2615
+ () => this.client.callTool({ name, arguments: args }, enhancedOptions)
2616
+ );
2617
+ logger.debug(`Tool '${name}' returned`, res);
2618
+ return res;
2656
2619
  }
2657
2620
  /**
2658
2621
  * List all available tools from the MCP server.
@@ -3267,53 +3230,6 @@ var HttpConnector = class extends BaseConnector {
3267
3230
  throw finalError;
3268
3231
  }
3269
3232
  }
3270
- /**
3271
- * Tee an SSE response so v2 MRTR progress can be correlated even when the
3272
- * upstream SDK does not carry the original callback to retry request IDs.
3273
- */
3274
- observeSseProgress(response) {
3275
- if (!response.body || !response.headers.get("content-type")?.includes("text/event-stream")) {
3276
- return response;
3277
- }
3278
- const [body, observed] = response.body.tee();
3279
- void (async () => {
3280
- const reader = observed.getReader();
3281
- const decoder = new TextDecoder();
3282
- let buffer = "";
3283
- try {
3284
- while (true) {
3285
- const { done, value } = await reader.read();
3286
- if (done) break;
3287
- buffer += decoder.decode(value, { stream: true });
3288
- const events = buffer.split(/\r?\n\r?\n/);
3289
- buffer = events.pop() ?? "";
3290
- for (const event of events) {
3291
- for (const line of event.split(/\r?\n/)) {
3292
- if (!line.startsWith("data:")) continue;
3293
- try {
3294
- const message = JSON.parse(line.slice(5).trim());
3295
- if (message.method === "notifications/progress") {
3296
- this.forwardRoundProgress(message.params);
3297
- }
3298
- } catch {
3299
- }
3300
- }
3301
- }
3302
- }
3303
- } catch (error) {
3304
- if (!(error instanceof DOMException && error.name === "AbortError")) {
3305
- logger.debug("Progress observer stream ended:", error);
3306
- }
3307
- } finally {
3308
- reader.releaseLock();
3309
- }
3310
- })();
3311
- return new Response(body, {
3312
- status: response.status,
3313
- statusText: response.statusText,
3314
- headers: response.headers
3315
- });
3316
- }
3317
3233
  async connectWithStreamableHttp(baseUrl) {
3318
3234
  try {
3319
3235
  logger.debug("[HttpConnector] Connecting with Streamable HTTP", {
@@ -3323,23 +3239,12 @@ var HttpConnector = class extends BaseConnector {
3323
3239
  authProviderUrl: this.opts.authProvider && "serverUrl" in this.opts.authProvider && typeof this.opts.authProvider.serverUrl === "string" ? this.opts.authProvider.serverUrl : "none",
3324
3240
  headers: this.headers
3325
3241
  });
3326
- const baseFetch = this.customFetch ?? globalThis.fetch.bind(globalThis);
3327
- const observedFetch = async (input, init) => {
3328
- const response = await baseFetch(input, init);
3329
- const requestHeaders = new Headers(
3330
- input instanceof Request ? input.headers : void 0
3331
- );
3332
- new Headers(init?.headers).forEach((value, key) => {
3333
- requestHeaders.set(key, value);
3334
- });
3335
- return requestHeaders.get("mcp-method") === "subscriptions/listen" ? response : this.observeSseProgress(response);
3336
- };
3337
3242
  const streamableTransport = new StreamableHTTPClientTransport2(
3338
3243
  new URL(baseUrl),
3339
3244
  {
3340
3245
  authProvider: this.opts.authProvider,
3341
3246
  // ← Pass OAuth provider to SDK
3342
- fetch: observedFetch,
3247
+ fetch: this.customFetch,
3343
3248
  requestInit: {
3344
3249
  headers: this.headers
3345
3250
  },