fastmcp 4.25.1 → 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 (38) hide show
  1. package/README.md +10 -2
  2. package/dist/FastMCP.cjs +3 -3
  3. package/dist/FastMCP.d.cts +3 -2
  4. package/dist/FastMCP.d.ts +3 -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-SQSE766U.js → chunk-GUHJKVLX.js} +67 -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-VWHJYU4V.cjs → chunk-MT5SJOZ5.cjs} +96 -61
  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 +22 -9
  29. package/dist/openapi/index.cjs.map +1 -1
  30. package/dist/openapi/index.d.cts +6 -5
  31. package/dist/openapi/index.d.ts +6 -5
  32. package/dist/openapi/index.js +16 -3
  33. package/dist/openapi/index.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/chunk-3VYVXSBB.js.map +0 -1
  36. package/dist/chunk-AKHG27NY.cjs.map +0 -1
  37. package/dist/chunk-SQSE766U.js.map +0 -1
  38. package/dist/chunk-VWHJYU4V.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
 
@@ -514,6 +516,8 @@ server.start({
514
516
 
515
517
  > **Note:** Stateless mode is only available with HTTP streaming transport. Features that depend on persistent sessions (like session-specific state) will not be available in stateless mode.
516
518
 
519
+ > **Legacy SSE:** the HTTP Stream transport also answers the legacy SSE endpoints (`GET /sse` and `POST /messages`) by default. Set `httpStream.sseEndpoint` to another path to move `GET /sse` (the path is not prefixed with `basePath`, and `POST /messages` stays where it is), or to `null` to turn both off — in stateless deployments a long-lived SSE session contradicts the stateless contract.
520
+
517
521
  You can also enable stateless mode using CLI arguments or environment variables:
518
522
 
519
523
  ```bash
@@ -752,6 +756,10 @@ server.addTool({
752
756
  });
753
757
  ```
754
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
+
755
763
  A server without an `authenticate` function has no auth to check, so every
756
764
  session sees every tool. With one, a session that still ends up without auth —
757
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 _chunkVWHJYU4Vcjs = require('./chunk-VWHJYU4V.cjs');
14
+ var _chunkMT5SJOZ5cjs = require('./chunk-MT5SJOZ5.cjs');
15
15
 
16
16
 
17
17
 
@@ -24,7 +24,7 @@ var _chunkVWHJYU4Vcjs = require('./chunk-VWHJYU4V.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 = _chunkVWHJYU4Vcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkVWHJYU4Vcjs.FastMCP; exports.FastMCPError = _chunkVWHJYU4Vcjs.FastMCPError; exports.FastMCPSession = _chunkVWHJYU4Vcjs.FastMCPSession; exports.GitHubProvider = _chunkAKHG27NYcjs.GitHubProvider; exports.GoogleProvider = _chunkAKHG27NYcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkVWHJYU4Vcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkAKHG27NYcjs.OAuthProvider; exports.ServerState = _chunkVWHJYU4Vcjs.ServerState; exports.SessionError = _chunkVWHJYU4Vcjs.SessionError; exports.UnexpectedStateError = _chunkVWHJYU4Vcjs.UnexpectedStateError; exports.UserError = _chunkVWHJYU4Vcjs.UserError; exports.audioContent = _chunkVWHJYU4Vcjs.audioContent; exports.getAuthSession = _chunkAKHG27NYcjs.getAuthSession; exports.imageContent = _chunkVWHJYU4Vcjs.imageContent; exports.jsonSchemaAdapter = _chunkVWHJYU4Vcjs.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 {
@@ -1182,6 +1182,7 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
1182
1182
  eventStore?: EventStore;
1183
1183
  host?: string;
1184
1184
  port: number;
1185
+ sseEndpoint?: `/${string}` | null;
1185
1186
  sslCa?: string;
1186
1187
  sslCert?: string;
1187
1188
  sslKey?: string;
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 {
@@ -1182,6 +1182,7 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
1182
1182
  eventStore?: EventStore;
1183
1183
  host?: string;
1184
1184
  port: number;
1185
+ sseEndpoint?: `/${string}` | null;
1185
1186
  sslCa?: string;
1186
1187
  sslCert?: string;
1187
1188
  sslKey?: string;
package/dist/FastMCP.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  audioContent,
12
12
  imageContent,
13
13
  jsonSchemaAdapter
14
- } from "./chunk-SQSE766U.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;
@@ -2585,6 +2627,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2585
2627
  );
2586
2628
  },
2587
2629
  port: httpConfig.port,
2630
+ sseEndpoint: httpConfig.sseEndpoint,
2588
2631
  sslCa: httpConfig.sslCa,
2589
2632
  sslCert: httpConfig.sslCert,
2590
2633
  sslKey: httpConfig.sslKey,
@@ -2639,6 +2682,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2639
2682
  );
2640
2683
  },
2641
2684
  port: httpConfig.port,
2685
+ sseEndpoint: httpConfig.sseEndpoint,
2642
2686
  sslCa: httpConfig.sslCa,
2643
2687
  sslCert: httpConfig.sslCert,
2644
2688
  sslKey: httpConfig.sslKey,
@@ -3052,15 +3096,13 @@ var FastMCP = class extends FastMCPEventEmitter {
3052
3096
  try {
3053
3097
  const params = Object.fromEntries(url2.searchParams.entries());
3054
3098
  const response = await oauthProxy.authorize(
3055
- 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
+ })
3056
3104
  );
3057
- const location = response.headers.get("Location");
3058
- if (location) {
3059
- res.writeHead(response.status, { Location: location }).end();
3060
- } else {
3061
- const html = await response.text();
3062
- res.writeHead(response.status, { "Content-Type": "text/html" }).end(html);
3063
- }
3105
+ await sendOAuthProxyResponse(res, response);
3064
3106
  } catch (error) {
3065
3107
  res.writeHead(400, { "Content-Type": "application/json" }).end(
3066
3108
  JSON.stringify(
@@ -3074,15 +3116,11 @@ var FastMCP = class extends FastMCPEventEmitter {
3074
3116
  }
3075
3117
  if (req.method === "GET" && oauthPath === "/oauth/callback") {
3076
3118
  try {
3077
- const mockRequest = new Request(`http://${host}${req.url}`);
3119
+ const mockRequest = new Request(`http://${host}${req.url}`, {
3120
+ headers: cookieHeaders(req)
3121
+ });
3078
3122
  const response = await oauthProxy.handleCallback(mockRequest);
3079
- const location = response.headers.get("Location");
3080
- if (location) {
3081
- res.writeHead(response.status, { Location: location }).end();
3082
- } else {
3083
- const text = await response.text();
3084
- res.writeHead(response.status).end(text);
3085
- }
3123
+ await sendOAuthProxyResponse(res, response);
3086
3124
  } catch (error) {
3087
3125
  res.writeHead(400, { "Content-Type": "application/json" }).end(
3088
3126
  JSON.stringify(
@@ -3139,19 +3177,14 @@ var FastMCP = class extends FastMCPEventEmitter {
3139
3177
  {
3140
3178
  body: Buffer.concat(bodyChunks).toString("utf8"),
3141
3179
  headers: {
3180
+ ...cookieHeaders(req),
3142
3181
  "Content-Type": "application/x-www-form-urlencoded"
3143
3182
  },
3144
3183
  method: "POST"
3145
3184
  }
3146
3185
  );
3147
3186
  const response = await oauthProxy.handleConsent(mockRequest);
3148
- const location = response.headers.get("Location");
3149
- if (location) {
3150
- res.writeHead(response.status, { Location: location }).end();
3151
- } else {
3152
- const text = await response.text();
3153
- res.writeHead(response.status).end(text);
3154
- }
3187
+ await sendOAuthProxyResponse(res, response);
3155
3188
  } catch (error) {
3156
3189
  res.writeHead(400, { "Content-Type": "application/json" }).end(
3157
3190
  JSON.stringify(
@@ -3421,6 +3454,7 @@ var FastMCP = class extends FastMCPEventEmitter {
3421
3454
  (statelessArg === "" ? true : parseBooleanSetting(statelessArg, "--stateless")) ?? parseBooleanSetting(envStateless, "FASTMCP_STATELESS") ?? false;
3422
3455
  const cors = overrides?.httpStream?.cors;
3423
3456
  const eventStore = overrides?.httpStream?.eventStore;
3457
+ const sseEndpoint = overrides?.httpStream?.sseEndpoint;
3424
3458
  const sslCa = overrides?.httpStream?.sslCa;
3425
3459
  const sslCert = overrides?.httpStream?.sslCert;
3426
3460
  const sslKey = overrides?.httpStream?.sslKey;
@@ -3433,6 +3467,7 @@ var FastMCP = class extends FastMCPEventEmitter {
3433
3467
  eventStore,
3434
3468
  host,
3435
3469
  port,
3470
+ sseEndpoint,
3436
3471
  sslCa,
3437
3472
  sslCert,
3438
3473
  sslKey,
@@ -3543,4 +3578,4 @@ export {
3543
3578
  FastMCPSession,
3544
3579
  FastMCP
3545
3580
  };
3546
- //# sourceMappingURL=chunk-SQSE766U.js.map
3581
+ //# sourceMappingURL=chunk-GUHJKVLX.js.map