mcp-use 1.6.3-canary.0 → 1.7.0-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.
Files changed (74) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/chunk-JQKKMUCT.js +0 -0
  3. package/dist/chunk-PE7UMCVO.js +377 -0
  4. package/dist/{chunk-BWOTID2D.js → chunk-QSLJXXMG.js} +3 -346
  5. package/dist/chunk-R5DJJ4IV.js +942 -0
  6. package/dist/{chunk-SJEHVCPM.js → chunk-XN2PU4PS.js} +100 -23
  7. package/dist/index.cjs +132 -29
  8. package/dist/index.js +8 -5
  9. package/dist/oauth-CNGBFOZW.js +29 -0
  10. package/dist/src/agents/index.js +1 -1
  11. package/dist/src/auth/browser-provider.d.ts +2 -0
  12. package/dist/src/auth/browser-provider.d.ts.map +1 -1
  13. package/dist/src/auth/callback.d.ts.map +1 -1
  14. package/dist/src/auth/index.cjs +396 -0
  15. package/dist/src/auth/index.js +10 -0
  16. package/dist/src/auth/types.d.ts +3 -1
  17. package/dist/src/auth/types.d.ts.map +1 -1
  18. package/dist/src/browser.cjs +36 -8
  19. package/dist/src/browser.js +6 -4
  20. package/dist/src/connectors/http.d.ts.map +1 -1
  21. package/dist/src/react/index.cjs +132 -29
  22. package/dist/src/react/index.js +3 -2
  23. package/dist/src/react/types.d.ts +12 -1
  24. package/dist/src/react/types.d.ts.map +1 -1
  25. package/dist/src/react/useMcp.d.ts.map +1 -1
  26. package/dist/src/server/context-storage.d.ts +54 -0
  27. package/dist/src/server/context-storage.d.ts.map +1 -0
  28. package/dist/src/server/index.cjs +1409 -410
  29. package/dist/src/server/index.d.ts +4 -1
  30. package/dist/src/server/index.d.ts.map +1 -1
  31. package/dist/src/server/index.js +420 -412
  32. package/dist/src/server/mcp-server.d.ts +50 -81
  33. package/dist/src/server/mcp-server.d.ts.map +1 -1
  34. package/dist/src/server/oauth/index.d.ts +13 -0
  35. package/dist/src/server/oauth/index.d.ts.map +1 -0
  36. package/dist/src/server/oauth/middleware.d.ts +19 -0
  37. package/dist/src/server/oauth/middleware.d.ts.map +1 -0
  38. package/dist/src/server/oauth/providers/auth0.d.ts +22 -0
  39. package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -0
  40. package/dist/src/server/oauth/providers/custom.d.ts +19 -0
  41. package/dist/src/server/oauth/providers/custom.d.ts.map +1 -0
  42. package/dist/src/server/oauth/providers/keycloak.d.ts +22 -0
  43. package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -0
  44. package/dist/src/server/oauth/providers/supabase.d.ts +24 -0
  45. package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -0
  46. package/dist/src/server/oauth/providers/types.d.ts +138 -0
  47. package/dist/src/server/oauth/providers/types.d.ts.map +1 -0
  48. package/dist/src/server/oauth/providers/workos.d.ts +30 -0
  49. package/dist/src/server/oauth/providers/workos.d.ts.map +1 -0
  50. package/dist/src/server/oauth/providers.d.ts +208 -0
  51. package/dist/src/server/oauth/providers.d.ts.map +1 -0
  52. package/dist/src/server/oauth/routes.d.ts +33 -0
  53. package/dist/src/server/oauth/routes.d.ts.map +1 -0
  54. package/dist/src/server/oauth/utils.d.ts +155 -0
  55. package/dist/src/server/oauth/utils.d.ts.map +1 -0
  56. package/dist/src/server/types/common.d.ts +47 -0
  57. package/dist/src/server/types/common.d.ts.map +1 -1
  58. package/dist/src/server/types/context.d.ts +34 -0
  59. package/dist/src/server/types/context.d.ts.map +1 -0
  60. package/dist/src/server/types/index.d.ts +2 -1
  61. package/dist/src/server/types/index.d.ts.map +1 -1
  62. package/dist/src/server/types/tool.d.ts +82 -9
  63. package/dist/src/server/types/tool.d.ts.map +1 -1
  64. package/dist/src/server/utils/index.d.ts +6 -0
  65. package/dist/src/server/utils/index.d.ts.map +1 -0
  66. package/dist/src/server/utils/response-helpers.d.ts +151 -0
  67. package/dist/src/server/utils/response-helpers.d.ts.map +1 -0
  68. package/dist/src/server/utils/runtime.d.ts +25 -0
  69. package/dist/src/server/utils/runtime.d.ts.map +1 -0
  70. package/dist/src/task_managers/streamable_http.d.ts +1 -0
  71. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  72. package/dist/tsup.config.d.ts.map +1 -1
  73. package/package.json +14 -5
  74. /package/dist/{chunk-MCF5P6GJ.js → chunk-GVVPUU5K.js} +0 -0
@@ -1,7 +1,9 @@
1
1
  import {
2
- BrowserMCPClient,
2
+ BrowserMCPClient
3
+ } from "./chunk-QSLJXXMG.js";
4
+ import {
3
5
  BrowserOAuthClientProvider
4
- } from "./chunk-BWOTID2D.js";
6
+ } from "./chunk-PE7UMCVO.js";
5
7
  import {
6
8
  __name
7
9
  } from "./chunk-3GQAWCBQ.js";
@@ -21,7 +23,6 @@ __name(assert, "assert");
21
23
  // src/react/useMcp.ts
22
24
  var DEFAULT_RECONNECT_DELAY = 3e3;
23
25
  var DEFAULT_RETRY_DELAY = 5e3;
24
- var AUTH_TIMEOUT = 5 * 60 * 1e3;
25
26
  function useMcp(options) {
26
27
  const {
27
28
  url,
@@ -39,6 +40,9 @@ function useMcp(options) {
39
40
  autoReconnect = DEFAULT_RECONNECT_DELAY,
40
41
  transportType = "auto",
41
42
  preventAutoAuth = false,
43
+ // Default to false for backward compatibility (auto-trigger OAuth)
44
+ useRedirectFlow = false,
45
+ // Default to false for backward compatibility (use popup)
42
46
  onPopupWindow,
43
47
  timeout = 3e4,
44
48
  // 30 seconds default for connection timeout
@@ -164,6 +168,7 @@ function useMcp(options) {
164
168
  clientUri,
165
169
  callbackUrl,
166
170
  preventAutoAuth,
171
+ useRedirectFlow,
167
172
  onPopupWindow
168
173
  });
169
174
  addLog("debug", "BrowserOAuthClientProvider initialized in connect.");
@@ -254,6 +259,42 @@ function useMcp(options) {
254
259
  } catch (err) {
255
260
  const errorMessage = err?.message || String(err);
256
261
  if (err.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
262
+ if (authProviderRef.current) {
263
+ addLog(
264
+ "info",
265
+ "Authentication required. OAuth provider available."
266
+ );
267
+ try {
268
+ const { auth } = await import("@modelcontextprotocol/sdk/client/auth.js");
269
+ const baseUrl = new URL(url).origin;
270
+ auth(authProviderRef.current, { serverUrl: baseUrl }).catch(
271
+ () => {
272
+ }
273
+ );
274
+ setTimeout(() => {
275
+ if (isMountedRef.current) {
276
+ const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
277
+ if (manualUrl) {
278
+ setAuthUrl(manualUrl);
279
+ addLog(
280
+ "info",
281
+ "Manual authentication URL available:",
282
+ manualUrl
283
+ );
284
+ } else {
285
+ addLog("warn", "Could not generate authentication URL");
286
+ }
287
+ }
288
+ }, 100);
289
+ } catch (authGenError) {
290
+ addLog("warn", "Error generating auth URL:", authGenError);
291
+ }
292
+ if (isMountedRef.current) {
293
+ setState("pending_auth");
294
+ }
295
+ connectingRef.current = false;
296
+ return "auth_redirect";
297
+ }
257
298
  if (customHeaders && Object.keys(customHeaders).length > 0) {
258
299
  failConnection(
259
300
  "Authentication failed: Server returned 401 Unauthorized. Check your Authorization header value is correct."
@@ -305,6 +346,7 @@ function useMcp(options) {
305
346
  customHeaders,
306
347
  transportType,
307
348
  preventAutoAuth,
349
+ useRedirectFlow,
308
350
  onPopupWindow,
309
351
  enabled,
310
352
  timeout,
@@ -357,32 +399,54 @@ function useMcp(options) {
357
399
  retry();
358
400
  } else if (currentState === "pending_auth") {
359
401
  addLog("info", "Proceeding with authentication from pending state...");
360
- setState("authenticating");
361
- if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
362
- authTimeoutRef.current = setTimeout(() => {
363
- if (isMountedRef.current) {
364
- const currentStateValue = stateRef.current;
365
- if (currentStateValue === "authenticating") {
366
- failConnection("Authentication timed out. Please try again.");
367
- }
368
- }
369
- }, AUTH_TIMEOUT);
370
402
  try {
371
403
  assert(
372
404
  authProviderRef.current,
373
405
  "Auth Provider not available for manual auth"
374
406
  );
375
407
  assert(url, "Server URL is required for authentication");
376
- addLog(
377
- "info",
378
- "Redirecting for manual authentication. Waiting for callback..."
379
- );
408
+ addLog("info", "Clearing all OAuth state and initiating fresh flow...");
409
+ const hashPrefix = `${storageKeyPrefix}:${authProviderRef.current.serverUrlHash}`;
410
+ Object.keys(localStorage).forEach((key) => {
411
+ if (key.startsWith(hashPrefix)) {
412
+ addLog("debug", `Removing stale OAuth key: ${key}`);
413
+ localStorage.removeItem(key);
414
+ }
415
+ if (key.startsWith(`${storageKeyPrefix}:state_`)) {
416
+ addLog("debug", `Removing orphaned state: ${key}`);
417
+ localStorage.removeItem(key);
418
+ }
419
+ });
420
+ setState("authenticating");
421
+ const freshAuthProvider = new BrowserOAuthClientProvider(url, {
422
+ storageKeyPrefix,
423
+ clientName,
424
+ clientUri,
425
+ callbackUrl,
426
+ preventAutoAuth: false,
427
+ // ← Allow OAuth to proceed
428
+ useRedirectFlow,
429
+ onPopupWindow
430
+ });
431
+ authProviderRef.current = freshAuthProvider;
432
+ addLog("info", "Triggering fresh OAuth authorization...");
433
+ const { auth } = await import("@modelcontextprotocol/sdk/client/auth.js");
434
+ const baseUrl = new URL(url).origin;
435
+ auth(freshAuthProvider, {
436
+ serverUrl: baseUrl
437
+ }).catch((err) => {
438
+ addLog(
439
+ "info",
440
+ "OAuth flow initiated:",
441
+ err?.message || "Redirecting..."
442
+ );
443
+ });
380
444
  } catch (authError) {
381
445
  if (!isMountedRef.current) return;
382
- if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
383
- failConnection(
384
- `Manual authentication failed: ${authError instanceof Error ? authError.message : String(authError)}`,
385
- authError instanceof Error ? authError : void 0
446
+ setState("pending_auth");
447
+ addLog(
448
+ "error",
449
+ `Manual authentication failed: ${authError instanceof Error ? authError.message : String(authError)}`
386
450
  );
387
451
  }
388
452
  } else if (currentState === "authenticating") {
@@ -401,7 +465,18 @@ function useMcp(options) {
401
465
  `Client not in a state requiring manual authentication trigger (state: ${currentState}). If needed, try disconnecting and reconnecting.`
402
466
  );
403
467
  }
404
- }, [addLog, retry, authUrl, url, failConnection, connect]);
468
+ }, [
469
+ addLog,
470
+ retry,
471
+ authUrl,
472
+ url,
473
+ useRedirectFlow,
474
+ onPopupWindow,
475
+ storageKeyPrefix,
476
+ clientName,
477
+ clientUri,
478
+ callbackUrl
479
+ ]);
405
480
  const clearStorage = useCallback(() => {
406
481
  if (authProviderRef.current) {
407
482
  const count = authProviderRef.current.clearStorage();
@@ -572,6 +647,7 @@ function useMcp(options) {
572
647
  clientUri,
573
648
  callbackUrl,
574
649
  preventAutoAuth,
650
+ useRedirectFlow,
575
651
  onPopupWindow
576
652
  });
577
653
  addLog(
@@ -593,7 +669,8 @@ function useMcp(options) {
593
669
  clientName,
594
670
  clientUri,
595
671
  clientConfig.name,
596
- clientConfig.version
672
+ clientConfig.version,
673
+ useRedirectFlow
597
674
  ]);
598
675
  useEffect(() => {
599
676
  let retryTimeoutId = null;
package/dist/index.cjs CHANGED
@@ -5645,6 +5645,7 @@ var HttpConnector = class extends BaseConnector {
5645
5645
  stop: /* @__PURE__ */ __name(async () => {
5646
5646
  if (this.streamableTransport) {
5647
5647
  try {
5648
+ await this.streamableTransport.terminateSession();
5648
5649
  await this.streamableTransport.close();
5649
5650
  } catch (e) {
5650
5651
  logger.warn(`Error closing Streamable HTTP transport: ${e}`);
@@ -5669,6 +5670,8 @@ var HttpConnector = class extends BaseConnector {
5669
5670
  async connectWithSse(baseUrl) {
5670
5671
  try {
5671
5672
  this.connectionManager = new SseConnectionManager(baseUrl, {
5673
+ authProvider: this.opts.authProvider,
5674
+ // ← Pass OAuth provider to SDK (same as streamable HTTP)
5672
5675
  requestInit: {
5673
5676
  headers: this.headers
5674
5677
  }
@@ -6833,6 +6836,7 @@ var BrowserOAuthClientProvider = class {
6833
6836
  clientUri;
6834
6837
  callbackUrl;
6835
6838
  preventAutoAuth;
6839
+ useRedirectFlow;
6836
6840
  onPopupWindow;
6837
6841
  constructor(serverUrl, options = {}) {
6838
6842
  this.serverUrl = serverUrl;
@@ -6844,6 +6848,7 @@ var BrowserOAuthClientProvider = class {
6844
6848
  options.callbackUrl || (typeof window !== "undefined" ? new URL("/oauth/callback", window.location.origin).toString() : "/oauth/callback")
6845
6849
  );
6846
6850
  this.preventAutoAuth = options.preventAutoAuth;
6851
+ this.useRedirectFlow = options.useRedirectFlow;
6847
6852
  this.onPopupWindow = options.onPopupWindow;
6848
6853
  }
6849
6854
  // --- SDK Interface Methods ---
@@ -6935,7 +6940,11 @@ var BrowserOAuthClientProvider = class {
6935
6940
  clientName: this.clientName,
6936
6941
  clientUri: this.clientUri,
6937
6942
  callbackUrl: this.callbackUrl
6938
- }
6943
+ },
6944
+ // Store flow type so callback knows how to handle the response
6945
+ flowType: this.useRedirectFlow ? "redirect" : "popup",
6946
+ // Store current URL for redirect flow so we can return to it
6947
+ returnUrl: this.useRedirectFlow && typeof window !== "undefined" ? window.location.href : void 0
6939
6948
  };
6940
6949
  localStorage.setItem(stateKey, JSON.stringify(stateData));
6941
6950
  authorizationUrl.searchParams.set("state", state);
@@ -6950,8 +6959,20 @@ var BrowserOAuthClientProvider = class {
6950
6959
  * @param authorizationUrl The fully constructed authorization URL from the SDK.
6951
6960
  */
6952
6961
  async redirectToAuthorization(authorizationUrl) {
6953
- if (this.preventAutoAuth) return;
6954
6962
  const sanitizedAuthUrl = await this.prepareAuthorizationUrl(authorizationUrl);
6963
+ if (this.preventAutoAuth) {
6964
+ console.info(
6965
+ `[${this.storageKeyPrefix}] Auto-auth prevented. Authorization URL stored for manual trigger.`
6966
+ );
6967
+ return;
6968
+ }
6969
+ if (this.useRedirectFlow) {
6970
+ console.info(
6971
+ `[${this.storageKeyPrefix}] Redirecting to authorization URL (full-page redirect).`
6972
+ );
6973
+ window.location.href = sanitizedAuthUrl;
6974
+ return;
6975
+ }
6955
6976
  const popupFeatures = "width=600,height=700,resizable=yes,scrollbars=yes,status=yes";
6956
6977
  try {
6957
6978
  const popup = window.open(
@@ -7101,24 +7122,31 @@ async function onMcpAuthorization() {
7101
7122
  authorizationCode: code
7102
7123
  });
7103
7124
  if (authResult === "AUTHORIZED") {
7104
- console.log(
7105
- `${logPrefix} Authorization successful via SDK auth(). Notifying opener...`
7106
- );
7107
- if (window.opener && !window.opener.closed) {
7125
+ console.log(`${logPrefix} Authorization successful via SDK auth().`);
7126
+ const isRedirectFlow = storedStateData.flowType === "redirect";
7127
+ if (isRedirectFlow && storedStateData.returnUrl) {
7128
+ console.log(
7129
+ `${logPrefix} Redirect flow complete. Returning to: ${storedStateData.returnUrl}`
7130
+ );
7131
+ localStorage.removeItem(stateKey);
7132
+ window.location.href = storedStateData.returnUrl;
7133
+ } else if (window.opener && !window.opener.closed) {
7134
+ console.log(`${logPrefix} Popup flow complete. Notifying opener...`);
7108
7135
  window.opener.postMessage(
7109
7136
  { type: "mcp_auth_callback", success: true },
7110
7137
  window.location.origin
7111
7138
  );
7139
+ localStorage.removeItem(stateKey);
7112
7140
  window.close();
7113
7141
  } else {
7114
7142
  console.warn(
7115
- `${logPrefix} No opener window detected. Redirecting to root.`
7143
+ `${logPrefix} No opener window or return URL detected. Redirecting to root.`
7116
7144
  );
7145
+ localStorage.removeItem(stateKey);
7117
7146
  const pathParts = window.location.pathname.split("/").filter(Boolean);
7118
7147
  const basePath = pathParts.length > 0 && pathParts[pathParts.length - 1] === "callback" ? "/" + pathParts.slice(0, -2).join("/") : "/";
7119
7148
  window.location.href = basePath || "/";
7120
7149
  }
7121
- localStorage.removeItem(stateKey);
7122
7150
  } else {
7123
7151
  console.warn(
7124
7152
  `${logPrefix} SDK auth() returned unexpected status: ${authResult}`
@@ -7240,7 +7268,6 @@ __name(assert, "assert");
7240
7268
  // src/react/useMcp.ts
7241
7269
  var DEFAULT_RECONNECT_DELAY = 3e3;
7242
7270
  var DEFAULT_RETRY_DELAY = 5e3;
7243
- var AUTH_TIMEOUT = 5 * 60 * 1e3;
7244
7271
  function useMcp(options) {
7245
7272
  const {
7246
7273
  url,
@@ -7258,6 +7285,9 @@ function useMcp(options) {
7258
7285
  autoReconnect = DEFAULT_RECONNECT_DELAY,
7259
7286
  transportType = "auto",
7260
7287
  preventAutoAuth = false,
7288
+ // Default to false for backward compatibility (auto-trigger OAuth)
7289
+ useRedirectFlow = false,
7290
+ // Default to false for backward compatibility (use popup)
7261
7291
  onPopupWindow,
7262
7292
  timeout = 3e4,
7263
7293
  // 30 seconds default for connection timeout
@@ -7383,6 +7413,7 @@ function useMcp(options) {
7383
7413
  clientUri,
7384
7414
  callbackUrl,
7385
7415
  preventAutoAuth,
7416
+ useRedirectFlow,
7386
7417
  onPopupWindow
7387
7418
  });
7388
7419
  addLog("debug", "BrowserOAuthClientProvider initialized in connect.");
@@ -7473,6 +7504,42 @@ function useMcp(options) {
7473
7504
  } catch (err) {
7474
7505
  const errorMessage = err?.message || String(err);
7475
7506
  if (err.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
7507
+ if (authProviderRef.current) {
7508
+ addLog(
7509
+ "info",
7510
+ "Authentication required. OAuth provider available."
7511
+ );
7512
+ try {
7513
+ const { auth: auth2 } = await import("@modelcontextprotocol/sdk/client/auth.js");
7514
+ const baseUrl = new URL(url).origin;
7515
+ auth2(authProviderRef.current, { serverUrl: baseUrl }).catch(
7516
+ () => {
7517
+ }
7518
+ );
7519
+ setTimeout(() => {
7520
+ if (isMountedRef.current) {
7521
+ const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
7522
+ if (manualUrl) {
7523
+ setAuthUrl(manualUrl);
7524
+ addLog(
7525
+ "info",
7526
+ "Manual authentication URL available:",
7527
+ manualUrl
7528
+ );
7529
+ } else {
7530
+ addLog("warn", "Could not generate authentication URL");
7531
+ }
7532
+ }
7533
+ }, 100);
7534
+ } catch (authGenError) {
7535
+ addLog("warn", "Error generating auth URL:", authGenError);
7536
+ }
7537
+ if (isMountedRef.current) {
7538
+ setState("pending_auth");
7539
+ }
7540
+ connectingRef.current = false;
7541
+ return "auth_redirect";
7542
+ }
7476
7543
  if (customHeaders && Object.keys(customHeaders).length > 0) {
7477
7544
  failConnection(
7478
7545
  "Authentication failed: Server returned 401 Unauthorized. Check your Authorization header value is correct."
@@ -7524,6 +7591,7 @@ function useMcp(options) {
7524
7591
  customHeaders,
7525
7592
  transportType,
7526
7593
  preventAutoAuth,
7594
+ useRedirectFlow,
7527
7595
  onPopupWindow,
7528
7596
  enabled,
7529
7597
  timeout,
@@ -7576,32 +7644,54 @@ function useMcp(options) {
7576
7644
  retry();
7577
7645
  } else if (currentState === "pending_auth") {
7578
7646
  addLog("info", "Proceeding with authentication from pending state...");
7579
- setState("authenticating");
7580
- if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
7581
- authTimeoutRef.current = setTimeout(() => {
7582
- if (isMountedRef.current) {
7583
- const currentStateValue = stateRef.current;
7584
- if (currentStateValue === "authenticating") {
7585
- failConnection("Authentication timed out. Please try again.");
7586
- }
7587
- }
7588
- }, AUTH_TIMEOUT);
7589
7647
  try {
7590
7648
  assert(
7591
7649
  authProviderRef.current,
7592
7650
  "Auth Provider not available for manual auth"
7593
7651
  );
7594
7652
  assert(url, "Server URL is required for authentication");
7595
- addLog(
7596
- "info",
7597
- "Redirecting for manual authentication. Waiting for callback..."
7598
- );
7653
+ addLog("info", "Clearing all OAuth state and initiating fresh flow...");
7654
+ const hashPrefix = `${storageKeyPrefix}:${authProviderRef.current.serverUrlHash}`;
7655
+ Object.keys(localStorage).forEach((key) => {
7656
+ if (key.startsWith(hashPrefix)) {
7657
+ addLog("debug", `Removing stale OAuth key: ${key}`);
7658
+ localStorage.removeItem(key);
7659
+ }
7660
+ if (key.startsWith(`${storageKeyPrefix}:state_`)) {
7661
+ addLog("debug", `Removing orphaned state: ${key}`);
7662
+ localStorage.removeItem(key);
7663
+ }
7664
+ });
7665
+ setState("authenticating");
7666
+ const freshAuthProvider = new BrowserOAuthClientProvider(url, {
7667
+ storageKeyPrefix,
7668
+ clientName,
7669
+ clientUri,
7670
+ callbackUrl,
7671
+ preventAutoAuth: false,
7672
+ // ← Allow OAuth to proceed
7673
+ useRedirectFlow,
7674
+ onPopupWindow
7675
+ });
7676
+ authProviderRef.current = freshAuthProvider;
7677
+ addLog("info", "Triggering fresh OAuth authorization...");
7678
+ const { auth: auth2 } = await import("@modelcontextprotocol/sdk/client/auth.js");
7679
+ const baseUrl = new URL(url).origin;
7680
+ auth2(freshAuthProvider, {
7681
+ serverUrl: baseUrl
7682
+ }).catch((err) => {
7683
+ addLog(
7684
+ "info",
7685
+ "OAuth flow initiated:",
7686
+ err?.message || "Redirecting..."
7687
+ );
7688
+ });
7599
7689
  } catch (authError) {
7600
7690
  if (!isMountedRef.current) return;
7601
- if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
7602
- failConnection(
7603
- `Manual authentication failed: ${authError instanceof Error ? authError.message : String(authError)}`,
7604
- authError instanceof Error ? authError : void 0
7691
+ setState("pending_auth");
7692
+ addLog(
7693
+ "error",
7694
+ `Manual authentication failed: ${authError instanceof Error ? authError.message : String(authError)}`
7605
7695
  );
7606
7696
  }
7607
7697
  } else if (currentState === "authenticating") {
@@ -7620,7 +7710,18 @@ function useMcp(options) {
7620
7710
  `Client not in a state requiring manual authentication trigger (state: ${currentState}). If needed, try disconnecting and reconnecting.`
7621
7711
  );
7622
7712
  }
7623
- }, [addLog, retry, authUrl, url, failConnection, connect]);
7713
+ }, [
7714
+ addLog,
7715
+ retry,
7716
+ authUrl,
7717
+ url,
7718
+ useRedirectFlow,
7719
+ onPopupWindow,
7720
+ storageKeyPrefix,
7721
+ clientName,
7722
+ clientUri,
7723
+ callbackUrl
7724
+ ]);
7624
7725
  const clearStorage = (0, import_react.useCallback)(() => {
7625
7726
  if (authProviderRef.current) {
7626
7727
  const count = authProviderRef.current.clearStorage();
@@ -7791,6 +7892,7 @@ function useMcp(options) {
7791
7892
  clientUri,
7792
7893
  callbackUrl,
7793
7894
  preventAutoAuth,
7895
+ useRedirectFlow,
7794
7896
  onPopupWindow
7795
7897
  });
7796
7898
  addLog(
@@ -7812,7 +7914,8 @@ function useMcp(options) {
7812
7914
  clientName,
7813
7915
  clientUri,
7814
7916
  clientConfig.name,
7815
- clientConfig.version
7917
+ clientConfig.version,
7918
+ useRedirectFlow
7816
7919
  ]);
7817
7920
  (0, import_react.useEffect)(() => {
7818
7921
  let retryTimeoutId = null;
package/dist/index.js CHANGED
@@ -18,7 +18,8 @@ import {
18
18
  ServerManager,
19
19
  Telemetry,
20
20
  setTelemetrySource
21
- } from "./chunk-MCF5P6GJ.js";
21
+ } from "./chunk-GVVPUU5K.js";
22
+ import "./chunk-JQKKMUCT.js";
22
23
  import {
23
24
  CodeModeConnector,
24
25
  PROMPTS
@@ -34,16 +35,18 @@ import {
34
35
  useWidgetProps,
35
36
  useWidgetState,
36
37
  useWidgetTheme
37
- } from "./chunk-SJEHVCPM.js";
38
+ } from "./chunk-XN2PU4PS.js";
38
39
  import {
39
40
  BaseMCPClient,
40
- BrowserOAuthClientProvider,
41
41
  ConnectionManager,
42
42
  HttpConnector,
43
43
  MCPSession,
44
- WebSocketConnector,
44
+ WebSocketConnector
45
+ } from "./chunk-QSLJXXMG.js";
46
+ import {
47
+ BrowserOAuthClientProvider,
45
48
  onMcpAuthorization
46
- } from "./chunk-BWOTID2D.js";
49
+ } from "./chunk-PE7UMCVO.js";
47
50
  import {
48
51
  BaseConnector
49
52
  } from "./chunk-2JBWOW4S.js";
@@ -0,0 +1,29 @@
1
+ import {
2
+ createBearerAuthMiddleware,
3
+ getAuth,
4
+ hasAnyScope,
5
+ hasScope,
6
+ oauthAuth0Provider,
7
+ oauthCustomProvider,
8
+ oauthKeycloakProvider,
9
+ oauthSupabaseProvider,
10
+ oauthWorkOSProvider,
11
+ requireAnyScope,
12
+ requireScope,
13
+ setupOAuthRoutes
14
+ } from "./chunk-R5DJJ4IV.js";
15
+ import "./chunk-3GQAWCBQ.js";
16
+ export {
17
+ createBearerAuthMiddleware,
18
+ getAuth,
19
+ hasAnyScope,
20
+ hasScope,
21
+ oauthAuth0Provider,
22
+ oauthCustomProvider,
23
+ oauthKeycloakProvider,
24
+ oauthSupabaseProvider,
25
+ oauthWorkOSProvider,
26
+ requireAnyScope,
27
+ requireScope,
28
+ setupOAuthRoutes
29
+ };
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  MCPAgent,
6
6
  RemoteAgent
7
- } from "../../chunk-MCF5P6GJ.js";
7
+ } from "../../chunk-GVVPUU5K.js";
8
8
  import {
9
9
  PROMPTS
10
10
  } from "../../chunk-2AOGMX4T.js";
@@ -11,6 +11,7 @@ export declare class BrowserOAuthClientProvider implements OAuthClientProvider {
11
11
  readonly clientUri: string;
12
12
  readonly callbackUrl: string;
13
13
  private preventAutoAuth?;
14
+ private useRedirectFlow?;
14
15
  readonly onPopupWindow: ((url: string, features: string, window: globalThis.Window | null) => void) | undefined;
15
16
  constructor(serverUrl: string, options?: {
16
17
  storageKeyPrefix?: string;
@@ -18,6 +19,7 @@ export declare class BrowserOAuthClientProvider implements OAuthClientProvider {
18
19
  clientUri?: string;
19
20
  callbackUrl?: string;
20
21
  preventAutoAuth?: boolean;
22
+ useRedirectFlow?: boolean;
21
23
  onPopupWindow?: (url: string, features: string, window: globalThis.Window | null) => void;
22
24
  });
23
25
  get redirectUrl(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"browser-provider.d.ts","sourceRoot":"","sources":["../../../src/auth/browser-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EACX,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAKpF;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IACpE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EA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C;QAC1B,aAAa,CAAC,EAAE,CACd,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,IAAI,KAC7B,IAAI,CAAC;KACN;IAsBR,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,cAAc,IAAI,mBAAmB,CAUxC;IAEK,iBAAiB,IAAI,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAmBhE,qBAAqB,CACzB,iBAAiB,EAAE,sBAAsB,GACxC,OAAO,CAAC,IAAI,CAAC;IAMV,MAAM,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAc1C,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9C,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrD,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAarC;;;;;OAKG;IACG,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAwCrE;;;;OAIG;IACG,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IA8DnE;;OAEG;IACH,uBAAuB,IAAI,MAAM,GAAG,IAAI;IAKxC,YAAY,IAAI,MAAM;IA0CtB,OAAO,CAAC,UAAU;IAUlB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAGlC"}
@@ -1 +1 @@
1
- {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../../src/auth/callback.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAsB,kBAAkB,kBAoKvC"}
1
+ {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../../src/auth/callback.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAsB,kBAAkB,kBA+KvC"}