fastmcp 4.26.0 → 4.26.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 (36) hide show
  1. package/README.md +8 -2
  2. package/dist/FastMCP.cjs +3 -3
  3. package/dist/FastMCP.d.cts +2 -2
  4. package/dist/FastMCP.d.ts +2 -2
  5. package/dist/FastMCP.js +2 -2
  6. package/dist/{OAuthProvider-CPC9zG96.d.cts → OAuthProvider-5T2VSp7V.d.cts} +34 -1
  7. package/dist/{OAuthProvider-CPC9zG96.d.ts → OAuthProvider-5T2VSp7V.d.ts} +34 -1
  8. package/dist/auth/index.cjs +2 -2
  9. package/dist/auth/index.d.cts +17 -3
  10. package/dist/auth/index.d.ts +17 -3
  11. package/dist/auth/index.js +1 -1
  12. package/dist/{chunk-LUGELV2V.js → chunk-GUHJKVLX.js} +63 -32
  13. package/dist/chunk-GUHJKVLX.js.map +1 -0
  14. package/dist/{chunk-3VYVXSBB.js → chunk-KYUSH4TQ.js} +188 -41
  15. package/dist/chunk-KYUSH4TQ.js.map +1 -0
  16. package/dist/{chunk-ZHTH5HQD.cjs → chunk-MT5SJOZ5.cjs} +93 -62
  17. package/dist/chunk-MT5SJOZ5.cjs.map +1 -0
  18. package/dist/{chunk-AKHG27NY.cjs → chunk-UNS6EZVP.cjs} +202 -55
  19. package/dist/chunk-UNS6EZVP.cjs.map +1 -0
  20. package/dist/edge/index.cjs +110 -16
  21. package/dist/edge/index.cjs.map +1 -1
  22. package/dist/edge/index.d.cts +7 -2
  23. package/dist/edge/index.d.ts +7 -2
  24. package/dist/edge/index.js +110 -16
  25. package/dist/edge/index.js.map +1 -1
  26. package/dist/examples/custom-routes.cjs +3 -3
  27. package/dist/examples/custom-routes.js +2 -2
  28. package/dist/openapi/index.cjs +8 -8
  29. package/dist/openapi/index.d.cts +1 -1
  30. package/dist/openapi/index.d.ts +1 -1
  31. package/dist/openapi/index.js +2 -2
  32. package/package.json +1 -1
  33. package/dist/chunk-3VYVXSBB.js.map +0 -1
  34. package/dist/chunk-AKHG27NY.cjs.map +0 -1
  35. package/dist/chunk-LUGELV2V.js.map +0 -1
  36. package/dist/chunk-ZHTH5HQD.cjs.map +0 -1
package/README.md CHANGED
@@ -406,17 +406,19 @@ FastMCP supports edge runtimes like Cloudflare Workers, enabling deployment of M
406
406
 
407
407
  > **Note:** Built-in authentication for EdgeFastMCP is planned for a future release. Both FastMCP and EdgeFastMCP use Hono internally, so there's no technical barrier—EdgeFastMCP was simply written before OAuth was added to FastMCP. PRs are welcome to add an `authenticate` option that accepts web `Request` instead of Node.js `http.IncomingMessage`.
408
408
  >
409
- > In the meantime, use Hono middleware:
409
+ > In the meantime, use Hono middleware. Middleware (a handler that takes `next`) runs in front of the MCP endpoint as well as your own routes, however it is registered, so this protects `/mcp`:
410
410
  >
411
411
  > ```ts
412
412
  > const app = server.getApp();
413
- > app.use("/api/*", async (c, next) => {
413
+ > app.use("/mcp", async (c, next) => {
414
414
  > if (c.req.header("authorization") !== "Bearer secret") {
415
415
  > return c.json({ error: "Unauthorized" }, 401);
416
416
  > }
417
417
  > await next();
418
418
  > });
419
419
  > ```
420
+ >
421
+ > A handler that takes only the context is a route of its own and does not replace the MCP endpoint. The `/health` route is not covered by middleware.
420
422
 
421
423
  ##### Cloudflare Workers
422
424
 
@@ -754,6 +756,10 @@ server.addTool({
754
756
  });
755
757
  ```
756
758
 
759
+ `canAccess` is synchronous, and only a boolean `true` allows access. An `async`
760
+ function returns a Promise, so the tool it guards is hidden from every session
761
+ and a warning is logged.
762
+
757
763
  A server without an `authenticate` function has no auth to check, so every
758
764
  session sees every tool. With one, a session that still ends up without auth —
759
765
  on stdio, where the server carries on when `authenticate` throws or returns
package/dist/FastMCP.cjs CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkZHTH5HQDcjs = require('./chunk-ZHTH5HQD.cjs');
14
+ var _chunkMT5SJOZ5cjs = require('./chunk-MT5SJOZ5.cjs');
15
15
 
16
16
 
17
17
 
@@ -24,7 +24,7 @@ var _chunkZHTH5HQDcjs = require('./chunk-ZHTH5HQD.cjs');
24
24
 
25
25
 
26
26
 
27
- var _chunkAKHG27NYcjs = require('./chunk-AKHG27NY.cjs');
27
+ var _chunkUNS6EZVPcjs = require('./chunk-UNS6EZVP.cjs');
28
28
  require('./chunk-6TDYSPLC.cjs');
29
29
 
30
30
 
@@ -50,5 +50,5 @@ require('./chunk-6TDYSPLC.cjs');
50
50
 
51
51
 
52
52
 
53
- exports.AuthProvider = _chunkAKHG27NYcjs.AuthProvider; exports.AzureProvider = _chunkAKHG27NYcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkZHTH5HQDcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkZHTH5HQDcjs.FastMCP; exports.FastMCPError = _chunkZHTH5HQDcjs.FastMCPError; exports.FastMCPSession = _chunkZHTH5HQDcjs.FastMCPSession; exports.GitHubProvider = _chunkAKHG27NYcjs.GitHubProvider; exports.GoogleProvider = _chunkAKHG27NYcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkZHTH5HQDcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkAKHG27NYcjs.OAuthProvider; exports.ServerState = _chunkZHTH5HQDcjs.ServerState; exports.SessionError = _chunkZHTH5HQDcjs.SessionError; exports.UnexpectedStateError = _chunkZHTH5HQDcjs.UnexpectedStateError; exports.UserError = _chunkZHTH5HQDcjs.UserError; exports.audioContent = _chunkZHTH5HQDcjs.audioContent; exports.getAuthSession = _chunkAKHG27NYcjs.getAuthSession; exports.imageContent = _chunkZHTH5HQDcjs.imageContent; exports.jsonSchemaAdapter = _chunkZHTH5HQDcjs.jsonSchemaAdapter; exports.requireAll = _chunkAKHG27NYcjs.requireAll; exports.requireAny = _chunkAKHG27NYcjs.requireAny; exports.requireAuth = _chunkAKHG27NYcjs.requireAuth; exports.requireRole = _chunkAKHG27NYcjs.requireRole; exports.requireScopes = _chunkAKHG27NYcjs.requireScopes;
53
+ exports.AuthProvider = _chunkUNS6EZVPcjs.AuthProvider; exports.AzureProvider = _chunkUNS6EZVPcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkMT5SJOZ5cjs.DiscoveryDocumentCache; exports.FastMCP = _chunkMT5SJOZ5cjs.FastMCP; exports.FastMCPError = _chunkMT5SJOZ5cjs.FastMCPError; exports.FastMCPSession = _chunkMT5SJOZ5cjs.FastMCPSession; exports.GitHubProvider = _chunkUNS6EZVPcjs.GitHubProvider; exports.GoogleProvider = _chunkUNS6EZVPcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkMT5SJOZ5cjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkUNS6EZVPcjs.OAuthProvider; exports.ServerState = _chunkMT5SJOZ5cjs.ServerState; exports.SessionError = _chunkMT5SJOZ5cjs.SessionError; exports.UnexpectedStateError = _chunkMT5SJOZ5cjs.UnexpectedStateError; exports.UserError = _chunkMT5SJOZ5cjs.UserError; exports.audioContent = _chunkMT5SJOZ5cjs.audioContent; exports.getAuthSession = _chunkUNS6EZVPcjs.getAuthSession; exports.imageContent = _chunkMT5SJOZ5cjs.imageContent; exports.jsonSchemaAdapter = _chunkMT5SJOZ5cjs.jsonSchemaAdapter; exports.requireAll = _chunkUNS6EZVPcjs.requireAll; exports.requireAny = _chunkUNS6EZVPcjs.requireAny; exports.requireAuth = _chunkUNS6EZVPcjs.requireAuth; exports.requireRole = _chunkUNS6EZVPcjs.requireRole; exports.requireScopes = _chunkUNS6EZVPcjs.requireScopes;
54
54
  //# sourceMappingURL=FastMCP.cjs.map
@@ -12,8 +12,8 @@ import { CorsOptions } from 'mcp-proxy';
12
12
  export { CorsOptions } from 'mcp-proxy';
13
13
  import { StrictEventEmitter } from 'strict-event-emitter-types';
14
14
  import { z } from 'zod';
15
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-CPC9zG96.cjs';
16
- export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-CPC9zG96.cjs';
15
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-5T2VSp7V.cjs';
16
+ export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-5T2VSp7V.cjs';
17
17
  import 'node:http';
18
18
 
19
19
  declare class DiscoveryDocumentCache {
package/dist/FastMCP.d.ts CHANGED
@@ -12,8 +12,8 @@ import { CorsOptions } from 'mcp-proxy';
12
12
  export { CorsOptions } from 'mcp-proxy';
13
13
  import { StrictEventEmitter } from 'strict-event-emitter-types';
14
14
  import { z } from 'zod';
15
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-CPC9zG96.js';
16
- export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-CPC9zG96.js';
15
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-5T2VSp7V.js';
16
+ export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-5T2VSp7V.js';
17
17
  import 'node:http';
18
18
 
19
19
  declare class DiscoveryDocumentCache {
package/dist/FastMCP.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  audioContent,
12
12
  imageContent,
13
13
  jsonSchemaAdapter
14
- } from "./chunk-LUGELV2V.js";
14
+ } from "./chunk-GUHJKVLX.js";
15
15
  import {
16
16
  AuthProvider,
17
17
  AzureProvider,
@@ -24,7 +24,7 @@ import {
24
24
  requireAuth,
25
25
  requireRole,
26
26
  requireScopes
27
- } from "./chunk-3VYVXSBB.js";
27
+ } from "./chunk-KYUSH4TQ.js";
28
28
  import "./chunk-OKKFL2M4.js";
29
29
  export {
30
30
  AuthProvider,
@@ -59,6 +59,8 @@ interface ClientCode {
59
59
  interface ConsentData {
60
60
  clientName: string;
61
61
  provider: string;
62
+ /** Where the client is sent once the user approves. */
63
+ redirectUri?: string;
62
64
  scope: string[];
63
65
  timestamp: number;
64
66
  transactionId: string;
@@ -318,6 +320,11 @@ interface OAuthTransaction {
318
320
  clientCodeChallengeMethod: string;
319
321
  /** Client ID from registration */
320
322
  clientId: string;
323
+ /**
324
+ * Digest of the cookie held by the browser the consent screen was shown to.
325
+ * Approving the request and finishing it both take that cookie.
326
+ */
327
+ consentBinding?: string;
321
328
  /** Whether user consent was given */
322
329
  consentGiven?: boolean;
323
330
  /** Transaction creation timestamp */
@@ -554,7 +561,7 @@ declare class OAuthProxy {
554
561
  /**
555
562
  * OAuth authorization endpoint
556
563
  */
557
- authorize(params: AuthorizationParams): Promise<Response>;
564
+ authorize(params: AuthorizationParams, request?: Request): Promise<Response>;
558
565
  /**
559
566
  * Stop cleanup interval and destroy resources
560
567
  */
@@ -631,6 +638,24 @@ declare class OAuthProxy {
631
638
  * Periodic maintenance hook. Expiry is enforced by the token storage.
632
639
  */
633
640
  private cleanup;
641
+ /**
642
+ * The cookie that ties consent requests to the browser they were shown to.
643
+ * A browser holds one, shared by every request it has open, and it lasts as
644
+ * long as a request does. `Lax` lets it travel with the provider's redirect
645
+ * back to the callback, which is a cross-site navigation. Over HTTPS the
646
+ * `__Host-` prefix keeps another host on the same site from setting it.
647
+ */
648
+ private consentCookie;
649
+ private consentCookieName;
650
+ /**
651
+ * The consent cookie `request` carries, if it carries a well-formed one.
652
+ *
653
+ * Only the spaces and tabs that may surround a cookie are dropped. Trimming
654
+ * all white space would take a cookie whose name begins with, say, a
655
+ * no-break space for this one, and a browser does not hold such a name to
656
+ * the `__Host-` rules.
657
+ */
658
+ private consentCookieValue;
634
659
  /**
635
660
  * Create a new OAuth transaction
636
661
  */
@@ -686,6 +711,14 @@ declare class OAuthProxy {
686
711
  * Handle swap mode refresh - verify FastMCP JWT and issue new tokens
687
712
  */
688
713
  private handleSwapModeRefresh;
714
+ /**
715
+ * Whether `request` comes from the browser the transaction's consent screen
716
+ * was shown to: it carries the cookie that screen set. A transaction that
717
+ * never had a consent screen is bound to no browser.
718
+ */
719
+ private isConsentBoundTo;
720
+ /** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
721
+ private isServedOverHttps;
689
722
  /**
690
723
  * Issue swapped tokens (JWT pattern)
691
724
  * Issues short-lived FastMCP JWTs and stores upstream tokens securely
@@ -59,6 +59,8 @@ interface ClientCode {
59
59
  interface ConsentData {
60
60
  clientName: string;
61
61
  provider: string;
62
+ /** Where the client is sent once the user approves. */
63
+ redirectUri?: string;
62
64
  scope: string[];
63
65
  timestamp: number;
64
66
  transactionId: string;
@@ -318,6 +320,11 @@ interface OAuthTransaction {
318
320
  clientCodeChallengeMethod: string;
319
321
  /** Client ID from registration */
320
322
  clientId: string;
323
+ /**
324
+ * Digest of the cookie held by the browser the consent screen was shown to.
325
+ * Approving the request and finishing it both take that cookie.
326
+ */
327
+ consentBinding?: string;
321
328
  /** Whether user consent was given */
322
329
  consentGiven?: boolean;
323
330
  /** Transaction creation timestamp */
@@ -554,7 +561,7 @@ declare class OAuthProxy {
554
561
  /**
555
562
  * OAuth authorization endpoint
556
563
  */
557
- authorize(params: AuthorizationParams): Promise<Response>;
564
+ authorize(params: AuthorizationParams, request?: Request): Promise<Response>;
558
565
  /**
559
566
  * Stop cleanup interval and destroy resources
560
567
  */
@@ -631,6 +638,24 @@ declare class OAuthProxy {
631
638
  * Periodic maintenance hook. Expiry is enforced by the token storage.
632
639
  */
633
640
  private cleanup;
641
+ /**
642
+ * The cookie that ties consent requests to the browser they were shown to.
643
+ * A browser holds one, shared by every request it has open, and it lasts as
644
+ * long as a request does. `Lax` lets it travel with the provider's redirect
645
+ * back to the callback, which is a cross-site navigation. Over HTTPS the
646
+ * `__Host-` prefix keeps another host on the same site from setting it.
647
+ */
648
+ private consentCookie;
649
+ private consentCookieName;
650
+ /**
651
+ * The consent cookie `request` carries, if it carries a well-formed one.
652
+ *
653
+ * Only the spaces and tabs that may surround a cookie are dropped. Trimming
654
+ * all white space would take a cookie whose name begins with, say, a
655
+ * no-break space for this one, and a browser does not hold such a name to
656
+ * the `__Host-` rules.
657
+ */
658
+ private consentCookieValue;
634
659
  /**
635
660
  * Create a new OAuth transaction
636
661
  */
@@ -686,6 +711,14 @@ declare class OAuthProxy {
686
711
  * Handle swap mode refresh - verify FastMCP JWT and issue new tokens
687
712
  */
688
713
  private handleSwapModeRefresh;
714
+ /**
715
+ * Whether `request` comes from the browser the transaction's consent screen
716
+ * was shown to: it carries the cookie that screen set. A transaction that
717
+ * never had a consent screen is bound to no browser.
718
+ */
719
+ private isConsentBoundTo;
720
+ /** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
721
+ private isServedOverHttps;
689
722
  /**
690
723
  * Issue swapped tokens (JWT pattern)
691
724
  * Issues short-lived FastMCP JWTs and stores upstream tokens securely
@@ -25,7 +25,7 @@
25
25
 
26
26
 
27
27
 
28
- var _chunkAKHG27NYcjs = require('../chunk-AKHG27NY.cjs');
28
+ var _chunkUNS6EZVPcjs = require('../chunk-UNS6EZVP.cjs');
29
29
 
30
30
 
31
31
 
@@ -53,5 +53,5 @@ var _chunkAKHG27NYcjs = require('../chunk-AKHG27NY.cjs');
53
53
 
54
54
 
55
55
 
56
- exports.AuthProvider = _chunkAKHG27NYcjs.AuthProvider; exports.AzureProvider = _chunkAKHG27NYcjs.AzureProvider; exports.ConsentManager = _chunkAKHG27NYcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkAKHG27NYcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkAKHG27NYcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkAKHG27NYcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkAKHG27NYcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkAKHG27NYcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkAKHG27NYcjs.DiskStore; exports.EncryptedTokenStorage = _chunkAKHG27NYcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkAKHG27NYcjs.GitHubProvider; exports.GoogleProvider = _chunkAKHG27NYcjs.GoogleProvider; exports.JWKSVerifier = _chunkAKHG27NYcjs.JWKSVerifier; exports.JWTIssuer = _chunkAKHG27NYcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkAKHG27NYcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkAKHG27NYcjs.OAuthProvider; exports.OAuthProxy = _chunkAKHG27NYcjs.OAuthProxy; exports.OAuthProxyError = _chunkAKHG27NYcjs.OAuthProxyError; exports.PKCEUtils = _chunkAKHG27NYcjs.PKCEUtils; exports.TOKEN_ENDPOINT_AUTH_METHODS = _chunkAKHG27NYcjs.TOKEN_ENDPOINT_AUTH_METHODS; exports.getAuthSession = _chunkAKHG27NYcjs.getAuthSession; exports.requireAll = _chunkAKHG27NYcjs.requireAll; exports.requireAny = _chunkAKHG27NYcjs.requireAny; exports.requireAuth = _chunkAKHG27NYcjs.requireAuth; exports.requireRole = _chunkAKHG27NYcjs.requireRole; exports.requireScopes = _chunkAKHG27NYcjs.requireScopes;
56
+ exports.AuthProvider = _chunkUNS6EZVPcjs.AuthProvider; exports.AzureProvider = _chunkUNS6EZVPcjs.AzureProvider; exports.ConsentManager = _chunkUNS6EZVPcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkUNS6EZVPcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkUNS6EZVPcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkUNS6EZVPcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkUNS6EZVPcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkUNS6EZVPcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkUNS6EZVPcjs.DiskStore; exports.EncryptedTokenStorage = _chunkUNS6EZVPcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkUNS6EZVPcjs.GitHubProvider; exports.GoogleProvider = _chunkUNS6EZVPcjs.GoogleProvider; exports.JWKSVerifier = _chunkUNS6EZVPcjs.JWKSVerifier; exports.JWTIssuer = _chunkUNS6EZVPcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkUNS6EZVPcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkUNS6EZVPcjs.OAuthProvider; exports.OAuthProxy = _chunkUNS6EZVPcjs.OAuthProxy; exports.OAuthProxyError = _chunkUNS6EZVPcjs.OAuthProxyError; exports.PKCEUtils = _chunkUNS6EZVPcjs.PKCEUtils; exports.TOKEN_ENDPOINT_AUTH_METHODS = _chunkUNS6EZVPcjs.TOKEN_ENDPOINT_AUTH_METHODS; exports.getAuthSession = _chunkUNS6EZVPcjs.getAuthSession; exports.requireAll = _chunkUNS6EZVPcjs.requireAll; exports.requireAny = _chunkUNS6EZVPcjs.requireAny; exports.requireAuth = _chunkUNS6EZVPcjs.requireAuth; exports.requireRole = _chunkUNS6EZVPcjs.requireRole; exports.requireScopes = _chunkUNS6EZVPcjs.requireScopes;
57
57
  //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,5 @@
1
- import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-CPC9zG96.cjs';
2
- export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-CPC9zG96.cjs';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-5T2VSp7V.cjs';
2
+ export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-5T2VSp7V.cjs';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -15,8 +15,15 @@ declare class ConsentManager {
15
15
  constructor(signingKey: string);
16
16
  /**
17
17
  * Create HTTP response with consent screen
18
+ *
19
+ * `cookie` is a `Set-Cookie` value that ties the request to the browser the
20
+ * screen is shown to. The screen may not be framed: a page that embeds it
21
+ * could have the user approve without seeing what they are approving.
18
22
  */
19
- createConsentResponse(transaction: OAuthTransaction, provider: string): Response;
23
+ createConsentResponse(transaction: OAuthTransaction, provider: string, options?: {
24
+ clientName?: string;
25
+ cookie?: string;
26
+ }): Response;
20
27
  /**
21
28
  * Generate HTML for consent screen
22
29
  */
@@ -29,6 +36,13 @@ declare class ConsentManager {
29
36
  * Validate and parse consent cookie
30
37
  */
31
38
  validateConsentCookie(cookie: string): ConsentData | null;
39
+ /**
40
+ * Where a redirect URI leads, as the browser will read it rather than as it
41
+ * was typed: the parsed host, so that a look-alike character, a tab or a
42
+ * backslash shows for what it does. A long host keeps its end, which is the
43
+ * part that says whose it is.
44
+ */
45
+ private describeDestination;
32
46
  /**
33
47
  * Escape HTML to prevent XSS
34
48
  */
@@ -1,5 +1,5 @@
1
- import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-CPC9zG96.js';
2
- export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-CPC9zG96.js';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-5T2VSp7V.js';
2
+ export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-5T2VSp7V.js';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -15,8 +15,15 @@ declare class ConsentManager {
15
15
  constructor(signingKey: string);
16
16
  /**
17
17
  * Create HTTP response with consent screen
18
+ *
19
+ * `cookie` is a `Set-Cookie` value that ties the request to the browser the
20
+ * screen is shown to. The screen may not be framed: a page that embeds it
21
+ * could have the user approve without seeing what they are approving.
18
22
  */
19
- createConsentResponse(transaction: OAuthTransaction, provider: string): Response;
23
+ createConsentResponse(transaction: OAuthTransaction, provider: string, options?: {
24
+ clientName?: string;
25
+ cookie?: string;
26
+ }): Response;
20
27
  /**
21
28
  * Generate HTML for consent screen
22
29
  */
@@ -29,6 +36,13 @@ declare class ConsentManager {
29
36
  * Validate and parse consent cookie
30
37
  */
31
38
  validateConsentCookie(cookie: string): ConsentData | null;
39
+ /**
40
+ * Where a redirect URI leads, as the browser will read it rather than as it
41
+ * was typed: the parsed host, so that a look-alike character, a tab or a
42
+ * backslash shows for what it does. A long host keeps its end, which is the
43
+ * part that says whose it is.
44
+ */
45
+ private describeDestination;
32
46
  /**
33
47
  * Escape HTML to prevent XSS
34
48
  */
@@ -25,7 +25,7 @@ import {
25
25
  requireAuth,
26
26
  requireRole,
27
27
  requireScopes
28
- } from "../chunk-3VYVXSBB.js";
28
+ } from "../chunk-KYUSH4TQ.js";
29
29
  export {
30
30
  AuthProvider,
31
31
  AzureProvider,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cancelResponseBody
3
- } from "./chunk-3VYVXSBB.js";
3
+ } from "./chunk-KYUSH4TQ.js";
4
4
  import {
5
5
  objectRootSchema,
6
6
  strictInputSchema,
@@ -697,7 +697,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
697
697
  this.setupCompleteHandlers();
698
698
  if (supportsTools) {
699
699
  this.setupToolHandlers(
700
- toolsVisibleTo(tools, this.#auth, this.#authRequired)
700
+ toolsVisibleTo(tools, this.#auth, this.#authRequired, this.#logger)
701
701
  );
702
702
  }
703
703
  if (resources.length || resourcesTemplates.length) {
@@ -839,7 +839,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
839
839
  }
840
840
  this.#tools = tools;
841
841
  this.setupToolHandlers(
842
- toolsVisibleTo(tools, this.#auth, this.#authRequired)
842
+ toolsVisibleTo(tools, this.#auth, this.#authRequired, this.#logger)
843
843
  );
844
844
  this.triggerListChangedNotification("notifications/tools/list_changed");
845
845
  }
@@ -862,7 +862,12 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
862
862
  */
863
863
  updateAuth(auth) {
864
864
  this.#auth = auth;
865
- const tools = toolsVisibleTo(this.#tools, auth, this.#authRequired);
865
+ const tools = toolsVisibleTo(
866
+ this.#tools,
867
+ auth,
868
+ this.#authRequired,
869
+ this.#logger
870
+ );
866
871
  if (tools.length !== this.#visibleTools.length || tools.some((tool, index) => tool !== this.#visibleTools[index])) {
867
872
  this.setupToolHandlers(tools);
868
873
  this.triggerListChangedNotification("notifications/tools/list_changed");
@@ -1934,6 +1939,9 @@ function convertObjectToSnakeCase(obj) {
1934
1939
  }
1935
1940
  return result;
1936
1941
  }
1942
+ function cookieHeaders(req) {
1943
+ return req.headers.cookie ? { cookie: req.headers.cookie } : {};
1944
+ }
1937
1945
  function isStreamableHttpTransport(transport) {
1938
1946
  return "handleRequest" in transport && typeof transport.handleRequest === "function";
1939
1947
  }
@@ -2058,6 +2066,20 @@ function grantedScopes(auth) {
2058
2066
  const values = Array.isArray(scopes) ? scopes : scopes instanceof Set ? [...scopes] : [];
2059
2067
  return values.filter((scope) => typeof scope === "string");
2060
2068
  }
2069
+ async function sendOAuthProxyResponse(res, response) {
2070
+ const body = await response.text();
2071
+ const headers = {};
2072
+ response.headers.forEach((value, key) => {
2073
+ if (key.toLowerCase() !== "set-cookie") {
2074
+ headers[key] = value;
2075
+ }
2076
+ });
2077
+ const setCookies = response.headers.getSetCookie();
2078
+ if (setCookies.length > 0) {
2079
+ headers["set-cookie"] = setCookies;
2080
+ }
2081
+ res.writeHead(response.status, headers).end(body);
2082
+ }
2061
2083
  function stripBasePath(path, basePath) {
2062
2084
  if (!basePath) {
2063
2085
  return path;
@@ -2070,12 +2092,32 @@ function stripBasePath(path, basePath) {
2070
2092
  }
2071
2093
  return null;
2072
2094
  }
2073
- function toolsVisibleTo(tools, auth, authRequired) {
2074
- if (auth) {
2075
- return tools.filter(
2076
- (tool) => tool.canAccess ? tool.canAccess(auth) : true
2095
+ var toolsWithInvalidCanAccess = /* @__PURE__ */ new WeakSet();
2096
+ function toolAdmits(tool, auth, logger) {
2097
+ if (!tool.canAccess) {
2098
+ return true;
2099
+ }
2100
+ const admitted = tool.canAccess(auth);
2101
+ if (typeof admitted === "boolean") {
2102
+ return admitted;
2103
+ }
2104
+ const isPromise = typeof admitted?.then === "function";
2105
+ if (isPromise) {
2106
+ Promise.resolve(admitted).catch(() => {
2107
+ });
2108
+ }
2109
+ if (admitted && !toolsWithInvalidCanAccess.has(tool)) {
2110
+ toolsWithInvalidCanAccess.add(tool);
2111
+ logger.warn(
2112
+ `[FastMCP warning] Tool '${tool.name}' is hidden: its canAccess returned ${isPromise ? "a Promise" : "a non-boolean value"}. canAccess must return a boolean synchronously.`
2077
2113
  );
2078
2114
  }
2115
+ return false;
2116
+ }
2117
+ function toolsVisibleTo(tools, auth, authRequired, logger) {
2118
+ if (auth) {
2119
+ return tools.filter((tool) => toolAdmits(tool, auth, logger));
2120
+ }
2079
2121
  return authRequired ? tools.filter((tool) => !tool.canAccess) : tools;
2080
2122
  }
2081
2123
  var FastMCPEventEmitterBase = EventEmitter;
@@ -3054,15 +3096,13 @@ var FastMCP = class extends FastMCPEventEmitter {
3054
3096
  try {
3055
3097
  const params = Object.fromEntries(url2.searchParams.entries());
3056
3098
  const response = await oauthProxy.authorize(
3057
- params
3099
+ params,
3100
+ // The consent cookie this browser already holds, if any
3101
+ new Request(`http://${host}${req.url}`, {
3102
+ headers: cookieHeaders(req)
3103
+ })
3058
3104
  );
3059
- const location = response.headers.get("Location");
3060
- if (location) {
3061
- res.writeHead(response.status, { Location: location }).end();
3062
- } else {
3063
- const html = await response.text();
3064
- res.writeHead(response.status, { "Content-Type": "text/html" }).end(html);
3065
- }
3105
+ await sendOAuthProxyResponse(res, response);
3066
3106
  } catch (error) {
3067
3107
  res.writeHead(400, { "Content-Type": "application/json" }).end(
3068
3108
  JSON.stringify(
@@ -3076,15 +3116,11 @@ var FastMCP = class extends FastMCPEventEmitter {
3076
3116
  }
3077
3117
  if (req.method === "GET" && oauthPath === "/oauth/callback") {
3078
3118
  try {
3079
- const mockRequest = new Request(`http://${host}${req.url}`);
3119
+ const mockRequest = new Request(`http://${host}${req.url}`, {
3120
+ headers: cookieHeaders(req)
3121
+ });
3080
3122
  const response = await oauthProxy.handleCallback(mockRequest);
3081
- const location = response.headers.get("Location");
3082
- if (location) {
3083
- res.writeHead(response.status, { Location: location }).end();
3084
- } else {
3085
- const text = await response.text();
3086
- res.writeHead(response.status).end(text);
3087
- }
3123
+ await sendOAuthProxyResponse(res, response);
3088
3124
  } catch (error) {
3089
3125
  res.writeHead(400, { "Content-Type": "application/json" }).end(
3090
3126
  JSON.stringify(
@@ -3141,19 +3177,14 @@ var FastMCP = class extends FastMCPEventEmitter {
3141
3177
  {
3142
3178
  body: Buffer.concat(bodyChunks).toString("utf8"),
3143
3179
  headers: {
3180
+ ...cookieHeaders(req),
3144
3181
  "Content-Type": "application/x-www-form-urlencoded"
3145
3182
  },
3146
3183
  method: "POST"
3147
3184
  }
3148
3185
  );
3149
3186
  const response = await oauthProxy.handleConsent(mockRequest);
3150
- const location = response.headers.get("Location");
3151
- if (location) {
3152
- res.writeHead(response.status, { Location: location }).end();
3153
- } else {
3154
- const text = await response.text();
3155
- res.writeHead(response.status).end(text);
3156
- }
3187
+ await sendOAuthProxyResponse(res, response);
3157
3188
  } catch (error) {
3158
3189
  res.writeHead(400, { "Content-Type": "application/json" }).end(
3159
3190
  JSON.stringify(
@@ -3547,4 +3578,4 @@ export {
3547
3578
  FastMCPSession,
3548
3579
  FastMCP
3549
3580
  };
3550
- //# sourceMappingURL=chunk-LUGELV2V.js.map
3581
+ //# sourceMappingURL=chunk-GUHJKVLX.js.map