@mcp-use/client 2.3.0 → 2.3.1-canary.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.
@@ -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.0";
131
+ var VERSION = "2.3.1-canary.1";
132
132
  function getPackageVersion() {
133
133
  return VERSION;
134
134
  }
package/dist/index.js CHANGED
@@ -1527,7 +1527,7 @@ init_connector_telemetry();
1527
1527
  init_logging();
1528
1528
 
1529
1529
  // src/utils/version.ts
1530
- var VERSION = "2.3.0";
1530
+ var VERSION = "2.3.1-canary.1";
1531
1531
  function getPackageVersion() {
1532
1532
  return VERSION;
1533
1533
  }
@@ -1905,7 +1905,7 @@ var HttpConnector = class extends BaseConnector {
1905
1905
  };
1906
1906
 
1907
1907
  // src/utils/version.ts
1908
- var VERSION = "2.3.0";
1908
+ var VERSION = "2.3.1-canary.1";
1909
1909
  function getPackageVersion() {
1910
1910
  return VERSION;
1911
1911
  }
@@ -4725,6 +4725,26 @@ function assert(condition, message) {
4725
4725
  throw new Error(message);
4726
4726
  }
4727
4727
  }
4728
+ function serializeClientIcons(icons) {
4729
+ if (icons === void 0) return "null";
4730
+ if (icons.length === 0) return "[]";
4731
+ return JSON.stringify(
4732
+ icons.map((icon) => [
4733
+ icon.src,
4734
+ icon.mimeType === void 0 ? null : icon.mimeType,
4735
+ icon.sizes === void 0 ? null : [...icon.sizes].sort()
4736
+ ])
4737
+ );
4738
+ }
4739
+ function serializeProxyHeaders(headers, customHeaders) {
4740
+ if (headers === void 0 && customHeaders === void 0) return "";
4741
+ const serializeEntries = (record) => {
4742
+ if (record === void 0) return "null";
4743
+ const keys = Object.keys(record).sort();
4744
+ return JSON.stringify(keys.map((k) => [k, record[k]]));
4745
+ };
4746
+ return `${serializeEntries(headers)}|${serializeEntries(customHeaders)}`;
4747
+ }
4728
4748
  async function loadServerIcon(params) {
4729
4749
  try {
4730
4750
  const iconUrl = params.serverInfo.icons?.[0]?.src;
@@ -5171,7 +5191,7 @@ function useMcp(options) {
5171
5191
  storageKeyPrefix = "mcp:auth",
5172
5192
  authProvider: providedAuthProvider,
5173
5193
  headers: headersOption,
5174
- proxyConfig,
5194
+ proxyConfig: rawProxyConfig,
5175
5195
  oauthProxyUrl: oauthProxyUrlOption,
5176
5196
  connectionMode,
5177
5197
  autoProxyFallback = false,
@@ -5197,6 +5217,34 @@ function useMcp(options) {
5197
5217
  onElicitation: onElicitationOption,
5198
5218
  oauth: oauthOptions
5199
5219
  } = options;
5220
+ const rawClientInfo = options.clientInfo;
5221
+ const clientInfoName = rawClientInfo?.name;
5222
+ const clientInfoTitle = rawClientInfo?.title;
5223
+ const clientInfoVersion = rawClientInfo?.version;
5224
+ const clientInfoDescription = rawClientInfo?.description;
5225
+ const clientInfoWebsiteUrl = rawClientInfo?.websiteUrl;
5226
+ const serializedClientIcons = serializeClientIcons(rawClientInfo?.icons);
5227
+ const clientInfo = useMemo(() => {
5228
+ if (!rawClientInfo) return void 0;
5229
+ return { ...rawClientInfo };
5230
+ }, [
5231
+ clientInfoName,
5232
+ clientInfoTitle,
5233
+ clientInfoVersion,
5234
+ clientInfoDescription,
5235
+ clientInfoWebsiteUrl,
5236
+ serializedClientIcons
5237
+ ]);
5238
+ const rawProxyAddress = rawProxyConfig?.proxyAddress;
5239
+ const serializedProxyHeaders = serializeProxyHeaders(
5240
+ rawProxyConfig?.headers,
5241
+ rawProxyConfig?.customHeaders
5242
+ );
5243
+ const proxyConfig = useMemo(() => {
5244
+ if (!rawProxyConfig) return void 0;
5245
+ return { ...rawProxyConfig };
5246
+ }, [rawProxyAddress, serializedProxyHeaders]);
5247
+ const headers = headersOption ?? {};
5200
5248
  const transportType = "http";
5201
5249
  const requestedProxyAddress = proxyConfig?.proxyAddress;
5202
5250
  const oauthClientId = oauthOptions?.clientId?.trim() || void 0;
@@ -5214,7 +5262,6 @@ function useMcp(options) {
5214
5262
  }
5215
5263
  return inst;
5216
5264
  }, [url, logLevelOption]);
5217
- const headers = headersOption ?? {};
5218
5265
  const effectiveClientOptions = useMemo(
5219
5266
  () => resolveClientOptions(clientOptions),
5220
5267
  [clientOptions]
@@ -5237,8 +5284,8 @@ function useMcp(options) {
5237
5284
  []
5238
5285
  );
5239
5286
  const mergedClientInfo = useMemo(
5240
- () => options.clientInfo ? { ...defaultClientInfo, ...options.clientInfo } : defaultClientInfo,
5241
- [options.clientInfo, defaultClientInfo]
5287
+ () => clientInfo ? { ...defaultClientInfo, ...clientInfo } : defaultClientInfo,
5288
+ [clientInfo, defaultClientInfo]
5242
5289
  );
5243
5290
  const derivedOAuthClientConfig = useMemo(
5244
5291
  () => deriveOAuthClientConfigFromClientInfo(mergedClientInfo),
@@ -8635,14 +8682,27 @@ function CloseIcon() {
8635
8682
  /* @__PURE__ */ React2.createElement("path", { d: "m6 6 12 12" })
8636
8683
  );
8637
8684
  }
8638
- function waitForSandboxProxyReady(iframe) {
8639
- return new Promise((resolve) => {
8685
+ function waitForSandboxProxyReady(iframe, options) {
8686
+ return new Promise((resolve, reject) => {
8687
+ const cleanup = () => {
8688
+ window.removeEventListener("message", listener);
8689
+ options?.signal?.removeEventListener("abort", onAbort);
8690
+ };
8640
8691
  const listener = (event) => {
8641
8692
  if (event.source === iframe.contentWindow && event.data?.method === SANDBOX_PROXY_READY) {
8642
- window.removeEventListener("message", listener);
8693
+ cleanup();
8643
8694
  resolve();
8644
8695
  }
8645
8696
  };
8697
+ const onAbort = () => {
8698
+ cleanup();
8699
+ reject(new Error("View sandbox initialization was aborted"));
8700
+ };
8701
+ if (options?.signal?.aborted) {
8702
+ onAbort();
8703
+ return;
8704
+ }
8705
+ options?.signal?.addEventListener("abort", onAbort, { once: true });
8646
8706
  window.addEventListener("message", listener);
8647
8707
  });
8648
8708
  }
@@ -8958,6 +9018,7 @@ function ViewRendererBase({
8958
9018
  if (!iframe) return;
8959
9019
  let disposed = false;
8960
9020
  let bridge = null;
9021
+ const abortController = new AbortController();
8961
9022
  const run = async () => {
8962
9023
  try {
8963
9024
  onLifecycleChangeRef.current?.({ status: "connecting" });
@@ -8969,17 +9030,23 @@ function ViewRendererBase({
8969
9030
  if (allowAttribute) {
8970
9031
  iframe.setAttribute("allow", allowAttribute);
8971
9032
  }
8972
- const readyPromise = waitForSandboxProxyReady(iframe);
8973
9033
  if (activeSandboxUrl.protocol === "blob:") {
8974
9034
  const response = await fetch(activeSandboxUrl.href);
8975
9035
  const sandboxHtml = await response.text();
8976
- if (disposed) return;
9036
+ if (disposed || abortController.signal.aborted) return;
9037
+ const readyPromise = waitForSandboxProxyReady(iframe, {
9038
+ signal: abortController.signal
9039
+ });
8977
9040
  iframe.srcdoc = sandboxHtml;
9041
+ await readyPromise;
8978
9042
  } else {
9043
+ const readyPromise = waitForSandboxProxyReady(iframe, {
9044
+ signal: abortController.signal
9045
+ });
8979
9046
  iframe.src = activeSandboxUrl.href;
9047
+ await readyPromise;
8980
9048
  }
8981
- await readyPromise;
8982
- if (disposed) return;
9049
+ if (disposed || abortController.signal.aborted) return;
8983
9050
  const capabilities = {
8984
9051
  ...effectiveHostCapabilities,
8985
9052
  sandbox: {
@@ -9190,7 +9257,7 @@ function ViewRendererBase({
9190
9257
  await publishAppTools();
9191
9258
  onLifecycleChangeRef.current?.({ status: "ready" });
9192
9259
  } catch (err) {
9193
- if (!disposed) {
9260
+ if (!disposed && !abortController.signal.aborted) {
9194
9261
  const message = err instanceof Error ? err.message : "Failed to connect view";
9195
9262
  setLoadError(message);
9196
9263
  onErrorRef.current?.(message);
@@ -9201,6 +9268,7 @@ function ViewRendererBase({
9201
9268
  void run();
9202
9269
  return () => {
9203
9270
  disposed = true;
9271
+ abortController.abort();
9204
9272
  const toClose = bridge;
9205
9273
  bridgeRef.current = null;
9206
9274
  onAppToolsChangedRef.current?.(null);