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
@@ -1066,6 +1066,7 @@ var HttpConnector = class extends BaseConnector {
1066
1066
  stop: /* @__PURE__ */ __name(async () => {
1067
1067
  if (this.streamableTransport) {
1068
1068
  try {
1069
+ await this.streamableTransport.terminateSession();
1069
1070
  await this.streamableTransport.close();
1070
1071
  } catch (e) {
1071
1072
  logger.warn(`Error closing Streamable HTTP transport: ${e}`);
@@ -1090,6 +1091,8 @@ var HttpConnector = class extends BaseConnector {
1090
1091
  async connectWithSse(baseUrl) {
1091
1092
  try {
1092
1093
  this.connectionManager = new SseConnectionManager(baseUrl, {
1094
+ authProvider: this.opts.authProvider,
1095
+ // ← Pass OAuth provider to SDK (same as streamable HTTP)
1093
1096
  requestInit: {
1094
1097
  headers: this.headers
1095
1098
  }
@@ -1684,6 +1687,7 @@ var BrowserOAuthClientProvider = class {
1684
1687
  clientUri;
1685
1688
  callbackUrl;
1686
1689
  preventAutoAuth;
1690
+ useRedirectFlow;
1687
1691
  onPopupWindow;
1688
1692
  constructor(serverUrl, options = {}) {
1689
1693
  this.serverUrl = serverUrl;
@@ -1695,6 +1699,7 @@ var BrowserOAuthClientProvider = class {
1695
1699
  options.callbackUrl || (typeof window !== "undefined" ? new URL("/oauth/callback", window.location.origin).toString() : "/oauth/callback")
1696
1700
  );
1697
1701
  this.preventAutoAuth = options.preventAutoAuth;
1702
+ this.useRedirectFlow = options.useRedirectFlow;
1698
1703
  this.onPopupWindow = options.onPopupWindow;
1699
1704
  }
1700
1705
  // --- SDK Interface Methods ---
@@ -1786,7 +1791,11 @@ var BrowserOAuthClientProvider = class {
1786
1791
  clientName: this.clientName,
1787
1792
  clientUri: this.clientUri,
1788
1793
  callbackUrl: this.callbackUrl
1789
- }
1794
+ },
1795
+ // Store flow type so callback knows how to handle the response
1796
+ flowType: this.useRedirectFlow ? "redirect" : "popup",
1797
+ // Store current URL for redirect flow so we can return to it
1798
+ returnUrl: this.useRedirectFlow && typeof window !== "undefined" ? window.location.href : void 0
1790
1799
  };
1791
1800
  localStorage.setItem(stateKey, JSON.stringify(stateData));
1792
1801
  authorizationUrl.searchParams.set("state", state);
@@ -1801,8 +1810,20 @@ var BrowserOAuthClientProvider = class {
1801
1810
  * @param authorizationUrl The fully constructed authorization URL from the SDK.
1802
1811
  */
1803
1812
  async redirectToAuthorization(authorizationUrl) {
1804
- if (this.preventAutoAuth) return;
1805
1813
  const sanitizedAuthUrl = await this.prepareAuthorizationUrl(authorizationUrl);
1814
+ if (this.preventAutoAuth) {
1815
+ console.info(
1816
+ `[${this.storageKeyPrefix}] Auto-auth prevented. Authorization URL stored for manual trigger.`
1817
+ );
1818
+ return;
1819
+ }
1820
+ if (this.useRedirectFlow) {
1821
+ console.info(
1822
+ `[${this.storageKeyPrefix}] Redirecting to authorization URL (full-page redirect).`
1823
+ );
1824
+ window.location.href = sanitizedAuthUrl;
1825
+ return;
1826
+ }
1806
1827
  const popupFeatures = "width=600,height=700,resizable=yes,scrollbars=yes,status=yes";
1807
1828
  try {
1808
1829
  const popup = window.open(
@@ -1897,7 +1918,6 @@ __name(assert, "assert");
1897
1918
  // src/react/useMcp.ts
1898
1919
  var DEFAULT_RECONNECT_DELAY = 3e3;
1899
1920
  var DEFAULT_RETRY_DELAY = 5e3;
1900
- var AUTH_TIMEOUT = 5 * 60 * 1e3;
1901
1921
  function useMcp(options) {
1902
1922
  const {
1903
1923
  url,
@@ -1915,6 +1935,9 @@ function useMcp(options) {
1915
1935
  autoReconnect = DEFAULT_RECONNECT_DELAY,
1916
1936
  transportType = "auto",
1917
1937
  preventAutoAuth = false,
1938
+ // Default to false for backward compatibility (auto-trigger OAuth)
1939
+ useRedirectFlow = false,
1940
+ // Default to false for backward compatibility (use popup)
1918
1941
  onPopupWindow,
1919
1942
  timeout = 3e4,
1920
1943
  // 30 seconds default for connection timeout
@@ -2040,6 +2063,7 @@ function useMcp(options) {
2040
2063
  clientUri,
2041
2064
  callbackUrl,
2042
2065
  preventAutoAuth,
2066
+ useRedirectFlow,
2043
2067
  onPopupWindow
2044
2068
  });
2045
2069
  addLog("debug", "BrowserOAuthClientProvider initialized in connect.");
@@ -2130,6 +2154,42 @@ function useMcp(options) {
2130
2154
  } catch (err) {
2131
2155
  const errorMessage = err?.message || String(err);
2132
2156
  if (err.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
2157
+ if (authProviderRef.current) {
2158
+ addLog(
2159
+ "info",
2160
+ "Authentication required. OAuth provider available."
2161
+ );
2162
+ try {
2163
+ const { auth: auth2 } = await import("@modelcontextprotocol/sdk/client/auth.js");
2164
+ const baseUrl = new URL(url).origin;
2165
+ auth2(authProviderRef.current, { serverUrl: baseUrl }).catch(
2166
+ () => {
2167
+ }
2168
+ );
2169
+ setTimeout(() => {
2170
+ if (isMountedRef.current) {
2171
+ const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
2172
+ if (manualUrl) {
2173
+ setAuthUrl(manualUrl);
2174
+ addLog(
2175
+ "info",
2176
+ "Manual authentication URL available:",
2177
+ manualUrl
2178
+ );
2179
+ } else {
2180
+ addLog("warn", "Could not generate authentication URL");
2181
+ }
2182
+ }
2183
+ }, 100);
2184
+ } catch (authGenError) {
2185
+ addLog("warn", "Error generating auth URL:", authGenError);
2186
+ }
2187
+ if (isMountedRef.current) {
2188
+ setState("pending_auth");
2189
+ }
2190
+ connectingRef.current = false;
2191
+ return "auth_redirect";
2192
+ }
2133
2193
  if (customHeaders && Object.keys(customHeaders).length > 0) {
2134
2194
  failConnection(
2135
2195
  "Authentication failed: Server returned 401 Unauthorized. Check your Authorization header value is correct."
@@ -2181,6 +2241,7 @@ function useMcp(options) {
2181
2241
  customHeaders,
2182
2242
  transportType,
2183
2243
  preventAutoAuth,
2244
+ useRedirectFlow,
2184
2245
  onPopupWindow,
2185
2246
  enabled,
2186
2247
  timeout,
@@ -2233,32 +2294,54 @@ function useMcp(options) {
2233
2294
  retry();
2234
2295
  } else if (currentState === "pending_auth") {
2235
2296
  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
2297
  try {
2247
2298
  assert(
2248
2299
  authProviderRef.current,
2249
2300
  "Auth Provider not available for manual auth"
2250
2301
  );
2251
2302
  assert(url, "Server URL is required for authentication");
2252
- addLog(
2253
- "info",
2254
- "Redirecting for manual authentication. Waiting for callback..."
2255
- );
2303
+ addLog("info", "Clearing all OAuth state and initiating fresh flow...");
2304
+ const hashPrefix = `${storageKeyPrefix}:${authProviderRef.current.serverUrlHash}`;
2305
+ Object.keys(localStorage).forEach((key) => {
2306
+ if (key.startsWith(hashPrefix)) {
2307
+ addLog("debug", `Removing stale OAuth key: ${key}`);
2308
+ localStorage.removeItem(key);
2309
+ }
2310
+ if (key.startsWith(`${storageKeyPrefix}:state_`)) {
2311
+ addLog("debug", `Removing orphaned state: ${key}`);
2312
+ localStorage.removeItem(key);
2313
+ }
2314
+ });
2315
+ setState("authenticating");
2316
+ const freshAuthProvider = new BrowserOAuthClientProvider(url, {
2317
+ storageKeyPrefix,
2318
+ clientName,
2319
+ clientUri,
2320
+ callbackUrl,
2321
+ preventAutoAuth: false,
2322
+ // ← Allow OAuth to proceed
2323
+ useRedirectFlow,
2324
+ onPopupWindow
2325
+ });
2326
+ authProviderRef.current = freshAuthProvider;
2327
+ addLog("info", "Triggering fresh OAuth authorization...");
2328
+ const { auth: auth2 } = await import("@modelcontextprotocol/sdk/client/auth.js");
2329
+ const baseUrl = new URL(url).origin;
2330
+ auth2(freshAuthProvider, {
2331
+ serverUrl: baseUrl
2332
+ }).catch((err) => {
2333
+ addLog(
2334
+ "info",
2335
+ "OAuth flow initiated:",
2336
+ err?.message || "Redirecting..."
2337
+ );
2338
+ });
2256
2339
  } catch (authError) {
2257
2340
  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
2341
+ setState("pending_auth");
2342
+ addLog(
2343
+ "error",
2344
+ `Manual authentication failed: ${authError instanceof Error ? authError.message : String(authError)}`
2262
2345
  );
2263
2346
  }
2264
2347
  } else if (currentState === "authenticating") {
@@ -2277,7 +2360,18 @@ function useMcp(options) {
2277
2360
  `Client not in a state requiring manual authentication trigger (state: ${currentState}). If needed, try disconnecting and reconnecting.`
2278
2361
  );
2279
2362
  }
2280
- }, [addLog, retry, authUrl, url, failConnection, connect]);
2363
+ }, [
2364
+ addLog,
2365
+ retry,
2366
+ authUrl,
2367
+ url,
2368
+ useRedirectFlow,
2369
+ onPopupWindow,
2370
+ storageKeyPrefix,
2371
+ clientName,
2372
+ clientUri,
2373
+ callbackUrl
2374
+ ]);
2281
2375
  const clearStorage = (0, import_react.useCallback)(() => {
2282
2376
  if (authProviderRef.current) {
2283
2377
  const count = authProviderRef.current.clearStorage();
@@ -2448,6 +2542,7 @@ function useMcp(options) {
2448
2542
  clientUri,
2449
2543
  callbackUrl,
2450
2544
  preventAutoAuth,
2545
+ useRedirectFlow,
2451
2546
  onPopupWindow
2452
2547
  });
2453
2548
  addLog(
@@ -2469,7 +2564,8 @@ function useMcp(options) {
2469
2564
  clientName,
2470
2565
  clientUri,
2471
2566
  clientConfig.name,
2472
- clientConfig.version
2567
+ clientConfig.version,
2568
+ useRedirectFlow
2473
2569
  ]);
2474
2570
  (0, import_react.useEffect)(() => {
2475
2571
  let retryTimeoutId = null;
@@ -2577,24 +2673,31 @@ async function onMcpAuthorization() {
2577
2673
  authorizationCode: code
2578
2674
  });
2579
2675
  if (authResult === "AUTHORIZED") {
2580
- console.log(
2581
- `${logPrefix} Authorization successful via SDK auth(). Notifying opener...`
2582
- );
2583
- if (window.opener && !window.opener.closed) {
2676
+ console.log(`${logPrefix} Authorization successful via SDK auth().`);
2677
+ const isRedirectFlow = storedStateData.flowType === "redirect";
2678
+ if (isRedirectFlow && storedStateData.returnUrl) {
2679
+ console.log(
2680
+ `${logPrefix} Redirect flow complete. Returning to: ${storedStateData.returnUrl}`
2681
+ );
2682
+ localStorage.removeItem(stateKey);
2683
+ window.location.href = storedStateData.returnUrl;
2684
+ } else if (window.opener && !window.opener.closed) {
2685
+ console.log(`${logPrefix} Popup flow complete. Notifying opener...`);
2584
2686
  window.opener.postMessage(
2585
2687
  { type: "mcp_auth_callback", success: true },
2586
2688
  window.location.origin
2587
2689
  );
2690
+ localStorage.removeItem(stateKey);
2588
2691
  window.close();
2589
2692
  } else {
2590
2693
  console.warn(
2591
- `${logPrefix} No opener window detected. Redirecting to root.`
2694
+ `${logPrefix} No opener window or return URL detected. Redirecting to root.`
2592
2695
  );
2696
+ localStorage.removeItem(stateKey);
2593
2697
  const pathParts = window.location.pathname.split("/").filter(Boolean);
2594
2698
  const basePath = pathParts.length > 0 && pathParts[pathParts.length - 1] === "callback" ? "/" + pathParts.slice(0, -2).join("/") : "/";
2595
2699
  window.location.href = basePath || "/";
2596
2700
  }
2597
- localStorage.removeItem(stateKey);
2598
2701
  } else {
2599
2702
  console.warn(
2600
2703
  `${logPrefix} SDK auth() returned unexpected status: ${authResult}`
@@ -9,10 +9,11 @@ import {
9
9
  useWidgetProps,
10
10
  useWidgetState,
11
11
  useWidgetTheme
12
- } from "../../chunk-SJEHVCPM.js";
12
+ } from "../../chunk-XN2PU4PS.js";
13
+ import "../../chunk-QSLJXXMG.js";
13
14
  import {
14
15
  onMcpAuthorization
15
- } from "../../chunk-BWOTID2D.js";
16
+ } from "../../chunk-PE7UMCVO.js";
16
17
  import "../../chunk-2JBWOW4S.js";
17
18
  import "../../chunk-34R6SIER.js";
18
19
  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,CAAC,EAAE,OAAO,CAAC;IAClB,2EAA2E;IAC3E,UAAU,CAAC,EAA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C;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"}
@@ -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"}