mcp-use 1.6.3-canary.0 → 1.7.0-canary.2

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 (105) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/chunk-3R5PDYIN.js +403 -0
  3. package/dist/{chunk-BWOTID2D.js → chunk-AGKMD2ZM.js} +7 -350
  4. package/dist/{chunk-SJEHVCPM.js → chunk-BG2APH43.js} +120 -26
  5. package/dist/{chunk-YURRUCIM.js → chunk-CPG2WZUL.js} +9 -11
  6. package/dist/chunk-F4UHAA5L.js +854 -0
  7. package/dist/chunk-JQKKMUCT.js +0 -0
  8. package/dist/chunk-MTHLLDCX.js +97 -0
  9. package/dist/{chunk-MCF5P6GJ.js → chunk-S6K5QZBJ.js} +739 -29
  10. package/dist/{display-YIYC6WJE.js → display-A5IEINAP.js} +79 -17
  11. package/dist/index.cjs +1055 -136
  12. package/dist/index.js +14 -10
  13. package/dist/{langfuse-C4HKZ3NL.js → langfuse-N5Y5BSXK.js} +1 -1
  14. package/dist/oauth-U4NNKN4B.js +30 -0
  15. package/dist/src/agents/display.d.ts.map +1 -1
  16. package/dist/src/agents/index.cjs +854 -78
  17. package/dist/src/agents/index.js +3 -2
  18. package/dist/src/auth/browser-provider.d.ts +2 -0
  19. package/dist/src/auth/browser-provider.d.ts.map +1 -1
  20. package/dist/src/auth/callback.d.ts.map +1 -1
  21. package/dist/src/auth/index.cjs +421 -0
  22. package/dist/src/auth/index.js +10 -0
  23. package/dist/src/auth/types.d.ts +3 -1
  24. package/dist/src/auth/types.d.ts.map +1 -1
  25. package/dist/src/browser.cjs +924 -98
  26. package/dist/src/browser.js +8 -5
  27. package/dist/src/connectors/base.d.ts +52 -121
  28. package/dist/src/connectors/base.d.ts.map +1 -1
  29. package/dist/src/connectors/http.d.ts.map +1 -1
  30. package/dist/src/managers/server_manager.d.ts.map +1 -1
  31. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +2 -2
  32. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
  33. package/dist/src/managers/tools/add_server_from_config.d.ts +1 -7
  34. package/dist/src/managers/tools/add_server_from_config.d.ts.map +1 -1
  35. package/dist/src/managers/tools/connect_mcp_server.d.ts +2 -10
  36. package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
  37. package/dist/src/managers/tools/list_mcp_servers.d.ts +2 -2
  38. package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -1
  39. package/dist/src/managers/tools/release_mcp_server_connection.d.ts +2 -2
  40. package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
  41. package/dist/src/observability/langfuse.d.ts +4 -0
  42. package/dist/src/observability/langfuse.d.ts.map +1 -1
  43. package/dist/src/react/McpUseProvider.d.ts.map +1 -1
  44. package/dist/src/react/index.cjs +189 -41
  45. package/dist/src/react/index.js +4 -2
  46. package/dist/src/react/types.d.ts +12 -1
  47. package/dist/src/react/types.d.ts.map +1 -1
  48. package/dist/src/react/useMcp.d.ts.map +1 -1
  49. package/dist/src/server/connect-adapter.d.ts.map +1 -1
  50. package/dist/src/server/context-storage.d.ts +54 -0
  51. package/dist/src/server/context-storage.d.ts.map +1 -0
  52. package/dist/src/server/index.cjs +1413 -418
  53. package/dist/src/server/index.d.ts +4 -1
  54. package/dist/src/server/index.d.ts.map +1 -1
  55. package/dist/src/server/index.js +426 -420
  56. package/dist/src/server/mcp-server.d.ts +50 -81
  57. package/dist/src/server/mcp-server.d.ts.map +1 -1
  58. package/dist/src/server/oauth/index.d.ts +13 -0
  59. package/dist/src/server/oauth/index.d.ts.map +1 -0
  60. package/dist/src/server/oauth/middleware.d.ts +19 -0
  61. package/dist/src/server/oauth/middleware.d.ts.map +1 -0
  62. package/dist/src/server/oauth/providers/auth0.d.ts +22 -0
  63. package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -0
  64. package/dist/src/server/oauth/providers/custom.d.ts +19 -0
  65. package/dist/src/server/oauth/providers/custom.d.ts.map +1 -0
  66. package/dist/src/server/oauth/providers/keycloak.d.ts +22 -0
  67. package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -0
  68. package/dist/src/server/oauth/providers/supabase.d.ts +24 -0
  69. package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -0
  70. package/dist/src/server/oauth/providers/types.d.ts +138 -0
  71. package/dist/src/server/oauth/providers/types.d.ts.map +1 -0
  72. package/dist/src/server/oauth/providers/workos.d.ts +30 -0
  73. package/dist/src/server/oauth/providers/workos.d.ts.map +1 -0
  74. package/dist/src/server/oauth/providers.d.ts +208 -0
  75. package/dist/src/server/oauth/providers.d.ts.map +1 -0
  76. package/dist/src/server/oauth/routes.d.ts +33 -0
  77. package/dist/src/server/oauth/routes.d.ts.map +1 -0
  78. package/dist/src/server/oauth/utils.d.ts +155 -0
  79. package/dist/src/server/oauth/utils.d.ts.map +1 -0
  80. package/dist/src/server/types/common.d.ts +47 -0
  81. package/dist/src/server/types/common.d.ts.map +1 -1
  82. package/dist/src/server/types/context.d.ts +34 -0
  83. package/dist/src/server/types/context.d.ts.map +1 -0
  84. package/dist/src/server/types/index.d.ts +2 -1
  85. package/dist/src/server/types/index.d.ts.map +1 -1
  86. package/dist/src/server/types/tool.d.ts +82 -9
  87. package/dist/src/server/types/tool.d.ts.map +1 -1
  88. package/dist/src/server/utils/index.d.ts +6 -0
  89. package/dist/src/server/utils/index.d.ts.map +1 -0
  90. package/dist/src/server/utils/response-helpers.d.ts +151 -0
  91. package/dist/src/server/utils/response-helpers.d.ts.map +1 -0
  92. package/dist/src/server/utils/runtime.d.ts +25 -0
  93. package/dist/src/server/utils/runtime.d.ts.map +1 -0
  94. package/dist/src/task_managers/streamable_http.d.ts +1 -0
  95. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  96. package/dist/src/utils/json-schema-to-zod/JSONSchemaToZod.d.ts +270 -0
  97. package/dist/src/utils/json-schema-to-zod/JSONSchemaToZod.d.ts.map +1 -0
  98. package/dist/src/utils/json-schema-to-zod/Type.d.ts +24 -0
  99. package/dist/src/utils/json-schema-to-zod/Type.d.ts.map +1 -0
  100. package/dist/src/utils/json-schema-to-zod/index.d.ts +3 -0
  101. package/dist/src/utils/json-schema-to-zod/index.d.ts.map +1 -0
  102. package/dist/src/utils/url-sanitize.d.ts +17 -0
  103. package/dist/src/utils/url-sanitize.d.ts.map +1 -0
  104. package/dist/tsup.config.d.ts.map +1 -1
  105. package/package.json +30 -38
@@ -1 +1 @@
1
- {"version":3,"file":"McpUseProvider.d.ts","sourceRoot":"","sources":["../../../src/react/McpUseProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAwB1E,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,YAAY,CAAC;IAC9C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,QAAQ,EAAE,cAAsB,EAChC,YAAoB,EACpB,QAAgB,GACjB,EAAE,mBAAmB,qBAkIrB"}
1
+ {"version":3,"file":"McpUseProvider.d.ts","sourceRoot":"","sources":["../../../src/react/McpUseProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqD,MAAM,OAAO,CAAC;AA4C1E,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,YAAY,CAAC;IAC9C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,QAAQ,EAAE,cAAsB,EAChC,YAAoB,EACpB,QAAgB,GACjB,EAAE,mBAAmB,qBAwIrB"}
@@ -47,7 +47,32 @@ module.exports = __toCommonJS(react_exports);
47
47
 
48
48
  // src/react/useMcp.ts
49
49
  var import_react = require("react");
50
- var import_strict_url_sanitise2 = require("strict-url-sanitise");
50
+
51
+ // src/utils/url-sanitize.ts
52
+ function sanitizeUrl(raw) {
53
+ const abort = /* @__PURE__ */ __name(() => {
54
+ throw new Error(`Invalid url to pass to open(): ${raw}`);
55
+ }, "abort");
56
+ let url;
57
+ try {
58
+ url = new URL(raw);
59
+ } catch (_) {
60
+ abort();
61
+ }
62
+ if (url.protocol !== "https:" && url.protocol !== "http:") abort();
63
+ if (url.hostname !== encodeURIComponent(url.hostname)) abort();
64
+ if (url.username) url.username = encodeURIComponent(url.username);
65
+ if (url.password) url.password = encodeURIComponent(url.password);
66
+ url.pathname = url.pathname.slice(0, 1) + encodeURIComponent(url.pathname.slice(1)).replace(/%2f/gi, "/");
67
+ url.search = url.search.slice(0, 1) + Array.from(url.searchParams.entries()).map(sanitizeParam).join("&");
68
+ url.hash = url.hash.slice(0, 1) + encodeURIComponent(url.hash.slice(1));
69
+ return url.href;
70
+ }
71
+ __name(sanitizeUrl, "sanitizeUrl");
72
+ function sanitizeParam([k, v]) {
73
+ return `${encodeURIComponent(k)}${v.length > 0 ? `=${encodeURIComponent(v)}` : ""}`;
74
+ }
75
+ __name(sanitizeParam, "sanitizeParam");
51
76
 
52
77
  // src/connectors/http.ts
53
78
  var import_client = require("@modelcontextprotocol/sdk/client/index.js");
@@ -1066,6 +1091,7 @@ var HttpConnector = class extends BaseConnector {
1066
1091
  stop: /* @__PURE__ */ __name(async () => {
1067
1092
  if (this.streamableTransport) {
1068
1093
  try {
1094
+ await this.streamableTransport.terminateSession();
1069
1095
  await this.streamableTransport.close();
1070
1096
  } catch (e) {
1071
1097
  logger.warn(`Error closing Streamable HTTP transport: ${e}`);
@@ -1090,6 +1116,8 @@ var HttpConnector = class extends BaseConnector {
1090
1116
  async connectWithSse(baseUrl) {
1091
1117
  try {
1092
1118
  this.connectionManager = new SseConnectionManager(baseUrl, {
1119
+ authProvider: this.opts.authProvider,
1120
+ // ← Pass OAuth provider to SDK (same as streamable HTTP)
1093
1121
  requestInit: {
1094
1122
  headers: this.headers
1095
1123
  }
@@ -1144,8 +1172,12 @@ var HttpConnector = class extends BaseConnector {
1144
1172
  }
1145
1173
  };
1146
1174
 
1147
- // src/connectors/websocket.ts
1148
- var import_uuid = require("uuid");
1175
+ // src/server/utils/runtime.ts
1176
+ var isDeno = typeof globalThis.Deno !== "undefined";
1177
+ function generateUUID() {
1178
+ return globalThis.crypto.randomUUID();
1179
+ }
1180
+ __name(generateUUID, "generateUUID");
1149
1181
 
1150
1182
  // src/task_managers/websocket.ts
1151
1183
  var import_ws = __toESM(require("ws"), 1);
@@ -1265,7 +1297,7 @@ var WebSocketConnector = class extends BaseConnector {
1265
1297
  }
1266
1298
  sendRequest(method, params = null) {
1267
1299
  if (!this.ws) throw new Error("WebSocket is not connected");
1268
- const id = (0, import_uuid.v4)();
1300
+ const id = generateUUID();
1269
1301
  const payload = JSON.stringify({ id, method, params: params ?? {} });
1270
1302
  return new Promise((resolve, reject) => {
1271
1303
  this.pending.set(id, { resolve, reject });
@@ -1672,7 +1704,6 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
1672
1704
  };
1673
1705
 
1674
1706
  // src/auth/browser-provider.ts
1675
- var import_strict_url_sanitise = require("strict-url-sanitise");
1676
1707
  var BrowserOAuthClientProvider = class {
1677
1708
  static {
1678
1709
  __name(this, "BrowserOAuthClientProvider");
@@ -1684,6 +1715,7 @@ var BrowserOAuthClientProvider = class {
1684
1715
  clientUri;
1685
1716
  callbackUrl;
1686
1717
  preventAutoAuth;
1718
+ useRedirectFlow;
1687
1719
  onPopupWindow;
1688
1720
  constructor(serverUrl, options = {}) {
1689
1721
  this.serverUrl = serverUrl;
@@ -1691,15 +1723,16 @@ var BrowserOAuthClientProvider = class {
1691
1723
  this.serverUrlHash = this.hashString(serverUrl);
1692
1724
  this.clientName = options.clientName || "mcp-use";
1693
1725
  this.clientUri = options.clientUri || (typeof window !== "undefined" ? window.location.origin : "");
1694
- this.callbackUrl = (0, import_strict_url_sanitise.sanitizeUrl)(
1726
+ this.callbackUrl = sanitizeUrl(
1695
1727
  options.callbackUrl || (typeof window !== "undefined" ? new URL("/oauth/callback", window.location.origin).toString() : "/oauth/callback")
1696
1728
  );
1697
1729
  this.preventAutoAuth = options.preventAutoAuth;
1730
+ this.useRedirectFlow = options.useRedirectFlow;
1698
1731
  this.onPopupWindow = options.onPopupWindow;
1699
1732
  }
1700
1733
  // --- SDK Interface Methods ---
1701
1734
  get redirectUrl() {
1702
- return (0, import_strict_url_sanitise.sanitizeUrl)(this.callbackUrl);
1735
+ return sanitizeUrl(this.callbackUrl);
1703
1736
  }
1704
1737
  get clientMetadata() {
1705
1738
  return {
@@ -1786,12 +1819,16 @@ var BrowserOAuthClientProvider = class {
1786
1819
  clientName: this.clientName,
1787
1820
  clientUri: this.clientUri,
1788
1821
  callbackUrl: this.callbackUrl
1789
- }
1822
+ },
1823
+ // Store flow type so callback knows how to handle the response
1824
+ flowType: this.useRedirectFlow ? "redirect" : "popup",
1825
+ // Store current URL for redirect flow so we can return to it
1826
+ returnUrl: this.useRedirectFlow && typeof window !== "undefined" ? window.location.href : void 0
1790
1827
  };
1791
1828
  localStorage.setItem(stateKey, JSON.stringify(stateData));
1792
1829
  authorizationUrl.searchParams.set("state", state);
1793
1830
  const authUrlString = authorizationUrl.toString();
1794
- const sanitizedAuthUrl = (0, import_strict_url_sanitise.sanitizeUrl)(authUrlString);
1831
+ const sanitizedAuthUrl = sanitizeUrl(authUrlString);
1795
1832
  localStorage.setItem(this.getKey("last_auth_url"), sanitizedAuthUrl);
1796
1833
  return sanitizedAuthUrl;
1797
1834
  }
@@ -1801,8 +1838,20 @@ var BrowserOAuthClientProvider = class {
1801
1838
  * @param authorizationUrl The fully constructed authorization URL from the SDK.
1802
1839
  */
1803
1840
  async redirectToAuthorization(authorizationUrl) {
1804
- if (this.preventAutoAuth) return;
1805
1841
  const sanitizedAuthUrl = await this.prepareAuthorizationUrl(authorizationUrl);
1842
+ if (this.preventAutoAuth) {
1843
+ console.info(
1844
+ `[${this.storageKeyPrefix}] Auto-auth prevented. Authorization URL stored for manual trigger.`
1845
+ );
1846
+ return;
1847
+ }
1848
+ if (this.useRedirectFlow) {
1849
+ console.info(
1850
+ `[${this.storageKeyPrefix}] Redirecting to authorization URL (full-page redirect).`
1851
+ );
1852
+ window.location.href = sanitizedAuthUrl;
1853
+ return;
1854
+ }
1806
1855
  const popupFeatures = "width=600,height=700,resizable=yes,scrollbars=yes,status=yes";
1807
1856
  try {
1808
1857
  const popup = window.open(
@@ -1836,7 +1885,7 @@ var BrowserOAuthClientProvider = class {
1836
1885
  */
1837
1886
  getLastAttemptedAuthUrl() {
1838
1887
  const storedUrl = localStorage.getItem(this.getKey("last_auth_url"));
1839
- return storedUrl ? (0, import_strict_url_sanitise.sanitizeUrl)(storedUrl) : null;
1888
+ return storedUrl ? sanitizeUrl(storedUrl) : null;
1840
1889
  }
1841
1890
  clearStorage() {
1842
1891
  const prefixPattern = `${this.storageKeyPrefix}_${this.serverUrlHash}_`;
@@ -1897,14 +1946,13 @@ __name(assert, "assert");
1897
1946
  // src/react/useMcp.ts
1898
1947
  var DEFAULT_RECONNECT_DELAY = 3e3;
1899
1948
  var DEFAULT_RETRY_DELAY = 5e3;
1900
- var AUTH_TIMEOUT = 5 * 60 * 1e3;
1901
1949
  function useMcp(options) {
1902
1950
  const {
1903
1951
  url,
1904
1952
  enabled = true,
1905
1953
  clientName,
1906
1954
  clientUri,
1907
- callbackUrl = typeof window !== "undefined" ? (0, import_strict_url_sanitise2.sanitizeUrl)(
1955
+ callbackUrl = typeof window !== "undefined" ? sanitizeUrl(
1908
1956
  new URL("/oauth/callback", window.location.origin).toString()
1909
1957
  ) : "/oauth/callback",
1910
1958
  storageKeyPrefix = "mcp:auth",
@@ -1915,6 +1963,9 @@ function useMcp(options) {
1915
1963
  autoReconnect = DEFAULT_RECONNECT_DELAY,
1916
1964
  transportType = "auto",
1917
1965
  preventAutoAuth = false,
1966
+ // Default to false for backward compatibility (auto-trigger OAuth)
1967
+ useRedirectFlow = false,
1968
+ // Default to false for backward compatibility (use popup)
1918
1969
  onPopupWindow,
1919
1970
  timeout = 3e4,
1920
1971
  // 30 seconds default for connection timeout
@@ -2040,6 +2091,7 @@ function useMcp(options) {
2040
2091
  clientUri,
2041
2092
  callbackUrl,
2042
2093
  preventAutoAuth,
2094
+ useRedirectFlow,
2043
2095
  onPopupWindow
2044
2096
  });
2045
2097
  addLog("debug", "BrowserOAuthClientProvider initialized in connect.");
@@ -2130,6 +2182,42 @@ function useMcp(options) {
2130
2182
  } catch (err) {
2131
2183
  const errorMessage = err?.message || String(err);
2132
2184
  if (err.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
2185
+ if (authProviderRef.current) {
2186
+ addLog(
2187
+ "info",
2188
+ "Authentication required. OAuth provider available."
2189
+ );
2190
+ try {
2191
+ const { auth: auth2 } = await import("@modelcontextprotocol/sdk/client/auth.js");
2192
+ const baseUrl = new URL(url).origin;
2193
+ auth2(authProviderRef.current, { serverUrl: baseUrl }).catch(
2194
+ () => {
2195
+ }
2196
+ );
2197
+ setTimeout(() => {
2198
+ if (isMountedRef.current) {
2199
+ const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
2200
+ if (manualUrl) {
2201
+ setAuthUrl(manualUrl);
2202
+ addLog(
2203
+ "info",
2204
+ "Manual authentication URL available:",
2205
+ manualUrl
2206
+ );
2207
+ } else {
2208
+ addLog("warn", "Could not generate authentication URL");
2209
+ }
2210
+ }
2211
+ }, 100);
2212
+ } catch (authGenError) {
2213
+ addLog("warn", "Error generating auth URL:", authGenError);
2214
+ }
2215
+ if (isMountedRef.current) {
2216
+ setState("pending_auth");
2217
+ }
2218
+ connectingRef.current = false;
2219
+ return "auth_redirect";
2220
+ }
2133
2221
  if (customHeaders && Object.keys(customHeaders).length > 0) {
2134
2222
  failConnection(
2135
2223
  "Authentication failed: Server returned 401 Unauthorized. Check your Authorization header value is correct."
@@ -2181,6 +2269,7 @@ function useMcp(options) {
2181
2269
  customHeaders,
2182
2270
  transportType,
2183
2271
  preventAutoAuth,
2272
+ useRedirectFlow,
2184
2273
  onPopupWindow,
2185
2274
  enabled,
2186
2275
  timeout,
@@ -2233,32 +2322,54 @@ function useMcp(options) {
2233
2322
  retry();
2234
2323
  } else if (currentState === "pending_auth") {
2235
2324
  addLog("info", "Proceeding with authentication from pending state...");
2236
- setState("authenticating");
2237
- if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
2238
- authTimeoutRef.current = setTimeout(() => {
2239
- if (isMountedRef.current) {
2240
- const currentStateValue = stateRef.current;
2241
- if (currentStateValue === "authenticating") {
2242
- failConnection("Authentication timed out. Please try again.");
2243
- }
2244
- }
2245
- }, AUTH_TIMEOUT);
2246
2325
  try {
2247
2326
  assert(
2248
2327
  authProviderRef.current,
2249
2328
  "Auth Provider not available for manual auth"
2250
2329
  );
2251
2330
  assert(url, "Server URL is required for authentication");
2252
- addLog(
2253
- "info",
2254
- "Redirecting for manual authentication. Waiting for callback..."
2255
- );
2331
+ addLog("info", "Clearing all OAuth state and initiating fresh flow...");
2332
+ const hashPrefix = `${storageKeyPrefix}:${authProviderRef.current.serverUrlHash}`;
2333
+ Object.keys(localStorage).forEach((key) => {
2334
+ if (key.startsWith(hashPrefix)) {
2335
+ addLog("debug", `Removing stale OAuth key: ${key}`);
2336
+ localStorage.removeItem(key);
2337
+ }
2338
+ if (key.startsWith(`${storageKeyPrefix}:state_`)) {
2339
+ addLog("debug", `Removing orphaned state: ${key}`);
2340
+ localStorage.removeItem(key);
2341
+ }
2342
+ });
2343
+ setState("authenticating");
2344
+ const freshAuthProvider = new BrowserOAuthClientProvider(url, {
2345
+ storageKeyPrefix,
2346
+ clientName,
2347
+ clientUri,
2348
+ callbackUrl,
2349
+ preventAutoAuth: false,
2350
+ // ← Allow OAuth to proceed
2351
+ useRedirectFlow,
2352
+ onPopupWindow
2353
+ });
2354
+ authProviderRef.current = freshAuthProvider;
2355
+ addLog("info", "Triggering fresh OAuth authorization...");
2356
+ const { auth: auth2 } = await import("@modelcontextprotocol/sdk/client/auth.js");
2357
+ const baseUrl = new URL(url).origin;
2358
+ auth2(freshAuthProvider, {
2359
+ serverUrl: baseUrl
2360
+ }).catch((err) => {
2361
+ addLog(
2362
+ "info",
2363
+ "OAuth flow initiated:",
2364
+ err?.message || "Redirecting..."
2365
+ );
2366
+ });
2256
2367
  } catch (authError) {
2257
2368
  if (!isMountedRef.current) return;
2258
- if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
2259
- failConnection(
2260
- `Manual authentication failed: ${authError instanceof Error ? authError.message : String(authError)}`,
2261
- authError instanceof Error ? authError : void 0
2369
+ setState("pending_auth");
2370
+ addLog(
2371
+ "error",
2372
+ `Manual authentication failed: ${authError instanceof Error ? authError.message : String(authError)}`
2262
2373
  );
2263
2374
  }
2264
2375
  } else if (currentState === "authenticating") {
@@ -2277,7 +2388,18 @@ function useMcp(options) {
2277
2388
  `Client not in a state requiring manual authentication trigger (state: ${currentState}). If needed, try disconnecting and reconnecting.`
2278
2389
  );
2279
2390
  }
2280
- }, [addLog, retry, authUrl, url, failConnection, connect]);
2391
+ }, [
2392
+ addLog,
2393
+ retry,
2394
+ authUrl,
2395
+ url,
2396
+ useRedirectFlow,
2397
+ onPopupWindow,
2398
+ storageKeyPrefix,
2399
+ clientName,
2400
+ clientUri,
2401
+ callbackUrl
2402
+ ]);
2281
2403
  const clearStorage = (0, import_react.useCallback)(() => {
2282
2404
  if (authProviderRef.current) {
2283
2405
  const count = authProviderRef.current.clearStorage();
@@ -2448,6 +2570,7 @@ function useMcp(options) {
2448
2570
  clientUri,
2449
2571
  callbackUrl,
2450
2572
  preventAutoAuth,
2573
+ useRedirectFlow,
2451
2574
  onPopupWindow
2452
2575
  });
2453
2576
  addLog(
@@ -2469,7 +2592,8 @@ function useMcp(options) {
2469
2592
  clientName,
2470
2593
  clientUri,
2471
2594
  clientConfig.name,
2472
- clientConfig.version
2595
+ clientConfig.version,
2596
+ useRedirectFlow
2473
2597
  ]);
2474
2598
  (0, import_react.useEffect)(() => {
2475
2599
  let retryTimeoutId = null;
@@ -2577,24 +2701,31 @@ async function onMcpAuthorization() {
2577
2701
  authorizationCode: code
2578
2702
  });
2579
2703
  if (authResult === "AUTHORIZED") {
2580
- console.log(
2581
- `${logPrefix} Authorization successful via SDK auth(). Notifying opener...`
2582
- );
2583
- if (window.opener && !window.opener.closed) {
2704
+ console.log(`${logPrefix} Authorization successful via SDK auth().`);
2705
+ const isRedirectFlow = storedStateData.flowType === "redirect";
2706
+ if (isRedirectFlow && storedStateData.returnUrl) {
2707
+ console.log(
2708
+ `${logPrefix} Redirect flow complete. Returning to: ${storedStateData.returnUrl}`
2709
+ );
2710
+ localStorage.removeItem(stateKey);
2711
+ window.location.href = storedStateData.returnUrl;
2712
+ } else if (window.opener && !window.opener.closed) {
2713
+ console.log(`${logPrefix} Popup flow complete. Notifying opener...`);
2584
2714
  window.opener.postMessage(
2585
2715
  { type: "mcp_auth_callback", success: true },
2586
2716
  window.location.origin
2587
2717
  );
2718
+ localStorage.removeItem(stateKey);
2588
2719
  window.close();
2589
2720
  } else {
2590
2721
  console.warn(
2591
- `${logPrefix} No opener window detected. Redirecting to root.`
2722
+ `${logPrefix} No opener window or return URL detected. Redirecting to root.`
2592
2723
  );
2724
+ localStorage.removeItem(stateKey);
2593
2725
  const pathParts = window.location.pathname.split("/").filter(Boolean);
2594
2726
  const basePath = pathParts.length > 0 && pathParts[pathParts.length - 1] === "callback" ? "/" + pathParts.slice(0, -2).join("/") : "/";
2595
2727
  window.location.href = basePath || "/";
2596
2728
  }
2597
- localStorage.removeItem(stateKey);
2598
2729
  } else {
2599
2730
  console.warn(
2600
2731
  `${logPrefix} SDK auth() returned unexpected status: ${authResult}`
@@ -3413,7 +3544,18 @@ __name(WidgetControls, "WidgetControls");
3413
3544
 
3414
3545
  // src/react/McpUseProvider.tsx
3415
3546
  var import_react7 = __toESM(require("react"), 1);
3416
- var import_react_router_dom = require("react-router-dom");
3547
+ var BrowserRouter = null;
3548
+ var routerError = null;
3549
+ (async () => {
3550
+ try {
3551
+ const routerModule = await import("react-router-dom");
3552
+ BrowserRouter = routerModule.BrowserRouter;
3553
+ } catch (error) {
3554
+ routerError = new Error(
3555
+ "\u274C react-router-dom not installed!\n\nTo use MCP widgets with McpUseProvider, you need to install:\n\n npm install react-router-dom\n # or\n pnpm add react-router-dom\n\nThis dependency is automatically included in projects created with 'create-mcp-use-app'."
3556
+ );
3557
+ }
3558
+ })();
3417
3559
  function getBasename() {
3418
3560
  if (typeof window === "undefined") return "/";
3419
3561
  const path = window.location.pathname;
@@ -3507,7 +3649,13 @@ function McpUseProvider({
3507
3649
  if (enableDebugger || viewControls) {
3508
3650
  content = /* @__PURE__ */ import_react7.default.createElement(WidgetControls, { debugger: enableDebugger, viewControls }, content);
3509
3651
  }
3510
- content = /* @__PURE__ */ import_react7.default.createElement(import_react_router_dom.BrowserRouter, { basename }, content);
3652
+ if (routerError) {
3653
+ throw routerError;
3654
+ }
3655
+ if (!BrowserRouter) {
3656
+ throw new Error("react-router-dom is still loading, please try again.");
3657
+ }
3658
+ content = /* @__PURE__ */ import_react7.default.createElement(BrowserRouter, { basename }, content);
3511
3659
  content = /* @__PURE__ */ import_react7.default.createElement(ThemeProvider, null, content);
3512
3660
  if (autoSize) {
3513
3661
  const containerStyle = {
@@ -9,10 +9,12 @@ import {
9
9
  useWidgetProps,
10
10
  useWidgetState,
11
11
  useWidgetTheme
12
- } from "../../chunk-SJEHVCPM.js";
12
+ } from "../../chunk-BG2APH43.js";
13
+ import "../../chunk-AGKMD2ZM.js";
13
14
  import {
14
15
  onMcpAuthorization
15
- } from "../../chunk-BWOTID2D.js";
16
+ } from "../../chunk-3R5PDYIN.js";
17
+ import "../../chunk-MTHLLDCX.js";
16
18
  import "../../chunk-2JBWOW4S.js";
17
19
  import "../../chunk-34R6SIER.js";
18
20
  import "../../chunk-3GQAWCBQ.js";
@@ -30,10 +30,21 @@ export type UseMcpOptions = {
30
30
  popupFeatures?: string;
31
31
  /** Transport type preference: 'auto' (HTTP with SSE fallback), 'http' (HTTP only), 'sse' (SSE only) */
32
32
  transportType?: "auto" | "http" | "sse";
33
- /** Prevent automatic authentication popup on initial connection (default: false) */
33
+ /**
34
+ * Prevent automatic authentication popup/redirect on initial connection (default: false)
35
+ * When true, the connection will enter 'pending_auth' state and wait for user to call authenticate()
36
+ * Set to true to show a modal/button before triggering OAuth instead of auto-redirecting
37
+ */
34
38
  preventAutoAuth?: boolean;
39
+ /**
40
+ * Use full-page redirect for OAuth instead of popup window (default: false)
41
+ * Redirect flow avoids popup blockers and provides better UX on mobile.
42
+ * Set to true to use redirect flow instead of popup.
43
+ */
44
+ useRedirectFlow?: boolean;
35
45
  /**
36
46
  * Callback function that is invoked just before the authentication popup window is opened.
47
+ * Only used when useRedirectFlow is false (popup mode).
37
48
  * @param url The URL that will be opened in the popup.
38
49
  * @param features The features string for the popup window.
39
50
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACL,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IAC1B,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6HAA6H;IAC7H,OAAO,CAA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AAI,EAAE,MAAM,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;aAAE,CAAC;SAC9D,CAAC,CAAC;KACJ,CAAC,CAAC;IACH,+DAA+D;IAC/D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,kDAAkD;IAClD,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,+GAA+G;IAC/G,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMcp.d.ts","sourceRoot":"","sources":["../../../src/react/useMcp.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAg4B3D"}
1
+ {"version":3,"file":"useMcp.d.ts","sourceRoot":"","sources":["../../../src/react/useMcp.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CA4+B3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"connect-adapter.d.ts","sourceRoot":"","sources":["../../../src/server/connect-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,iBAAiB,EAAQ,MAAM,MAAM,CAAC;AAE7D;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,GAAG,GAAG,OAAO,CA0C5D;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,GAAG,EACf,cAAc,GAAE,MAAY,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CAQ5B;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,iBAAiB,EAAE,GAAG,EACtB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,iBAAiB,CAAC,CAwJ5B"}
1
+ {"version":3,"file":"connect-adapter.d.ts","sourceRoot":"","sources":["../../../src/server/connect-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,iBAAiB,EAAQ,MAAM,MAAM,CAAC;AAE7D;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,GAAG,GAAG,OAAO,CA0C5D;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,GAAG,EACf,cAAc,GAAE,MAAY,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CAQ5B;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,iBAAiB,EAAE,GAAG,EACtB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,iBAAiB,CAAC,CA6J5B"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * AsyncLocalStorage-based context management for HTTP requests
3
+ *
4
+ * This module provides a way to pass HTTP request context (Hono Context)
5
+ * through async call chains without explicit parameter passing.
6
+ *
7
+ * This is particularly useful for:
8
+ * - Passing authentication info from middleware to tool callbacks
9
+ * - Accessing request headers, user data, etc. in deeply nested functions
10
+ * - Maintaining request isolation in concurrent request handling
11
+ */
12
+ import type { Context } from "hono";
13
+ /**
14
+ * Execute a function with a request context stored in AsyncLocalStorage
15
+ *
16
+ * @param context - Hono Context object to store
17
+ * @param fn - Function to execute within this context
18
+ * @returns Promise resolving to the function's return value
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * app.post('/mcp', async (c) => {
23
+ * return runWithContext(c, async () => {
24
+ * // Any async operations here can access context via getRequestContext()
25
+ * await handleMcpRequest();
26
+ * return c.json({ success: true });
27
+ * });
28
+ * });
29
+ * ```
30
+ */
31
+ export declare function runWithContext<T>(context: Context, fn: () => Promise<T>): Promise<T>;
32
+ /**
33
+ * Get the current request context from AsyncLocalStorage
34
+ *
35
+ * @returns The Hono Context for the current async operation, or undefined if not in a request context
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // Inside a tool callback
40
+ * const context = getRequestContext();
41
+ * if (context) {
42
+ * const user = context.get('user');
43
+ * console.log('Current user:', user);
44
+ * }
45
+ * ```
46
+ */
47
+ export declare function getRequestContext(): Context | undefined;
48
+ /**
49
+ * Check if currently executing within a request context
50
+ *
51
+ * @returns true if a request context is available
52
+ */
53
+ export declare function hasRequestContext(): boolean;
54
+ //# sourceMappingURL=context-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-storage.d.ts","sourceRoot":"","sources":["../../../src/server/context-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAQpC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,GAAG,SAAS,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C"}