@mcp-use/inspector 20.0.0-beta.15 → 20.0.0-beta.16

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.
@@ -37672,7 +37672,7 @@ function YE() {
37672
37672
  let e = window.__INSPECTOR_VERSION__;
37673
37673
  if (e !== void 0 && e !== "") return e;
37674
37674
  }
37675
- return "20.0.0-beta.14";
37675
+ return "20.0.0-beta.15";
37676
37676
  } catch {
37677
37677
  return "0.0.0";
37678
37678
  }
@@ -49208,8 +49208,7 @@ var aV = class {
49208
49208
  }
49209
49209
  }
49210
49210
  getProxyFetch(e) {
49211
- if (!this.proxyOAuthRequests || !this.oauthProxyUrl) return e;
49212
- let t = e ?? globalThis.fetch.bind(globalThis), n = this.oauthProxyUrl, r = /* @__PURE__ */ new Set(), i = !1;
49211
+ let t = e ?? globalThis.fetch.bind(globalThis), n = this.proxyOAuthRequests && this.oauthProxyUrl ? this.oauthProxyUrl : void 0, r = /* @__PURE__ */ new Set(), i = !1;
49213
49212
  return async (e, a) => {
49214
49213
  let o = typeof e == "string" ? e : e instanceof URL ? e.toString() : e.url, s = this.reanchorWellKnownUrl(o), c;
49215
49214
  try {
@@ -49218,6 +49217,10 @@ var aV = class {
49218
49217
  return await t(e, a);
49219
49218
  }
49220
49219
  let l = c.includes("/.well-known/");
49220
+ if (!n) return await t(l ? s : e, l ? {
49221
+ ...a,
49222
+ cache: "no-store"
49223
+ } : a);
49221
49224
  if (!i) {
49222
49225
  i = !0;
49223
49226
  let e = (await this.discoveryState())?.authorizationServerMetadata;
@@ -49238,7 +49241,8 @@ var aV = class {
49238
49241
  if (l) {
49239
49242
  let e = await t(d, {
49240
49243
  ...a,
49241
- method: "GET"
49244
+ method: "GET",
49245
+ cache: "no-store"
49242
49246
  });
49243
49247
  try {
49244
49248
  let t = await e.clone().json();
@@ -49285,7 +49289,9 @@ var aV = class {
49285
49289
  return this.staticClientInfo ? this.staticClientInfo : this.session.clientInformation(e);
49286
49290
  }
49287
49291
  async saveClientInformation(e, t) {
49288
- if (!this.staticClientInfo) return this.session.saveClientInformation(e, t);
49292
+ if (this.staticClientInfo) return;
49293
+ let { client_secret: n, ...r } = e;
49294
+ return n && console.info(`[${this.storageKeyPrefix}] Discarded client_secret returned for a public browser OAuth client.`), this.session.saveClientInformation(r, t);
49289
49295
  }
49290
49296
  codeVerifier() {
49291
49297
  return this.session.codeVerifier();
@@ -52879,8 +52885,7 @@ var KH = class {
52879
52885
  }
52880
52886
  }
52881
52887
  getProxyFetch(e) {
52882
- if (!this.proxyOAuthRequests || !this.oauthProxyUrl) return e;
52883
- let t = e ?? globalThis.fetch.bind(globalThis), n = this.oauthProxyUrl, r = /* @__PURE__ */ new Set(), i = !1;
52888
+ let t = e ?? globalThis.fetch.bind(globalThis), n = this.proxyOAuthRequests && this.oauthProxyUrl ? this.oauthProxyUrl : void 0, r = /* @__PURE__ */ new Set(), i = !1;
52884
52889
  return async (e, a) => {
52885
52890
  let o = typeof e == "string" ? e : e instanceof URL ? e.toString() : e.url, s = this.reanchorWellKnownUrl(o), c;
52886
52891
  try {
@@ -52889,6 +52894,10 @@ var KH = class {
52889
52894
  return await t(e, a);
52890
52895
  }
52891
52896
  let l = c.includes("/.well-known/");
52897
+ if (!n) return await t(l ? s : e, l ? {
52898
+ ...a,
52899
+ cache: "no-store"
52900
+ } : a);
52892
52901
  if (!i) {
52893
52902
  i = !0;
52894
52903
  let e = (await this.discoveryState())?.authorizationServerMetadata;
@@ -52909,7 +52918,8 @@ var KH = class {
52909
52918
  if (l) {
52910
52919
  let e = await t(d, {
52911
52920
  ...a,
52912
- method: "GET"
52921
+ method: "GET",
52922
+ cache: "no-store"
52913
52923
  });
52914
52924
  try {
52915
52925
  let t = await e.clone().json();
@@ -52956,7 +52966,9 @@ var KH = class {
52956
52966
  return this.staticClientInfo ? this.staticClientInfo : this.session.clientInformation(e);
52957
52967
  }
52958
52968
  async saveClientInformation(e, t) {
52959
- if (!this.staticClientInfo) return this.session.saveClientInformation(e, t);
52969
+ if (this.staticClientInfo) return;
52970
+ let { client_secret: n, ...r } = e;
52971
+ return n && console.info(`[${this.storageKeyPrefix}] Discarded client_secret returned for a public browser OAuth client.`), this.session.saveClientInformation(r, t);
52960
52972
  }
52961
52973
  codeVerifier() {
52962
52974
  return this.session.codeVerifier();
@@ -53948,225 +53960,242 @@ function Ice(e) {
53948
53960
  }
53949
53961
  var sU = 3e3, Lce = 5e3;
53950
53962
  function Rce(e) {
53951
- let { url: t, enabled: n = !0, callbackUrl: r = typeof window < "u" ? GH(new URL("/oauth/callback", window.location.origin).toString()) : "/oauth/callback", storageKeyPrefix: i = "mcp:auth", authProvider: a, headers: o, proxyConfig: s, oauthProxyUrl: c, autoProxyFallback: l = !1, logLevel: u = "silent", autoRetry: d = !1, autoReconnect: f = !0, reconnectionOptions: p, preventAutoAuth: m = !0, useRedirectFlow: h = !1, onPopupWindow: g, timeout: _ = 3e4, wrapTransport: v, serverId: y, fetch: b, clientOptions: x, protocolNegotiation: S, onNotification: C, onSampling: w, onElicitation: T, oauth: E } = e, D = "http", O = E?.clientId?.trim() || void 0, k = E?.clientMetadataUrl?.trim() || void 0, A = E?.scope?.trim() || void 0, j = (0, M.useMemo)(() => O ? { client_id: O } : void 0, [O]), N = (0, M.useMemo)(() => {
53963
+ let { url: t, enabled: n = !0, callbackUrl: r = typeof window < "u" ? GH(new URL("/oauth/callback", window.location.origin).toString()) : "/oauth/callback", storageKeyPrefix: i = "mcp:auth", authProvider: a, headers: o, proxyConfig: s, oauthProxyUrl: c, connectionMode: l, autoProxyFallback: u = !1, logLevel: d = "silent", autoRetry: f = !1, autoReconnect: p = !0, reconnectionOptions: m, preventAutoAuth: h = !0, useRedirectFlow: g = !1, onPopupWindow: _, timeout: v = 3e4, wrapTransport: y, serverId: b, fetch: x, clientOptions: S, protocolNegotiation: C, onNotification: w, onSampling: T, onElicitation: E, oauth: D } = e, O = "http", k = s?.proxyAddress, A = D?.clientId?.trim() || void 0, j = D?.clientMetadataUrl?.trim() || void 0, N = D?.scope?.trim() || void 0, P = (0, M.useMemo)(() => A ? { client_id: A } : void 0, [A]), F = (0, M.useMemo)(() => {
53952
53964
  let e = `useMcp:${t || "no-url"}`, n = OH.get(e);
53953
- return u && (n.level = u), n;
53954
- }, [t, u]), P = o ?? {}, F = (0, M.useMemo)(() => Kse(x), [x]), I = w, L = T, R = (0, M.useMemo)(() => ({
53965
+ return d && (n.level = d), n;
53966
+ }, [t, d]), I = o ?? {}, L = (0, M.useMemo)(() => Kse(S), [S]), R = T, z = E, B = (0, M.useMemo)(() => ({
53955
53967
  name: "mcp-use",
53956
53968
  title: "mcp-use",
53957
53969
  version: WH(),
53958
53970
  description: "mcp-use is a complete TypeScript framework for building and using MCP",
53959
53971
  icons: [{ src: "https://mcp-use.com/logo.png" }],
53960
53972
  websiteUrl: "https://mcp-use.com"
53961
- }), []), z = (0, M.useMemo)(() => e.clientInfo ? {
53962
- ...R,
53973
+ }), []), V = (0, M.useMemo)(() => e.clientInfo ? {
53974
+ ...B,
53963
53975
  ...e.clientInfo
53964
- } : R, [e.clientInfo, R]), B = (0, M.useMemo)(() => Mce(z), [z]), V = (0, M.useMemo)(() => {
53965
- if (!l) return {
53976
+ } : B, [e.clientInfo, B]), H = (0, M.useMemo)(() => Mce(V), [V]), U = (0, M.useMemo)(() => {
53977
+ if (l === "direct" || l === "proxy" || !u) return {
53966
53978
  enabled: !1,
53967
53979
  proxyAddress: void 0
53968
53980
  };
53969
- if (typeof l == "boolean") {
53981
+ if (typeof u == "boolean") {
53970
53982
  let e = s?.proxyAddress;
53971
53983
  return {
53972
- enabled: l && !!e,
53984
+ enabled: u && !!e,
53973
53985
  proxyAddress: e
53974
53986
  };
53975
53987
  }
53976
- let e = l.proxyAddress ?? s?.proxyAddress;
53988
+ let e = u.proxyAddress ?? s?.proxyAddress;
53977
53989
  return {
53978
- enabled: l.enabled !== !1 && !!e,
53990
+ enabled: u.enabled !== !1 && !!e,
53979
53991
  proxyAddress: e
53980
53992
  };
53981
- }, [l, s]), H = (0, M.useMemo)(() => f === !1 ? {
53993
+ }, [
53994
+ u,
53995
+ l,
53996
+ s
53997
+ ]), W = (0, M.useMemo)(() => p === !1 ? {
53982
53998
  enabled: !1,
53983
53999
  initialDelay: 0,
53984
54000
  healthCheckInterval: !1,
53985
54001
  healthCheckTimeout: 3e4
53986
- } : f === !0 ? {
54002
+ } : p === !0 ? {
53987
54003
  enabled: !0,
53988
54004
  initialDelay: sU,
53989
54005
  healthCheckInterval: 1e4,
53990
54006
  healthCheckTimeout: 3e4
53991
- } : typeof f == "number" ? {
54007
+ } : typeof p == "number" ? {
53992
54008
  enabled: !0,
53993
- initialDelay: f,
54009
+ initialDelay: p,
53994
54010
  healthCheckInterval: 1e4,
53995
54011
  healthCheckTimeout: 3e4
53996
54012
  } : {
53997
- enabled: f.enabled !== !1,
53998
- initialDelay: f.initialDelay ?? sU,
53999
- healthCheckInterval: f.healthCheckInterval ?? 1e4,
54000
- healthCheckTimeout: f.healthCheckTimeout ?? 3e4
54001
- }, [f]), [U, W] = (0, M.useState)(void 0);
54013
+ enabled: p.enabled !== !1,
54014
+ initialDelay: p.initialDelay ?? sU,
54015
+ healthCheckInterval: p.healthCheckInterval ?? 1e4,
54016
+ healthCheckTimeout: p.healthCheckTimeout ?? 3e4
54017
+ }, [p]), [G, ee] = (0, M.useState)(void 0);
54002
54018
  (0, M.useEffect)(() => {
54003
- W(void 0);
54004
- }, [t, s]);
54005
- let G = (0, M.useMemo)(() => {
54006
- if (!U?.proxyAddress) return s;
54007
- let e = s?.headers ?? {};
54008
- return {
54009
- ...U,
54010
- headers: {
54011
- ...e,
54012
- ...U.headers ?? {}
54013
- }
54014
- };
54015
- }, [U, s]), ee = G?.proxyAddress, te = G?.headers ?? {}, ne = (0, M.useMemo)(() => t || "", [t]), re = (0, M.useMemo)(() => ({
54016
- ...te,
54017
- ...P
54018
- }), [te, P]), [ie, K] = (0, M.useState)("discovering"), [ae, oe] = (0, M.useState)([]), [se, ce] = (0, M.useState)([]), [q, le] = (0, M.useState)([]), [ue, de] = (0, M.useState)([]), [fe, pe] = (0, M.useState)(e._initialServerInfo?.name ? e._initialServerInfo : void 0), [me, he] = (0, M.useState)(), [ge, _e] = (0, M.useState)(void 0), [ve, ye] = (0, M.useState)(void 0), [be, xe] = (0, M.useState)(), [Se, Ce] = (0, M.useState)({}), [we, Te] = (0, M.useState)(void 0), [Ee, De] = (0, M.useState)([]), [Oe, ke] = (0, M.useState)(void 0), [Ae, je] = (0, M.useState)(void 0), Me = (0, M.useRef)(null), Ne = (0, M.useRef)(null), Pe = (0, M.useRef)(a ?? null), Fe = (0, M.useRef)(null), Ie = (0, M.useRef)(!1), Le = (0, M.useRef)(!0), Re = (0, M.useRef)(0), ze = (0, M.useRef)(0), Be = (0, M.useRef)(null), Ve = (0, M.useRef)(!1), He = (0, M.useRef)(!1), Ue = (0, M.useRef)(ie), We = (0, M.useRef)(f), Ge = (0, M.useRef)(null), Ke = (0, M.useRef)(null), qe = (0, M.useRef)(null), Je = (0, M.useRef)(I), Ye = (0, M.useRef)(L), Xe = (0, M.useRef)(I !== void 0), Ze = (0, M.useRef)(L !== void 0), Qe = (0, M.useRef)(C);
54019
- I !== void 0 && (Je.current = I), L !== void 0 && (Ye.current = L), Xe.current = I !== void 0, Ze.current = L !== void 0, Qe.current = C;
54020
- let $e = (0, M.useCallback)(async (e) => Je.current(e), []), et = (0, M.useCallback)(async (e) => Ye.current(e), []), tt = (0, M.useCallback)((e) => {
54021
- Qe.current?.(e);
54019
+ ee(void 0);
54020
+ }, [
54021
+ t,
54022
+ k,
54023
+ l,
54024
+ U.proxyAddress
54025
+ ]);
54026
+ let te = (0, M.useMemo)(() => {
54027
+ if (U.enabled && G?.proxyAddress === U.proxyAddress && G) {
54028
+ let e = s?.headers ?? {};
54029
+ return {
54030
+ ...G,
54031
+ headers: {
54032
+ ...e,
54033
+ ...G.headers ?? {}
54034
+ }
54035
+ };
54036
+ }
54037
+ return l === "auto" || l === "direct" || l === void 0 && U.enabled ? void 0 : s;
54038
+ }, [
54039
+ G,
54040
+ s,
54041
+ l,
54042
+ U.enabled,
54043
+ U.proxyAddress
54044
+ ]), ne = te?.proxyAddress, re = te?.headers ?? {}, ie = (0, M.useMemo)(() => t || "", [t]), K = (0, M.useMemo)(() => ({
54045
+ ...re,
54046
+ ...I
54047
+ }), [re, I]), [ae, oe] = (0, M.useState)("discovering"), [se, ce] = (0, M.useState)([]), [q, le] = (0, M.useState)([]), [ue, de] = (0, M.useState)([]), [fe, pe] = (0, M.useState)([]), [me, he] = (0, M.useState)(e._initialServerInfo?.name ? e._initialServerInfo : void 0), [ge, _e] = (0, M.useState)(), [ve, ye] = (0, M.useState)(void 0), [be, xe] = (0, M.useState)(void 0), [Se, Ce] = (0, M.useState)(), [we, Te] = (0, M.useState)({}), [Ee, De] = (0, M.useState)(void 0), [Oe, ke] = (0, M.useState)([]), [Ae, je] = (0, M.useState)(void 0), [Me, Ne] = (0, M.useState)(void 0), Pe = (0, M.useRef)(null), Fe = (0, M.useRef)(null), Ie = (0, M.useRef)(a ?? null), Le = (0, M.useRef)(null), Re = (0, M.useRef)(!1), ze = (0, M.useRef)(!0), Be = (0, M.useRef)(0), Ve = (0, M.useRef)(0), He = (0, M.useRef)(null), Ue = (0, M.useRef)(!1), We = (0, M.useRef)(!1), Ge = (0, M.useRef)(ae), Ke = (0, M.useRef)(p), qe = (0, M.useRef)(null), Je = (0, M.useRef)(null), Ye = (0, M.useRef)(null), Xe = (0, M.useRef)(R), Ze = (0, M.useRef)(z), Qe = (0, M.useRef)(R !== void 0), $e = (0, M.useRef)(z !== void 0), et = (0, M.useRef)(w);
54048
+ R !== void 0 && (Xe.current = R), z !== void 0 && (Ze.current = z), Qe.current = R !== void 0, $e.current = z !== void 0, et.current = w;
54049
+ let tt = (0, M.useCallback)(async (e) => Xe.current(e), []), nt = (0, M.useCallback)(async (e) => Ze.current(e), []), rt = (0, M.useCallback)((e) => {
54050
+ et.current?.(e);
54022
54051
  }, []);
54023
54052
  (0, M.useEffect)(() => {
54024
- Ue.current = ie, We.current = f;
54025
- }, [ie, f]), (0, M.useEffect)(() => {
54026
- Pe.current = a ?? null;
54053
+ Ge.current = ae, Ke.current = p;
54054
+ }, [ae, p]), (0, M.useEffect)(() => {
54055
+ Ie.current = a ?? null;
54027
54056
  }, [a]);
54028
- let nt = (0, M.useCallback)((e, t, ...n) => {
54057
+ let it = (0, M.useCallback)((e, t, ...n) => {
54029
54058
  let r = n.length > 0 ? `${t} ${n.map((e) => JSON.stringify(e)).join(" ")}` : t, i = `[useMcp] ${r}`;
54030
54059
  switch (e) {
54031
54060
  case "error":
54032
- N.error(i);
54061
+ F.error(i);
54033
54062
  break;
54034
54063
  case "warn":
54035
- N.warn(i);
54064
+ F.warn(i);
54036
54065
  break;
54037
54066
  case "info":
54038
- N.info(i);
54067
+ F.info(i);
54039
54068
  break;
54040
54069
  case "debug":
54041
- N.debug(i);
54070
+ F.debug(i);
54042
54071
  break;
54043
- default: N.info(i);
54072
+ default: F.info(i);
54044
54073
  }
54045
- Le.current && De((t) => [...t.slice(-100), {
54074
+ ze.current && ke((t) => [...t.slice(-100), {
54046
54075
  level: e,
54047
54076
  message: r,
54048
54077
  timestamp: Date.now()
54049
54078
  }]);
54050
- }, [N]), rt = Ice({
54051
- stateRef: Ue,
54052
- connectionRef: Ne,
54053
- hasClient: () => Me.current !== null,
54054
- isMounted: () => Le.current,
54055
- setTools: oe,
54056
- setResources: ce,
54057
- setResourceTemplates: le,
54058
- setPrompts: de,
54059
- addLog: nt
54060
- }), it = (0, M.useCallback)(async (e = !1) => {
54061
- e || nt("info", "Disconnecting..."), Ie.current = !1, Be.current && clearTimeout(Be.current), Be.current = null;
54062
- let t = ze.current, n = Me.current;
54079
+ }, [F]), at = Ice({
54080
+ stateRef: Ge,
54081
+ connectionRef: Fe,
54082
+ hasClient: () => Pe.current !== null,
54083
+ isMounted: () => ze.current,
54084
+ setTools: ce,
54085
+ setResources: le,
54086
+ setResourceTemplates: de,
54087
+ setPrompts: pe,
54088
+ addLog: it
54089
+ }), ot = (0, M.useCallback)(async (e = !1) => {
54090
+ e || it("info", "Disconnecting..."), Re.current = !1, He.current && clearTimeout(He.current), He.current = null;
54091
+ let t = Ve.current, n = Pe.current;
54063
54092
  if (n) try {
54064
- let e = rU, t = n === Me.current ? Ne.current : null;
54093
+ let e = rU, t = n === Pe.current ? Fe.current : null;
54065
54094
  t && t._healthCheckCleanup && (t._healthCheckCleanup(), t._healthCheckCleanup = null), t && await n.closeSession(e);
54066
54095
  } catch (t) {
54067
- e || nt("warn", "Error closing connection:", t);
54068
- }
54069
- let r = ze.current !== t;
54070
- Me.current === n && !r && (Me.current = null, Ne.current = null), Le.current && !e && !r && (K("discovering"), oe([]), ce([]), le([]), de([]), Te(void 0), ke(void 0), je(void 0), pe(void 0), he(void 0), _e(void 0), ye(void 0), xe(void 0), Ce({}));
54071
- }, [nt]), at = (0, M.useCallback)((e, n) => {
54072
- nt("error", e, n ?? "");
54073
- let r = n && "code" in n ? n.code : void 0, i = V.enabled && !G?.proxyAddress, o = e.includes("CORS") || e.includes("blocked by CORS policy") || e.includes("Failed to fetch"), s = r === 400;
54074
- if (i && (o || s || typeof r == "number" && r >= 404 && r < 500) && !(r === 401 || r === 403)) return nt("info", `Direct connection failed with ${o ? "CORS error" : s ? "HTTP 400 (Bad Request)" : "HTTP 4xx error"}. Trying with proxy...`), Me.current = null, a || (Pe.current = null), nt("debug", "Cleared client and auth provider for proxy fallback"), W({ proxyAddress: V.proxyAddress }), Le.current && K("discovering"), setTimeout(() => {
54075
- Le.current && Ke.current?.();
54096
+ e || it("warn", "Error closing connection:", t);
54097
+ }
54098
+ let r = Ve.current !== t;
54099
+ Pe.current === n && !r && (Pe.current = null, Fe.current = null), ze.current && !e && !r && (oe("discovering"), ce([]), le([]), de([]), pe([]), De(void 0), je(void 0), Ne(void 0), he(void 0), _e(void 0), ye(void 0), xe(void 0), Ce(void 0), Te({}));
54100
+ }, [it]), st = (0, M.useCallback)((e, n) => {
54101
+ it("error", e, n ?? "");
54102
+ let r = n && "code" in n ? n.code : void 0, i = U.enabled && !te?.proxyAddress, o = e.includes("CORS") || e.includes("blocked by CORS policy") || e.includes("Failed to fetch"), s = r === 400;
54103
+ if (i && (o || s || typeof r == "number" && r >= 404 && r < 500) && !(r === 401 || r === 403)) return it("info", `Direct connection failed with ${o ? "CORS error" : s ? "HTTP 400 (Bad Request)" : "HTTP 4xx error"}. Trying with proxy...`), Pe.current = null, a || (Ie.current = null), it("debug", "Cleared client and auth provider for proxy fallback"), ee({ proxyAddress: U.proxyAddress }), ze.current && oe("discovering"), setTimeout(() => {
54104
+ ze.current && Je.current?.();
54076
54105
  }, 1e3), !0;
54077
- if (Le.current) {
54078
- nt("info", "Setting state to FAILED:", e), K("failed"), Te(e);
54079
- let t = Pe.current?.getLastAttemptedAuthUrl?.();
54080
- t && (ke(t), nt("info", "Manual authentication URL may be available.", t));
54106
+ if (ze.current) {
54107
+ it("info", "Setting state to FAILED:", e), oe("failed"), De(e);
54108
+ let t = Ie.current?.getLastAttemptedAuthUrl?.();
54109
+ t && (je(t), it("info", "Manual authentication URL may be available.", t));
54081
54110
  }
54082
- return Ie.current = !1, t && eU.getInstance().trackUseMcpConnection({
54111
+ return Re.current = !1, t && eU.getInstance().trackUseMcpConnection({
54083
54112
  url: t,
54084
- transportType: D,
54113
+ transportType: O,
54085
54114
  success: !1,
54086
54115
  errorType: n?.name || "UnknownError",
54087
- hasOAuth: !!Pe.current,
54088
- hasSampling: Xe.current,
54089
- hasElicitation: Ze.current
54116
+ hasOAuth: !!Ie.current,
54117
+ hasSampling: Qe.current,
54118
+ hasElicitation: $e.current
54090
54119
  }).catch(() => {}), !1;
54091
54120
  }, [
54092
- nt,
54121
+ it,
54093
54122
  t,
54094
- D,
54095
- V,
54096
- G,
54123
+ O,
54124
+ U,
54125
+ te,
54097
54126
  a
54098
- ]), ot = (0, M.useCallback)(async () => {
54127
+ ]), ct = (0, M.useCallback)(async () => {
54099
54128
  if (!n || !t) {
54100
- nt("debug", n ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag.");
54129
+ it("debug", n ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag.");
54101
54130
  return;
54102
54131
  }
54103
- if (Ie.current) {
54104
- nt("debug", "Connection attempt already in progress.");
54132
+ if (Re.current) {
54133
+ it("debug", "Connection attempt already in progress.");
54105
54134
  return;
54106
54135
  }
54107
- if (!Le.current) {
54108
- nt("debug", "Connect called after unmount, aborting.");
54136
+ if (!ze.current) {
54137
+ it("debug", "Connect called after unmount, aborting.");
54109
54138
  return;
54110
54139
  }
54111
- if (Ie.current = !0, ze.current += 1, Re.current += 1, Te(void 0), ke(void 0), Ge.current = null, K("discovering"), oe([]), ce([]), le([]), de([]), pe(void 0), he(void 0), _e(void 0), ye(void 0), xe(void 0), Ce({}), nt("info", `Connecting attempt #${Re.current} to ${t}...`), !Pe.current) {
54140
+ if (Re.current = !0, Ve.current += 1, Be.current += 1, De(void 0), je(void 0), qe.current = null, oe("discovering"), ce([]), le([]), de([]), pe([]), he(void 0), _e(void 0), ye(void 0), xe(void 0), Ce(void 0), Te({}), it("info", `Connecting attempt #${Be.current} to ${t}...`), !Ie.current) {
54112
54141
  let { provider: e, oauthProxyUrl: t } = aU({
54113
- effectiveOAuthUrl: ne,
54142
+ effectiveOAuthUrl: ie,
54114
54143
  storageKeyPrefix: i,
54115
- oauthClientConfig: B,
54144
+ oauthClientConfig: H,
54116
54145
  callbackUrl: r,
54117
- preventAutoAuth: m,
54118
- useRedirectFlow: h,
54119
- gatewayUrl: ee,
54146
+ preventAutoAuth: h,
54147
+ useRedirectFlow: g,
54148
+ gatewayUrl: ne,
54120
54149
  oauthProxyUrl: c,
54121
- onPopupWindow: g,
54150
+ onPopupWindow: _,
54122
54151
  proxyOAuthRequests: !0,
54123
- staticClientInfo: j,
54124
- clientMetadataUrl: k,
54125
- scope: A
54152
+ staticClientInfo: P,
54153
+ clientMetadataUrl: j,
54154
+ scope: N
54126
54155
  });
54127
- Pe.current = e, t && nt("debug", `OAuth BFF enabled: ${t}`), nt("debug", `BrowserOAuthClientProvider initialized with URL: ${ne}, proxy: ${t ? "enabled" : "disabled"}, gateway: ${ee ? "enabled" : "disabled"}`);
54156
+ Ie.current = e, t && it("debug", `OAuth BFF enabled: ${t}`), it("debug", `BrowserOAuthClientProvider initialized with URL: ${ie}, proxy: ${t ? "enabled" : "disabled"}, gateway: ${ne ? "enabled" : "disabled"}`);
54128
54157
  }
54129
- Me.current ? nt("debug", "BrowserMCPClient already exists, reusing.") : (Me.current = new Sce(), nt("debug", "BrowserMCPClient initialized in connect."));
54158
+ Pe.current ? it("debug", "BrowserMCPClient already exists, reusing.") : (Pe.current = new Sce(), it("debug", "BrowserMCPClient initialized in connect."));
54130
54159
  let e = async (n) => {
54131
- if (!Le.current) return nt("debug", "Connection attempt aborted - component unmounted"), "failed";
54132
- nt("info", `Attempting connection with transport: ${n}`), nt("debug", `Client ref status at start of tryConnectWithTransport: ${Me.current ? "initialized" : "NULL"}`);
54160
+ if (!ze.current) return it("debug", "Connection attempt aborted - component unmounted"), "failed";
54161
+ it("info", `Attempting connection with transport: ${n}`), it("debug", `Client ref status at start of tryConnectWithTransport: ${Pe.current ? "initialized" : "NULL"}`);
54133
54162
  try {
54134
54163
  let e = rU, r = {
54135
54164
  url: t,
54136
- timeout: _,
54137
- clientInfo: z,
54165
+ timeout: v,
54166
+ clientInfo: V,
54138
54167
  ...(() => {
54139
- let e = Pe.current?.getProxyFetch?.(b) ?? b;
54168
+ let e = Ie.current?.getProxyFetch?.(x) ?? x;
54140
54169
  return e ? { fetch: e } : {};
54141
54170
  })(),
54142
- ...F && { clientOptions: F },
54143
- ...S !== void 0 && { protocolNegotiation: S },
54144
- ...p ? { reconnectionOptions: p } : f === !1 ? { reconnectionOptions: { maxRetries: 0 } } : {}
54171
+ ...L && { clientOptions: L },
54172
+ ...C !== void 0 && { protocolNegotiation: C },
54173
+ ...m ? { reconnectionOptions: m } : p === !1 ? { reconnectionOptions: { maxRetries: 0 } } : {}
54145
54174
  };
54146
- if (ee && (r.gatewayUrl = ee, nt("debug", `Using proxy gateway: ${ee} for target: ${t}`)), re && Object.keys(re).length > 0 && (r.headers = re), !Me.current) {
54147
- if (!Le.current) return nt("debug", "Connection aborted - component unmounted, client cleaned up"), "failed";
54175
+ if (ne && (r.gatewayUrl = ne, it("debug", `Using proxy gateway: ${ne} for target: ${t}`)), K && Object.keys(K).length > 0 && (r.headers = K), !Pe.current) {
54176
+ if (!ze.current) return it("debug", "Connection aborted - component unmounted, client cleaned up"), "failed";
54148
54177
  let e = /* @__PURE__ */ Error("Client not initialized - this is a bug in the connection flow");
54149
- throw nt("error", "Client ref is null in tryConnectWithTransport but component is still mounted"), e;
54178
+ throw it("error", "Client ref is null in tryConnectWithTransport but component is still mounted"), e;
54150
54179
  }
54151
- Me.current.addServer(e, {
54180
+ Pe.current.addServer(e, {
54152
54181
  ...r,
54153
- authProvider: Pe.current,
54154
- onSampling: Xe.current ? $e : void 0,
54155
- onElicitation: Ze.current ? et : void 0,
54182
+ authProvider: Ie.current,
54183
+ onSampling: Qe.current ? tt : void 0,
54184
+ onElicitation: $e.current ? nt : void 0,
54156
54185
  onNotification: (e) => {
54157
- nt("debug", "Notification received:", e.method, e), tt(e), e.method === "notifications/tools/list_changed" ? (nt("info", "Tools list changed, auto-refreshing..."), rt.refreshTools().catch((e) => nt("warn", "Auto-refresh tools failed:", e))) : e.method === "notifications/resources/list_changed" ? (nt("info", "Resources list changed, auto-refreshing..."), rt.refreshResources().catch((e) => nt("warn", "Auto-refresh resources failed:", e))) : e.method === "notifications/prompts/list_changed" && (nt("info", "Prompts list changed, auto-refreshing..."), rt.refreshPrompts().catch((e) => nt("warn", "Auto-refresh prompts failed:", e)));
54186
+ it("debug", "Notification received:", e.method, e), rt(e), e.method === "notifications/tools/list_changed" ? (it("info", "Tools list changed, auto-refreshing..."), at.refreshTools().catch((e) => it("warn", "Auto-refresh tools failed:", e))) : e.method === "notifications/resources/list_changed" ? (it("info", "Resources list changed, auto-refreshing..."), at.refreshResources().catch((e) => it("warn", "Auto-refresh resources failed:", e))) : e.method === "notifications/prompts/list_changed" && (it("info", "Prompts list changed, auto-refreshing..."), at.refreshPrompts().catch((e) => it("warn", "Auto-refresh prompts failed:", e)));
54158
54187
  },
54159
- wrapTransport: v ? (n) => (nt("debug", "Applying transport wrapper for server:", e, "url:", t), v(n, y ?? t)) : void 0
54188
+ wrapTransport: y ? (n) => (it("debug", "Applying transport wrapper for server:", e, "url:", t), y(n, b ?? t)) : void 0
54160
54189
  });
54161
- let i = await Me.current.connect(e);
54162
- if (Ne.current = i, !Le.current) return nt("debug", "Connection aborted after connection creation - component unmounted"), "failed";
54163
- nt("info", "✅ Successfully connected to MCP server"), nt("info", "Server info:", i.info.server), nt("info", "Server capabilities:", i.info.capabilities), H.enabled && H.healthCheckInterval !== !1 && (i._healthCheckCleanup = Fce({
54164
- gatewayUrl: ee,
54190
+ let i = await Pe.current.connect(e);
54191
+ if (Fe.current = i, !ze.current) return it("debug", "Connection aborted after connection creation - component unmounted"), "failed";
54192
+ it("info", "✅ Successfully connected to MCP server"), it("info", "Server info:", i.info.server), it("info", "Server capabilities:", i.info.capabilities), W.enabled && W.healthCheckInterval !== !1 && (i._healthCheckCleanup = Fce({
54193
+ gatewayUrl: ne,
54165
54194
  url: t,
54166
- allHeaders: re,
54195
+ allHeaders: K,
54167
54196
  getAuthHeaders: async () => {
54168
54197
  try {
54169
- let e = await Pe.current?.tokens?.();
54198
+ let e = await Ie.current?.tokens?.();
54170
54199
  if (e?.access_token) {
54171
54200
  let t = e.token_type || "bearer";
54172
54201
  return { Authorization: `${t.charAt(0).toUpperCase() + t.slice(1)} ${e.access_token}` };
@@ -54174,67 +54203,67 @@ function Rce(e) {
54174
54203
  } catch {}
54175
54204
  return {};
54176
54205
  },
54177
- isMountedRef: Le,
54178
- stateRef: Ue,
54179
- autoReconnectRef: We,
54180
- setState: K,
54181
- addLog: nt,
54182
- connect: ot,
54183
- defaultReconnectDelay: H.initialDelay,
54184
- healthCheckIntervalMs: H.healthCheckInterval,
54185
- healthCheckTimeoutMs: H.healthCheckTimeout
54206
+ isMountedRef: ze,
54207
+ stateRef: Ge,
54208
+ autoReconnectRef: Ke,
54209
+ setState: oe,
54210
+ addLog: it,
54211
+ connect: ct,
54212
+ defaultReconnectDelay: W.initialDelay,
54213
+ healthCheckIntervalMs: W.healthCheckInterval,
54214
+ healthCheckTimeoutMs: W.healthCheckTimeout
54186
54215
  })), eU.getInstance().trackUseMcpConnection({
54187
54216
  url: t,
54188
54217
  transportType: n,
54189
54218
  success: !0,
54190
- hasOAuth: !!Pe.current,
54191
- hasSampling: Xe.current,
54192
- hasElicitation: Ze.current
54193
- }).catch(() => {}), oe(i.tools || []);
54219
+ hasOAuth: !!Ie.current,
54220
+ hasSampling: Qe.current,
54221
+ hasElicitation: $e.current
54222
+ }).catch(() => {}), ce(i.tools || []);
54194
54223
  let [a, o, s] = await Promise.all([
54195
54224
  i.listAllResources(),
54196
54225
  i.listPrompts(),
54197
54226
  i.supports("resources") ? i.listResourceTemplates() : Promise.resolve({ resourceTemplates: [] })
54198
54227
  ]);
54199
- if (!Le.current) return nt("debug", "Connection aborted after discovery - component unmounted"), "failed";
54200
- ce(a.resources || []), de(o.prompts || []), le(s.resourceTemplates || []);
54201
- let { server: c, capabilities: l, protocolEra: u, protocolVersion: d, instructions: m, extensions: h } = i.info;
54202
- if (Le.current && (_e(u), ye(d), xe(m), Ce(h)), c) {
54203
- if (nt("debug", "Server info:", c), !Le.current) return nt("debug", "Skipping state update - component unmounted"), "failed";
54204
- pe(c), Fe.current = Ace({
54228
+ if (!ze.current) return it("debug", "Connection aborted after discovery - component unmounted"), "failed";
54229
+ le(a.resources || []), pe(o.prompts || []), de(s.resourceTemplates || []);
54230
+ let { server: c, capabilities: l, protocolEra: u, protocolVersion: d, instructions: f, extensions: h } = i.info;
54231
+ if (ze.current && (ye(u), xe(d), Ce(f), Te(h)), c) {
54232
+ if (it("debug", "Server info:", c), !ze.current) return it("debug", "Skipping state update - component unmounted"), "failed";
54233
+ he(c), Le.current = Ace({
54205
54234
  serverInfo: c,
54206
54235
  url: t,
54207
- isMounted: () => Le.current,
54208
- setServerInfo: pe,
54209
- addLog: nt
54236
+ isMounted: () => ze.current,
54237
+ setServerInfo: he,
54238
+ addLog: it
54210
54239
  });
54211
54240
  }
54212
54241
  if (l) {
54213
- if (nt("debug", "Server capabilities:", l), !Le.current) return nt("debug", "Skipping state update - component unmounted"), "failed";
54214
- he(l);
54242
+ if (it("debug", "Server capabilities:", l), !ze.current) return it("debug", "Skipping state update - component unmounted"), "failed";
54243
+ _e(l);
54215
54244
  }
54216
- if (Pe.current) {
54217
- let e = await Pe.current.tokens?.();
54218
- if (!Le.current) return nt("debug", "Connection aborted after token fetch for auth tokens - component unmounted"), "failed";
54245
+ if (Ie.current) {
54246
+ let e = await Ie.current.tokens?.();
54247
+ if (!ze.current) return it("debug", "Connection aborted after token fetch for auth tokens - component unmounted"), "failed";
54219
54248
  if (e?.access_token) {
54220
54249
  let t = e.expires_in ? Date.now() + e.expires_in * 1e3 : void 0, n = null, r = null, i = null;
54221
54250
  try {
54222
- n = await Pe.current.getTokenEndpoint?.() ?? null;
54251
+ n = await Ie.current.getTokenEndpoint?.() ?? null;
54223
54252
  } catch {
54224
54253
  n = null;
54225
54254
  }
54226
54255
  try {
54227
- r = await Pe.current.getResource?.() ?? null;
54256
+ r = await Ie.current.getResource?.() ?? null;
54228
54257
  } catch {
54229
54258
  r = null;
54230
54259
  }
54231
54260
  try {
54232
- i = await Pe.current.getClientCredentials?.() ?? null;
54261
+ i = await Ie.current.getClientCredentials?.() ?? null;
54233
54262
  } catch {
54234
54263
  i = null;
54235
54264
  }
54236
- if (!Le.current) return nt("debug", "Skipping state update - component unmounted"), "failed";
54237
- je({
54265
+ if (!ze.current) return it("debug", "Skipping state update - component unmounted"), "failed";
54266
+ Ne({
54238
54267
  access_token: e.access_token,
54239
54268
  token_type: e.token_type || "Bearer",
54240
54269
  expires_at: t,
@@ -54247,145 +54276,145 @@ function Rce(e) {
54247
54276
  });
54248
54277
  }
54249
54278
  }
54250
- return Ge.current = n, K("ready"), "success";
54279
+ return qe.current = n, oe("ready"), "success";
54251
54280
  } catch (r) {
54252
- let i = r, a = i?.message || String(r), o = Pe.current?.getLastAttemptedAuthUrl?.();
54253
- if (o && Pe.current && m) return nt("info", "OAuth already discovered (stored auth URL present); awaiting manual authentication."), Le.current && (K("pending_auth"), ke(o)), Ie.current = !1, "auth_redirect";
54281
+ let i = r, a = i?.message || String(r), o = Ie.current?.getLastAttemptedAuthUrl?.();
54282
+ if (o && Ie.current && h) return it("info", "OAuth already discovered (stored auth URL present); awaiting manual authentication."), ze.current && (oe("pending_auth"), je(o)), Re.current = !1, "auth_redirect";
54254
54283
  let s = Nce(r), c = tU(r);
54255
- if (s && P && Object.keys(P).length > 0) return at("Authentication failed (HTTP 401). Server does not support OAuth. Check your Authorization header value is correct."), "failed";
54256
- if (s && (!P || Object.keys(P).length === 0)) return at("Authentication required (HTTP 401). Server does not support OAuth. Add an Authorization header in the Custom Headers section (e.g., Authorization: Bearer YOUR_API_KEY)."), "failed";
54284
+ if (s && I && Object.keys(I).length > 0) return st("Authentication failed (HTTP 401). Server does not support OAuth. Check your Authorization header value is correct."), "failed";
54285
+ if (s && (!I || Object.keys(I).length === 0)) return st("Authentication required (HTTP 401). Server does not support OAuth. Add an Authorization header in the Custom Headers section (e.g., Authorization: Bearer YOUR_API_KEY)."), "failed";
54257
54286
  if (c) {
54258
- if (s) return at("Authentication required (HTTP 401). Server does not support OAuth. Add an Authorization header in the Custom Headers section (e.g., Authorization: Bearer YOUR_API_KEY)."), "failed";
54259
- if (Pe.current) if (nt("info", "Authentication required. OAuth provider available."), m) {
54260
- if (nt("info", "Waiting for user to initiate authentication flow..."), Le.current) {
54261
- K("pending_auth");
54262
- let e = Pe.current?.getLastAttemptedAuthUrl?.();
54263
- e && (ke(e), nt("info", "Retrieved stored auth URL for manual authentication"));
54287
+ if (s) return st("Authentication required (HTTP 401). Server does not support OAuth. Add an Authorization header in the Custom Headers section (e.g., Authorization: Bearer YOUR_API_KEY)."), "failed";
54288
+ if (Ie.current) if (it("info", "Authentication required. OAuth provider available."), h) {
54289
+ if (it("info", "Waiting for user to initiate authentication flow..."), ze.current) {
54290
+ oe("pending_auth");
54291
+ let e = Ie.current?.getLastAttemptedAuthUrl?.();
54292
+ e && (je(e), it("info", "Retrieved stored auth URL for manual authentication"));
54264
54293
  }
54265
- return Ie.current = !1, "auth_redirect";
54294
+ return Re.current = !1, "auth_redirect";
54266
54295
  } else {
54267
- nt("info", "Triggering automatic OAuth authentication flow...");
54296
+ it("info", "Triggering automatic OAuth authentication flow...");
54268
54297
  try {
54269
- if (await _B(Pe.current, {
54298
+ if (await _B(Ie.current, {
54270
54299
  serverUrl: t,
54271
- fetchFn: Pe.current.getProxyFetch?.()
54300
+ fetchFn: Ie.current.getProxyFetch?.()
54272
54301
  }) === "REDIRECT") {
54273
- let e = await Pe.current.getAuthorizationCode?.();
54302
+ let e = await Ie.current.getAuthorizationCode?.();
54274
54303
  if (!e) throw Error("Authorization code not captured by headless provider");
54275
- await _B(Pe.current, {
54304
+ await _B(Ie.current, {
54276
54305
  serverUrl: t,
54277
54306
  authorizationCode: e,
54278
- fetchFn: Pe.current.getProxyFetch?.()
54307
+ fetchFn: Ie.current.getProxyFetch?.()
54279
54308
  });
54280
54309
  }
54281
- return nt("info", "OAuth flow completed, reconnecting..."), await e(n);
54310
+ return it("info", "OAuth flow completed, reconnecting..."), await e(n);
54282
54311
  } catch (e) {
54283
- return at(`Automatic OAuth authentication failed: ${e instanceof Error ? e.message : String(e)}`, e instanceof Error ? e : Error(String(e))), "failed";
54312
+ return st(`Automatic OAuth authentication failed: ${e instanceof Error ? e.message : String(e)}`, e instanceof Error ? e : Error(String(e))), "failed";
54284
54313
  }
54285
54314
  }
54286
- return P && Object.keys(P).length > 0 ? (at("Authentication failed: Server returned 401 Unauthorized. Check your Authorization header value is correct."), "failed") : (at("Authentication required: Server returned 401 Unauthorized. Add an Authorization header in the Custom Headers section (e.g., Authorization: Bearer YOUR_API_KEY)."), "failed");
54315
+ return I && Object.keys(I).length > 0 ? (st("Authentication failed: Server returned 401 Unauthorized. Check your Authorization header value is correct."), "failed") : (st("Authentication required: Server returned 401 Unauthorized. Add an Authorization header in the Custom Headers section (e.g., Authorization: Bearer YOUR_API_KEY)."), "failed");
54287
54316
  }
54288
- return at(a, i instanceof Error ? i : Error(String(i))) ? "auth_redirect" : "failed";
54317
+ return st(a, i instanceof Error ? i : Error(String(i))) ? "auth_redirect" : "failed";
54289
54318
  }
54290
54319
  }, a = "failed";
54291
- nt("debug", "Connecting via streamable HTTP"), a = await e("http"), (a === "success" || a === "failed" || a === "auth_redirect") && (Ie.current = !1), nt("debug", `Connection sequence finished with status: ${a}`);
54320
+ it("debug", "Connecting via streamable HTTP"), a = await e("http"), (a === "success" || a === "failed" || a === "auth_redirect") && (Re.current = !1), it("debug", `Connection sequence finished with status: ${a}`);
54292
54321
  }, [
54293
- nt,
54294
- at,
54295
54322
  it,
54323
+ st,
54324
+ ot,
54296
54325
  t,
54297
54326
  i,
54298
54327
  r,
54299
- B.name,
54300
- B.version,
54301
- B.uri,
54302
- B.logo_uri,
54303
- j,
54304
- k,
54305
- A,
54328
+ H.name,
54329
+ H.version,
54330
+ H.uri,
54331
+ H.logo_uri,
54306
54332
  P,
54307
- D,
54308
- m,
54333
+ j,
54334
+ N,
54335
+ I,
54336
+ O,
54309
54337
  h,
54310
54338
  g,
54311
- n,
54312
54339
  _,
54313
- z,
54314
- F,
54315
- S,
54316
- ee,
54317
- c,
54318
- re,
54340
+ n,
54341
+ v,
54342
+ V,
54343
+ L,
54344
+ C,
54319
54345
  ne,
54320
- $e,
54321
- et,
54322
- tt
54346
+ c,
54347
+ K,
54348
+ ie,
54349
+ tt,
54350
+ nt,
54351
+ rt
54323
54352
  ]);
54324
54353
  (0, M.useEffect)(() => {
54325
- Ke.current = ot, qe.current = at;
54326
- }, [ot, at]);
54327
- let st = (0, M.useCallback)(() => {
54328
- Ue.current === "failed" ? (nt("info", "Retry requested..."), Ke.current?.()) : nt("warn", `Retry called but state is not 'failed' (state: ${Ue.current}). Ignoring.`);
54329
- }, [nt]), ct = (0, M.useCallback)(async () => {
54330
- nt("info", "Manual authentication requested...");
54331
- let e = Ue.current;
54332
- if (e === "failed") nt("info", "Attempting to reconnect and authenticate via retry..."), st();
54354
+ Je.current = ct, Ye.current = st;
54355
+ }, [ct, st]);
54356
+ let lt = (0, M.useCallback)(() => {
54357
+ Ge.current === "failed" ? (it("info", "Retry requested..."), Je.current?.()) : it("warn", `Retry called but state is not 'failed' (state: ${Ge.current}). Ignoring.`);
54358
+ }, [it]), ut = (0, M.useCallback)(async () => {
54359
+ it("info", "Manual authentication requested...");
54360
+ let e = Ge.current;
54361
+ if (e === "failed") it("info", "Attempting to reconnect and authenticate via retry..."), lt();
54333
54362
  else if (e === "pending_auth") {
54334
- nt("info", "Proceeding with authentication from pending state...");
54363
+ it("info", "Proceeding with authentication from pending state...");
54335
54364
  try {
54336
- if (iU(Pe.current, "Auth Provider not available for manual auth"), iU(t, "Server URL is required for authentication"), a) {
54337
- nt("info", "Using provided authProvider for manual authentication");
54365
+ if (iU(Ie.current, "Auth Provider not available for manual auth"), iU(t, "Server URL is required for authentication"), a) {
54366
+ it("info", "Using provided authProvider for manual authentication");
54338
54367
  let e = new URL(t), n = e.origin + e.pathname.replace(/\/+$/, "");
54339
- await _B(Pe.current, {
54368
+ await _B(Ie.current, {
54340
54369
  serverUrl: n,
54341
- fetchFn: Pe.current.getProxyFetch?.()
54342
- }), Ke.current?.();
54370
+ fetchFn: Ie.current.getProxyFetch?.()
54371
+ }), Je.current?.();
54343
54372
  return;
54344
54373
  }
54345
- nt("info", `Cleared ${Pe.current.clearStorage?.() ?? 0} OAuth storage item(s) for fresh authentication`), K("authenticating");
54374
+ it("info", `Cleared ${Ie.current.clearStorage?.() ?? 0} OAuth storage item(s) for fresh authentication`), oe("authenticating");
54346
54375
  let e = null, n = null, { provider: o, oauthProxyUrl: s } = aU({
54347
- effectiveOAuthUrl: ne,
54376
+ effectiveOAuthUrl: ie,
54348
54377
  storageKeyPrefix: i,
54349
- oauthClientConfig: B,
54378
+ oauthClientConfig: H,
54350
54379
  callbackUrl: r,
54351
54380
  preventAutoAuth: !1,
54352
- useRedirectFlow: h,
54353
- gatewayUrl: ee,
54381
+ useRedirectFlow: g,
54382
+ gatewayUrl: ne,
54354
54383
  oauthProxyUrl: c,
54355
54384
  onPopupWindow: (t, r, i) => {
54356
54385
  e = i;
54357
54386
  try {
54358
54387
  n = new URL(t).searchParams.get("state");
54359
54388
  } catch {}
54360
- g?.(t, r, i);
54389
+ _?.(t, r, i);
54361
54390
  },
54362
54391
  proxyOAuthRequests: !0,
54363
- staticClientInfo: j,
54364
- clientMetadataUrl: k,
54365
- scope: A
54392
+ staticClientInfo: P,
54393
+ clientMetadataUrl: j,
54394
+ scope: N
54366
54395
  });
54367
- s && nt("info", "Scoped OAuth proxy fetch enabled for manual auth"), Pe.current = o, nt("info", "Triggering fresh OAuth authorization...");
54396
+ s && it("info", "Scoped OAuth proxy fetch enabled for manual auth"), Ie.current = o, it("info", "Triggering fresh OAuth authorization...");
54368
54397
  let l = new URL(t), u = await _B(o, {
54369
54398
  serverUrl: l.origin + l.pathname.replace(/\/+$/, ""),
54370
54399
  fetchFn: o.getProxyFetch?.()
54371
54400
  });
54372
54401
  if (u === "AUTHORIZED") {
54373
- nt("info", "OAuth flow completed (tokens obtained)"), Ie.current = !1, Ke.current?.();
54402
+ it("info", "OAuth flow completed (tokens obtained)"), Re.current = !1, Je.current?.();
54374
54403
  return;
54375
54404
  }
54376
54405
  if (u !== "REDIRECT") throw Error(`Unexpected OAuth auth() result: ${u}`);
54377
- nt("info", "OAuth authorization redirect initiated");
54406
+ it("info", "OAuth authorization redirect initiated");
54378
54407
  let d = o.getLastAttemptedAuthUrl?.();
54379
- if (d && (ke(d), nt("info", "Updated auth URL for fallback:", d), !n)) try {
54408
+ if (d && (je(d), it("info", "Updated auth URL for fallback:", d), !n)) try {
54380
54409
  n = new URL(d).searchParams.get("state");
54381
54410
  } catch {}
54382
- if (h) return;
54411
+ if (g) return;
54383
54412
  let f = o.getKey?.("tokens");
54384
54413
  if (!f) {
54385
- nt("warn", "Could not derive tokens storage key; relying on callback listener.");
54414
+ it("warn", "Could not derive tokens storage key; relying on callback listener.");
54386
54415
  return;
54387
54416
  }
54388
- He.current = !0;
54417
+ We.current = !0;
54389
54418
  let p;
54390
54419
  try {
54391
54420
  p = await HH({
@@ -54394,189 +54423,190 @@ function Rce(e) {
54394
54423
  tokensKey: f
54395
54424
  });
54396
54425
  } finally {
54397
- He.current = !1;
54426
+ We.current = !1;
54398
54427
  }
54399
- if (!Le.current) return;
54428
+ if (!ze.current) return;
54400
54429
  switch (p.kind) {
54401
54430
  case "success":
54402
- nt("info", "Authentication succeeded; reconnecting to MCP server..."), Ie.current = !1, Ke.current?.();
54431
+ it("info", "Authentication succeeded; reconnecting to MCP server..."), Re.current = !1, Je.current?.();
54403
54432
  break;
54404
54433
  case "cancelled":
54405
- nt("warn", "Authentication popup was closed before completing. Returning to pending_auth."), K("pending_auth");
54434
+ it("warn", "Authentication popup was closed before completing. Returning to pending_auth."), oe("pending_auth");
54406
54435
  break;
54407
54436
  case "timeout":
54408
- nt("warn", "Authentication timed out waiting for the popup. Returning to pending_auth."), K("pending_auth");
54437
+ it("warn", "Authentication timed out waiting for the popup. Returning to pending_auth."), oe("pending_auth");
54409
54438
  break;
54410
54439
  case "error":
54411
- at(`Authentication failed: ${p.error}`);
54440
+ st(`Authentication failed: ${p.error}`);
54412
54441
  break;
54413
54442
  default: break;
54414
54443
  }
54415
54444
  } catch (e) {
54416
- if (!Le.current) return;
54445
+ if (!ze.current) return;
54417
54446
  let t = e instanceof Error ? e : Error(String(e));
54418
- at(`Manual authentication failed: ${t.message}`, t);
54447
+ st(`Manual authentication failed: ${t.message}`, t);
54419
54448
  }
54420
54449
  } else if (e === "authenticating") {
54421
- nt("warn", "Already attempting authentication. Check for blocked popups or wait for timeout.");
54422
- let e = Pe.current?.getLastAttemptedAuthUrl?.();
54423
- e && !Oe && (ke(e), nt("info", "Manual authentication URL retrieved:", e));
54424
- } else nt("info", `Client not in a state requiring manual authentication trigger (state: ${e}). If needed, try disconnecting and reconnecting.`);
54450
+ it("warn", "Already attempting authentication. Check for blocked popups or wait for timeout.");
54451
+ let e = Ie.current?.getLastAttemptedAuthUrl?.();
54452
+ e && !Ae && (je(e), it("info", "Manual authentication URL retrieved:", e));
54453
+ } else it("info", `Client not in a state requiring manual authentication trigger (state: ${e}). If needed, try disconnecting and reconnecting.`);
54425
54454
  }, [
54426
- nt,
54455
+ it,
54456
+ lt,
54427
54457
  st,
54428
- at,
54429
- Oe,
54458
+ Ae,
54430
54459
  t,
54431
- h,
54432
54460
  g,
54461
+ _,
54433
54462
  i,
54434
- B.name,
54435
- B.uri,
54436
- B.logo_uri,
54463
+ H.name,
54464
+ H.uri,
54465
+ H.logo_uri,
54466
+ P,
54437
54467
  j,
54438
- k,
54439
- A,
54468
+ N,
54440
54469
  r,
54441
- z,
54470
+ V,
54442
54471
  a
54443
- ]), lt = (0, M.useCallback)(() => {
54444
- Pe.current?.clearStorage ? (nt("info", `Cleared ${Pe.current.clearStorage()} item(s) from localStorage for ${t}.`), ke(void 0), it()) : nt("warn", "Auth provider not initialized, cannot clear storage.");
54472
+ ]), dt = (0, M.useCallback)(() => {
54473
+ Ie.current?.clearStorage ? (it("info", `Cleared ${Ie.current.clearStorage()} item(s) from localStorage for ${t}.`), je(void 0), ot()) : it("warn", "Auth provider not initialized, cannot clear storage.");
54445
54474
  }, [
54446
54475
  t,
54447
- nt,
54448
- it
54476
+ it,
54477
+ ot
54449
54478
  ]);
54450
54479
  (0, M.useEffect)(() => {
54451
54480
  if (typeof window > "u") return;
54452
54481
  let e = (e, t) => {
54453
- if (He.current) {
54454
- nt("debug", `Ignoring auth callback via ${t}; manual popup flow owns this result.`);
54482
+ if (We.current) {
54483
+ it("debug", `Ignoring auth callback via ${t}; manual popup flow owns this result.`);
54455
54484
  return;
54456
54485
  }
54457
- let n = Pe.current?.serverUrlHash;
54486
+ let n = Ie.current?.serverUrlHash;
54458
54487
  if (e?.serverUrlHash && n && e.serverUrlHash !== n) {
54459
- nt("debug", `Ignoring auth callback via ${t} for a different server.`);
54488
+ it("debug", `Ignoring auth callback via ${t} for a different server.`);
54460
54489
  return;
54461
54490
  }
54462
- if (nt("info", `Received auth callback via ${t}.`, e), Be.current && clearTimeout(Be.current), Be.current = null, e?.success) nt("info", "Authentication successful via popup. Reconnecting client..."), Ie.current && nt("debug", "Connection attempt already in progress, resetting flag to allow reconnection."), Ie.current = !1, setTimeout(() => {
54463
- Le.current && (nt("debug", "Initiating reconnection after successful auth callback."), Ke.current?.());
54491
+ if (it("info", `Received auth callback via ${t}.`, e), He.current && clearTimeout(He.current), He.current = null, e?.success) it("info", "Authentication successful via popup. Reconnecting client..."), Re.current && it("debug", "Connection attempt already in progress, resetting flag to allow reconnection."), Re.current = !1, setTimeout(() => {
54492
+ ze.current && (it("debug", "Initiating reconnection after successful auth callback."), Je.current?.());
54464
54493
  }, 100);
54465
54494
  else {
54466
- if (Ue.current !== "authenticating" && Ue.current !== "pending_auth") {
54467
- nt("debug", `Ignoring stale auth failure callback (state=${Ue.current}).`);
54495
+ if (Ge.current !== "authenticating" && Ge.current !== "pending_auth") {
54496
+ it("debug", `Ignoring stale auth failure callback (state=${Ge.current}).`);
54468
54497
  return;
54469
54498
  }
54470
- qe.current?.(`Authentication failed in callback: ${e?.error || "Unknown reason."}`);
54499
+ Ye.current?.(`Authentication failed in callback: ${e?.error || "Unknown reason."}`);
54471
54500
  }
54472
54501
  }, t = (t) => {
54473
54502
  t.origin === window.location.origin && t.data?.type === BH && e(t.data, "postMessage");
54474
54503
  };
54475
- window.addEventListener("message", t), nt("debug", "Auth callback message listener added.");
54504
+ window.addEventListener("message", t), it("debug", "Auth callback message listener added.");
54476
54505
  let n = null, r = (t) => {
54477
54506
  t.data?.type === BH && e(t.data, "BroadcastChannel");
54478
54507
  };
54479
54508
  if (typeof BroadcastChannel < "u") try {
54480
- n = new BroadcastChannel(zH), n.addEventListener("message", r), nt("debug", "Auth callback BroadcastChannel listener added.");
54509
+ n = new BroadcastChannel(zH), n.addEventListener("message", r), it("debug", "Auth callback BroadcastChannel listener added.");
54481
54510
  } catch (e) {
54482
- nt("warn", "Failed to open auth callback BroadcastChannel; lost-opener popups will not reach this client.", e), n = null;
54511
+ it("warn", "Failed to open auth callback BroadcastChannel; lost-opener popups will not reach this client.", e), n = null;
54483
54512
  }
54484
54513
  return () => {
54485
- if (window.removeEventListener("message", t), nt("debug", "Auth callback message listener removed."), n) {
54514
+ if (window.removeEventListener("message", t), it("debug", "Auth callback message listener removed."), n) {
54486
54515
  try {
54487
54516
  n.removeEventListener("message", r), n.close();
54488
54517
  } catch {}
54489
- nt("debug", "Auth callback BroadcastChannel listener removed.");
54518
+ it("debug", "Auth callback BroadcastChannel listener removed.");
54490
54519
  }
54491
- Be.current && clearTimeout(Be.current);
54520
+ He.current && clearTimeout(He.current);
54492
54521
  };
54493
- }, [nt]), (0, M.useEffect)(() => {
54494
- if (Le.current = !0, !n || !t) return nt("debug", n ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag."), K("discovering"), () => {
54495
- Le.current = !1;
54522
+ }, [it]), (0, M.useEffect)(() => {
54523
+ if (ze.current = !0, !n || !t) return it("debug", n ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag."), oe("discovering"), () => {
54524
+ ze.current = !1;
54496
54525
  };
54497
- if (nt("debug", "useMcp mounted, initiating connection."), Re.current = 0, a) Pe.current = a, nt("debug", "Using externally provided authProvider");
54498
- else if (!Pe.current || Pe.current.serverUrl !== ne) {
54526
+ if (it("debug", "useMcp mounted, initiating connection."), Be.current = 0, a) Ie.current = a, it("debug", "Using externally provided authProvider");
54527
+ else if (!Ie.current || Ie.current.serverUrl !== ie) {
54499
54528
  let { provider: e, oauthProxyUrl: t } = aU({
54500
- effectiveOAuthUrl: ne,
54529
+ effectiveOAuthUrl: ie,
54501
54530
  storageKeyPrefix: i,
54502
- oauthClientConfig: B,
54531
+ oauthClientConfig: H,
54503
54532
  callbackUrl: r,
54504
- preventAutoAuth: m,
54505
- useRedirectFlow: h,
54506
- gatewayUrl: ee,
54533
+ preventAutoAuth: h,
54534
+ useRedirectFlow: g,
54535
+ gatewayUrl: ne,
54507
54536
  oauthProxyUrl: c,
54508
- onPopupWindow: g,
54537
+ onPopupWindow: _,
54509
54538
  proxyOAuthRequests: !0,
54510
- staticClientInfo: j,
54511
- clientMetadataUrl: k,
54512
- scope: A
54539
+ staticClientInfo: P,
54540
+ clientMetadataUrl: j,
54541
+ scope: N
54513
54542
  });
54514
- Pe.current = e, t && nt("debug", `OAuth proxy URL in effect: ${t}`), nt("debug", `BrowserOAuthClientProvider initialized/updated with URL: ${ne}, proxy: ${t ? "enabled" : "disabled"}, gateway: ${ee ? "enabled" : "disabled"}`);
54543
+ Ie.current = e, t && it("debug", `OAuth proxy URL in effect: ${t}`), it("debug", `BrowserOAuthClientProvider initialized/updated with URL: ${ie}, proxy: ${t ? "enabled" : "disabled"}, gateway: ${ne ? "enabled" : "disabled"}`);
54515
54544
  }
54516
- return ot(), () => {
54517
- Le.current = !1, nt("debug", "useMcp unmounting, disconnecting."), it(!0);
54545
+ return ct(), () => {
54546
+ ze.current = !1, it("debug", "useMcp unmounting, disconnecting."), ot(!0);
54518
54547
  };
54519
54548
  }, [
54520
54549
  t,
54521
54550
  n,
54522
54551
  i,
54523
54552
  r,
54524
- B.name,
54525
- B.version,
54526
- B.uri,
54527
- B.logo_uri,
54553
+ H.name,
54554
+ H.version,
54555
+ H.uri,
54556
+ H.logo_uri,
54557
+ P,
54528
54558
  j,
54529
- k,
54530
- A,
54531
- h,
54532
- z,
54533
- ne,
54559
+ N,
54560
+ g,
54561
+ V,
54562
+ ie,
54534
54563
  s,
54564
+ U.proxyAddress,
54535
54565
  a
54536
54566
  ]);
54537
- let ut = (0, M.useRef)(st), dt = (0, M.useRef)(nt);
54567
+ let ft = (0, M.useRef)(lt), pt = (0, M.useRef)(it);
54538
54568
  (0, M.useEffect)(() => {
54539
- ut.current = st, dt.current = nt;
54540
- }, [st, nt]), (0, M.useEffect)(() => {
54569
+ ft.current = lt, pt.current = it;
54570
+ }, [lt, it]), (0, M.useEffect)(() => {
54541
54571
  let e = null;
54542
- if (ie === "failed" && d && Re.current > 0) {
54543
- if (!Ve.current) {
54544
- Ve.current = !0;
54545
- let t = typeof d == "number" ? d : Lce;
54546
- dt.current("info", `Connection failed, auto-retrying in ${t}ms...`), e = setTimeout(() => {
54547
- Ve.current = !1, Le.current && Ue.current === "failed" && ut.current();
54572
+ if (ae === "failed" && f && Be.current > 0) {
54573
+ if (!Ue.current) {
54574
+ Ue.current = !0;
54575
+ let t = typeof f == "number" ? f : Lce;
54576
+ pt.current("info", `Connection failed, auto-retrying in ${t}ms...`), e = setTimeout(() => {
54577
+ Ue.current = !1, ze.current && Ge.current === "failed" && ft.current();
54548
54578
  }, t);
54549
54579
  }
54550
- } else ie !== "failed" && (Ve.current = !1);
54580
+ } else ae !== "failed" && (Ue.current = !1);
54551
54581
  return () => {
54552
- e && (clearTimeout(e), Ve.current = !1);
54582
+ e && (clearTimeout(e), Ue.current = !1);
54553
54583
  };
54554
- }, [ie, d]);
54555
- let ft = (0, M.useCallback)(async () => Ue.current === "ready" ? fe?.icon ? fe.icon : Fe.current ? (nt("debug", "Waiting for icon to finish loading..."), await Fe.current) : (nt("debug", "No icon available and no loading in progress"), null) : (nt("warn", "Cannot ensure icon loaded - not connected"), null), [fe, nt]);
54584
+ }, [ae, f]);
54585
+ let mt = (0, M.useCallback)(async () => Ge.current === "ready" ? me?.icon ? me.icon : Le.current ? (it("debug", "Waiting for icon to finish loading..."), await Le.current) : (it("debug", "No icon available and no loading in progress"), null) : (it("warn", "Cannot ensure icon loaded - not connected"), null), [me, it]);
54556
54586
  return {
54557
- state: ie,
54558
- name: fe?.name || t || "",
54559
- tools: ae,
54560
- resources: se,
54561
- resourceTemplates: q,
54562
- prompts: ue,
54563
- serverInfo: fe,
54564
- capabilities: me,
54565
- protocolEra: ge,
54566
- protocolVersion: ve,
54567
- instructions: be,
54568
- extensions: Se,
54569
- error: we,
54570
- log: Ee,
54571
- authUrl: Oe,
54572
- authTokens: Ae,
54573
- client: Me.current,
54574
- ...rt,
54575
- retry: st,
54576
- disconnect: it,
54577
- authenticate: ct,
54578
- clearStorage: lt,
54579
- ensureIconLoaded: ft
54587
+ state: ae,
54588
+ name: me?.name || t || "",
54589
+ tools: se,
54590
+ resources: q,
54591
+ resourceTemplates: ue,
54592
+ prompts: fe,
54593
+ serverInfo: me,
54594
+ capabilities: ge,
54595
+ protocolEra: ve,
54596
+ protocolVersion: be,
54597
+ instructions: Se,
54598
+ extensions: we,
54599
+ error: Ee,
54600
+ log: Oe,
54601
+ authUrl: Ae,
54602
+ authTokens: Me,
54603
+ client: Pe.current,
54604
+ ...at,
54605
+ retry: lt,
54606
+ disconnect: ot,
54607
+ authenticate: ut,
54608
+ clearStorage: dt,
54609
+ ensureIconLoaded: mt
54580
54610
  };
54581
54611
  }
54582
54612
  var cU = null;
@@ -55927,6 +55957,9 @@ function jW(e) {
55927
55957
  displayName: e.name?.trim() || e.url,
55928
55958
  connectionMode: r,
55929
55959
  protocolNegotiation: e.protocolNegotiation ?? "auto",
55960
+ proxyConfig: void 0,
55961
+ headers: void 0,
55962
+ autoProxyFallback: !1,
55930
55963
  ...e.oauth ? { oauth: e.oauth } : {}
55931
55964
  };
55932
55965
  return r === "proxy" && n ? i.proxyConfig = {
@@ -61725,6 +61758,24 @@ function eZ() {
61725
61758
  variant: "outline",
61726
61759
  disabled: !0,
61727
61760
  children: [/* @__PURE__ */ (0, k.jsx)(ip, { className: "mr-2 h-4 w-4 animate-spin" }), "Authenticating..."]
61761
+ }) : e.authenticate ? /* @__PURE__ */ (0, k.jsx)(Y, {
61762
+ "data-testid": "server-tile-authenticate",
61763
+ size: "sm",
61764
+ className: "bg-yellow-500/20 border-0 dark:bg-yellow-400/10 text-yellow-800 dark:text-yellow-500",
61765
+ variant: "outline",
61766
+ onClick: (t) => {
61767
+ t.stopPropagation();
61768
+ try {
61769
+ sessionStorage.setItem("__mcpUseInspectorReconnect", JSON.stringify({
61770
+ url: e.url,
61771
+ name: e.name || "Auto-connected Server",
61772
+ transportType: e.transportType || "http",
61773
+ connectionMode: "auto"
61774
+ }));
61775
+ } catch {}
61776
+ e.authenticate();
61777
+ },
61778
+ children: "Authenticate"
61728
61779
  }) : e.authUrl ? /* @__PURE__ */ (0, k.jsx)(Y, {
61729
61780
  "data-testid": "server-tile-authenticate",
61730
61781
  size: "sm",