@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.
@@ -651,7 +651,6 @@ var BaseConnector = class {
651
651
  opts;
652
652
  notificationHandlers = [];
653
653
  rootsCache = [];
654
- activeProgressHandlers = /* @__PURE__ */ new Set();
655
654
  /**
656
655
  * Creates a connector with shared SDK and callback options.
657
656
  *
@@ -688,9 +687,6 @@ var BaseConnector = class {
688
687
  */
689
688
  onNotification(handler) {
690
689
  this.notificationHandlers.push(handler);
691
- if (this.client) {
692
- this.setupNotificationHandler();
693
- }
694
690
  }
695
691
  /** Forward a normalized notification to every registered consumer. */
696
692
  async forwardNotification(notification) {
@@ -743,40 +739,13 @@ var BaseConnector = class {
743
739
  ]) {
744
740
  const originalHandler = handlersMap.get(method);
745
741
  if (originalHandler) {
746
- handlersMap.set(method, async (notification) => {
747
- await originalHandler(notification);
742
+ handlersMap.set(method, async (notification, ...args) => {
743
+ await originalHandler(notification, ...args);
748
744
  await this.forwardNotification(notification);
749
745
  });
750
746
  }
751
747
  }
752
748
  }
753
- /**
754
- * Forward v2 MRTR progress whose retry request IDs are not associated with
755
- * the original call callback by the current SDK beta.
756
- *
757
- * ponytail: fallback is enabled only when exactly one progress-aware call is
758
- * active; remove it when the upstream SDK propagates handlers to MRTR rounds.
759
- */
760
- setupRoundProgressForwarding() {
761
- if (!this.client) return;
762
- const sdkClient = this.client;
763
- const original = sdkClient._onnotification.bind(this.client);
764
- sdkClient._onnotification = async (message) => {
765
- if (message && typeof message === "object" && message.method === "notifications/progress") {
766
- this.forwardRoundProgress(message.params);
767
- }
768
- await original?.(message);
769
- };
770
- }
771
- /** Forward progress parsed from a transport stream to the active call. */
772
- forwardRoundProgress(params) {
773
- if (this.activeProgressHandlers.size === 1) {
774
- const [handler] = this.activeProgressHandlers;
775
- handler?.(
776
- params
777
- );
778
- }
779
- }
780
749
  /**
781
750
  * Auto-refresh tools cache when server sends tools/list_changed notification
782
751
  */
@@ -1129,17 +1098,11 @@ var BaseConnector = class {
1129
1098
  );
1130
1099
  }
1131
1100
  logger.debug(`Calling tool '${name}' with args`, args);
1132
- const progressHandler = enhancedOptions?.onprogress;
1133
- if (progressHandler) this.activeProgressHandlers.add(progressHandler);
1134
- try {
1135
- const res = await this.executeRequest(
1136
- () => this.client.callTool({ name, arguments: args }, enhancedOptions)
1137
- );
1138
- logger.debug(`Tool '${name}' returned`, res);
1139
- return res;
1140
- } finally {
1141
- if (progressHandler) this.activeProgressHandlers.delete(progressHandler);
1142
- }
1101
+ const res = await this.executeRequest(
1102
+ () => this.client.callTool({ name, arguments: args }, enhancedOptions)
1103
+ );
1104
+ logger.debug(`Tool '${name}' returned`, res);
1105
+ return res;
1143
1106
  }
1144
1107
  /**
1145
1108
  * List all available tools from the MCP server.
@@ -1754,53 +1717,6 @@ var HttpConnector = class extends BaseConnector {
1754
1717
  throw finalError;
1755
1718
  }
1756
1719
  }
1757
- /**
1758
- * Tee an SSE response so v2 MRTR progress can be correlated even when the
1759
- * upstream SDK does not carry the original callback to retry request IDs.
1760
- */
1761
- observeSseProgress(response) {
1762
- if (!response.body || !response.headers.get("content-type")?.includes("text/event-stream")) {
1763
- return response;
1764
- }
1765
- const [body, observed] = response.body.tee();
1766
- void (async () => {
1767
- const reader = observed.getReader();
1768
- const decoder = new TextDecoder();
1769
- let buffer = "";
1770
- try {
1771
- while (true) {
1772
- const { done, value } = await reader.read();
1773
- if (done) break;
1774
- buffer += decoder.decode(value, { stream: true });
1775
- const events = buffer.split(/\r?\n\r?\n/);
1776
- buffer = events.pop() ?? "";
1777
- for (const event of events) {
1778
- for (const line of event.split(/\r?\n/)) {
1779
- if (!line.startsWith("data:")) continue;
1780
- try {
1781
- const message = JSON.parse(line.slice(5).trim());
1782
- if (message.method === "notifications/progress") {
1783
- this.forwardRoundProgress(message.params);
1784
- }
1785
- } catch {
1786
- }
1787
- }
1788
- }
1789
- }
1790
- } catch (error) {
1791
- if (!(error instanceof DOMException && error.name === "AbortError")) {
1792
- logger.debug("Progress observer stream ended:", error);
1793
- }
1794
- } finally {
1795
- reader.releaseLock();
1796
- }
1797
- })();
1798
- return new Response(body, {
1799
- status: response.status,
1800
- statusText: response.statusText,
1801
- headers: response.headers
1802
- });
1803
- }
1804
1720
  async connectWithStreamableHttp(baseUrl) {
1805
1721
  try {
1806
1722
  logger.debug("[HttpConnector] Connecting with Streamable HTTP", {
@@ -1810,23 +1726,12 @@ var HttpConnector = class extends BaseConnector {
1810
1726
  authProviderUrl: this.opts.authProvider && "serverUrl" in this.opts.authProvider && typeof this.opts.authProvider.serverUrl === "string" ? this.opts.authProvider.serverUrl : "none",
1811
1727
  headers: this.headers
1812
1728
  });
1813
- const baseFetch = this.customFetch ?? globalThis.fetch.bind(globalThis);
1814
- const observedFetch = async (input, init) => {
1815
- const response = await baseFetch(input, init);
1816
- const requestHeaders = new Headers(
1817
- input instanceof Request ? input.headers : void 0
1818
- );
1819
- new Headers(init?.headers).forEach((value, key) => {
1820
- requestHeaders.set(key, value);
1821
- });
1822
- return requestHeaders.get("mcp-method") === "subscriptions/listen" ? response : this.observeSseProgress(response);
1823
- };
1824
1729
  const streamableTransport = new StreamableHTTPClientTransport(
1825
1730
  new URL(baseUrl),
1826
1731
  {
1827
1732
  authProvider: this.opts.authProvider,
1828
1733
  // ← Pass OAuth provider to SDK
1829
- fetch: observedFetch,
1734
+ fetch: this.customFetch,
1830
1735
  requestInit: {
1831
1736
  headers: this.headers
1832
1737
  },
@@ -1975,7 +1880,7 @@ var HttpConnector = class extends BaseConnector {
1975
1880
  };
1976
1881
 
1977
1882
  // src/utils/version.ts
1978
- var VERSION = "2.3.1";
1883
+ var VERSION = "2.3.2-canary.0";
1979
1884
  function getPackageVersion() {
1980
1885
  return VERSION;
1981
1886
  }