fastmcp 4.26.1 → 4.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -226,7 +226,11 @@ See the [https-server example](src/examples/https-server.ts) for a complete demo
226
226
 
227
227
  ##### CORS Configuration
228
228
 
229
- By default, FastMCP enables CORS with a standard set of allowed headers. You can customize the CORS behavior by passing a `cors` option:
229
+ By default, FastMCP enables CORS with a standard set of allowed headers.
230
+
231
+ A server bound to a loopback address, which is the default (`localhost`), answers browser requests from loopback origins only, such as `http://localhost:6274`. A page served from any other origin cannot open a session or send a message: those requests are refused with a 403. A local server is out of the network's reach but not out of a browser's: without this, any web page you visit could call its tools. Requests without an `Origin` header, which is every client that is not a web page, are not affected, and a server bound to another address answers every origin.
232
+
233
+ To answer pages served from elsewhere, name their origins in `cors.origin`. That list replaces the loopback default, so include a local page's origin too if you use one. Credentials (`credentials: true`) are only granted to origins named there.
230
234
 
231
235
  ```ts
232
236
  server.start({
@@ -234,7 +238,7 @@ server.start({
234
238
  httpStream: {
235
239
  port: 8080,
236
240
  cors: {
237
- origin: "http://localhost:3000",
241
+ origin: ["https://app.example.com", "http://localhost:6274"],
238
242
  allowedHeaders: [
239
243
  "Content-Type",
240
244
  "Authorization",
@@ -252,10 +256,10 @@ server.start({
252
256
 
253
257
  The `cors` option accepts:
254
258
 
255
- - `true` (default) - enable CORS with default settings
259
+ - `true` - enable CORS for every origin
256
260
  - `false` - disable CORS entirely
257
261
  - An object with these fields:
258
- - `origin` - a string, array of strings, or a function `(origin: string) => boolean`
262
+ - `origin` - a string, array of strings, or a function `(origin: string) => boolean`. On a server bound to loopback these are the origins it answers, and `"*"` answers all of them. An extension's or app's origin, such as `chrome-extension://…`, can be named as it is
259
263
  - `allowedHeaders` - a string or array of strings
260
264
  - `methods` - array of allowed HTTP methods
261
265
  - `exposedHeaders` - array of headers to expose
package/dist/FastMCP.cjs CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkMT5SJOZ5cjs = require('./chunk-MT5SJOZ5.cjs');
14
+ var _chunkUULT6NOScjs = require('./chunk-UULT6NOS.cjs');
15
15
 
16
16
 
17
17
 
@@ -24,7 +24,7 @@ var _chunkMT5SJOZ5cjs = require('./chunk-MT5SJOZ5.cjs');
24
24
 
25
25
 
26
26
 
27
- var _chunkUNS6EZVPcjs = require('./chunk-UNS6EZVP.cjs');
27
+ var _chunkHVKGDRTLcjs = require('./chunk-HVKGDRTL.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 = _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;
53
+ exports.AuthProvider = _chunkHVKGDRTLcjs.AuthProvider; exports.AzureProvider = _chunkHVKGDRTLcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkUULT6NOScjs.DiscoveryDocumentCache; exports.FastMCP = _chunkUULT6NOScjs.FastMCP; exports.FastMCPError = _chunkUULT6NOScjs.FastMCPError; exports.FastMCPSession = _chunkUULT6NOScjs.FastMCPSession; exports.GitHubProvider = _chunkHVKGDRTLcjs.GitHubProvider; exports.GoogleProvider = _chunkHVKGDRTLcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkUULT6NOScjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkHVKGDRTLcjs.OAuthProvider; exports.ServerState = _chunkUULT6NOScjs.ServerState; exports.SessionError = _chunkUULT6NOScjs.SessionError; exports.UnexpectedStateError = _chunkUULT6NOScjs.UnexpectedStateError; exports.UserError = _chunkUULT6NOScjs.UserError; exports.audioContent = _chunkUULT6NOScjs.audioContent; exports.getAuthSession = _chunkHVKGDRTLcjs.getAuthSession; exports.imageContent = _chunkUULT6NOScjs.imageContent; exports.jsonSchemaAdapter = _chunkUULT6NOScjs.jsonSchemaAdapter; exports.requireAll = _chunkHVKGDRTLcjs.requireAll; exports.requireAny = _chunkHVKGDRTLcjs.requireAny; exports.requireAuth = _chunkHVKGDRTLcjs.requireAuth; exports.requireRole = _chunkHVKGDRTLcjs.requireRole; exports.requireScopes = _chunkHVKGDRTLcjs.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-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';
15
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-B7VDZGyx.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-B7VDZGyx.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-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';
15
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-B7VDZGyx.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-B7VDZGyx.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-GUHJKVLX.js";
14
+ } from "./chunk-ASOZUCE2.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-KYUSH4TQ.js";
27
+ } from "./chunk-W6P57SNV.js";
28
28
  import "./chunk-OKKFL2M4.js";
29
29
  export {
30
30
  AuthProvider,
@@ -197,7 +197,14 @@ interface OAuthProxyConfig {
197
197
  *
198
198
  * A client calling POST /oauth/register must present a `redirect_uri` that
199
199
  * matches one of these patterns (exact string or glob with `*` / `?`);
200
- * otherwise the registration is rejected with `invalid_redirect_uri`. Once
200
+ * otherwise the registration is rejected with `invalid_redirect_uri`. The
201
+ * host the URI leads to must match the pattern's host as well, so a
202
+ * wildcard in the host, as in `https://*.example.com/*`, stands for part of
203
+ * a host name rather than for a path on some other host, and one that ends
204
+ * a host name does not reach into a longer one. A `?` in the host may also
205
+ * be read as the start of the query, as in a URL. The patterns are checked
206
+ * again at /oauth/authorize, so a registration they no longer allow cannot
207
+ * be used. Once
201
208
  * registered, the same exact URI must be echoed back at /oauth/authorize —
202
209
  * the proxy performs an exact per-client match per RFC 6749 §3.1.2.3.
203
210
  *
@@ -738,7 +745,19 @@ declare class OAuthProxy {
738
745
  */
739
746
  private isTransactionCallbackRegistered;
740
747
  /**
741
- * Match URI against pattern (supports wildcards)
748
+ * Whether a redirect URI matches a pattern.
749
+ *
750
+ * The pattern is a glob over the URI as it is written, and the host the URI
751
+ * really leads to must match the pattern's host as well: `*` runs past the
752
+ * end of a host, so the text of `https://*.example.com/*` could otherwise be
753
+ * found in the path of a URI on any host at all. The URI's host is the one
754
+ * a browser goes to, which a backslash or a tab can make other than it is
755
+ * written. The pattern's runs from after `://` to the first `/` or `#`.
756
+ *
757
+ * A `?` there may stand for a character, as in `localhost:30??`, or start
758
+ * the query, as in `https://app.example.com?source=*`, where the host ends.
759
+ * A URI may match the pattern read any of these ways, if its host matches
760
+ * the host that reading gives.
742
761
  */
743
762
  private matchesPattern;
744
763
  /**
@@ -197,7 +197,14 @@ interface OAuthProxyConfig {
197
197
  *
198
198
  * A client calling POST /oauth/register must present a `redirect_uri` that
199
199
  * matches one of these patterns (exact string or glob with `*` / `?`);
200
- * otherwise the registration is rejected with `invalid_redirect_uri`. Once
200
+ * otherwise the registration is rejected with `invalid_redirect_uri`. The
201
+ * host the URI leads to must match the pattern's host as well, so a
202
+ * wildcard in the host, as in `https://*.example.com/*`, stands for part of
203
+ * a host name rather than for a path on some other host, and one that ends
204
+ * a host name does not reach into a longer one. A `?` in the host may also
205
+ * be read as the start of the query, as in a URL. The patterns are checked
206
+ * again at /oauth/authorize, so a registration they no longer allow cannot
207
+ * be used. Once
201
208
  * registered, the same exact URI must be echoed back at /oauth/authorize —
202
209
  * the proxy performs an exact per-client match per RFC 6749 §3.1.2.3.
203
210
  *
@@ -738,7 +745,19 @@ declare class OAuthProxy {
738
745
  */
739
746
  private isTransactionCallbackRegistered;
740
747
  /**
741
- * Match URI against pattern (supports wildcards)
748
+ * Whether a redirect URI matches a pattern.
749
+ *
750
+ * The pattern is a glob over the URI as it is written, and the host the URI
751
+ * really leads to must match the pattern's host as well: `*` runs past the
752
+ * end of a host, so the text of `https://*.example.com/*` could otherwise be
753
+ * found in the path of a URI on any host at all. The URI's host is the one
754
+ * a browser goes to, which a backslash or a tab can make other than it is
755
+ * written. The pattern's runs from after `://` to the first `/` or `#`.
756
+ *
757
+ * A `?` there may stand for a character, as in `localhost:30??`, or start
758
+ * the query, as in `https://app.example.com?source=*`, where the host ends.
759
+ * A URI may match the pattern read any of these ways, if its host matches
760
+ * the host that reading gives.
742
761
  */
743
762
  private matchesPattern;
744
763
  /**
@@ -25,7 +25,7 @@
25
25
 
26
26
 
27
27
 
28
- var _chunkUNS6EZVPcjs = require('../chunk-UNS6EZVP.cjs');
28
+ var _chunkHVKGDRTLcjs = require('../chunk-HVKGDRTL.cjs');
29
29
 
30
30
 
31
31
 
@@ -53,5 +53,5 @@ var _chunkUNS6EZVPcjs = require('../chunk-UNS6EZVP.cjs');
53
53
 
54
54
 
55
55
 
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;
56
+ exports.AuthProvider = _chunkHVKGDRTLcjs.AuthProvider; exports.AzureProvider = _chunkHVKGDRTLcjs.AzureProvider; exports.ConsentManager = _chunkHVKGDRTLcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkHVKGDRTLcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkHVKGDRTLcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkHVKGDRTLcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkHVKGDRTLcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkHVKGDRTLcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkHVKGDRTLcjs.DiskStore; exports.EncryptedTokenStorage = _chunkHVKGDRTLcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkHVKGDRTLcjs.GitHubProvider; exports.GoogleProvider = _chunkHVKGDRTLcjs.GoogleProvider; exports.JWKSVerifier = _chunkHVKGDRTLcjs.JWKSVerifier; exports.JWTIssuer = _chunkHVKGDRTLcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkHVKGDRTLcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkHVKGDRTLcjs.OAuthProvider; exports.OAuthProxy = _chunkHVKGDRTLcjs.OAuthProxy; exports.OAuthProxyError = _chunkHVKGDRTLcjs.OAuthProxyError; exports.PKCEUtils = _chunkHVKGDRTLcjs.PKCEUtils; exports.TOKEN_ENDPOINT_AUTH_METHODS = _chunkHVKGDRTLcjs.TOKEN_ENDPOINT_AUTH_METHODS; exports.getAuthSession = _chunkHVKGDRTLcjs.getAuthSession; exports.requireAll = _chunkHVKGDRTLcjs.requireAll; exports.requireAny = _chunkHVKGDRTLcjs.requireAny; exports.requireAuth = _chunkHVKGDRTLcjs.requireAuth; exports.requireRole = _chunkHVKGDRTLcjs.requireRole; exports.requireScopes = _chunkHVKGDRTLcjs.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-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';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-B7VDZGyx.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-B7VDZGyx.cjs';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -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-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';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-B7VDZGyx.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-B7VDZGyx.js';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -25,7 +25,7 @@ import {
25
25
  requireAuth,
26
26
  requireRole,
27
27
  requireScopes
28
- } from "../chunk-KYUSH4TQ.js";
28
+ } from "../chunk-W6P57SNV.js";
29
29
  export {
30
30
  AuthProvider,
31
31
  AzureProvider,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cancelResponseBody
3
- } from "./chunk-KYUSH4TQ.js";
3
+ } from "./chunk-W6P57SNV.js";
4
4
  import {
5
5
  objectRootSchema,
6
6
  strictInputSchema,
@@ -1942,6 +1942,28 @@ function convertObjectToSnakeCase(obj) {
1942
1942
  function cookieHeaders(req) {
1943
1943
  return req.headers.cookie ? { cookie: req.headers.cookie } : {};
1944
1944
  }
1945
+ function isLoopbackHost(host) {
1946
+ let name;
1947
+ try {
1948
+ name = new URL(
1949
+ `http://${host.includes(":") && !host.startsWith("[") ? `[${host}]` : host}`
1950
+ ).hostname;
1951
+ } catch {
1952
+ return false;
1953
+ }
1954
+ return isLoopbackHostname(name.replace(/\.$/, ""));
1955
+ }
1956
+ function isLoopbackHostname(name) {
1957
+ return name === "localhost" || name.endsWith(".localhost") || /^127\.\d+\.\d+\.\d+$/.test(name) || name === "[::1]" || // `::ffff:127.0.0.1`, an IPv4 loopback address written for IPv6.
1958
+ /^\[::ffff:7f[\da-f]{2}:[\da-f]{1,4}\]$/.test(name);
1959
+ }
1960
+ function isLoopbackOrigin(origin) {
1961
+ try {
1962
+ return isLoopbackHostname(new URL(origin).hostname);
1963
+ } catch {
1964
+ return false;
1965
+ }
1966
+ }
1945
1967
  function isStreamableHttpTransport(transport) {
1946
1968
  return "handleRequest" in transport && typeof transport.handleRequest === "function";
1947
1969
  }
@@ -2066,6 +2088,38 @@ function grantedScopes(auth) {
2066
2088
  const values = Array.isArray(scopes) ? scopes : scopes instanceof Set ? [...scopes] : [];
2067
2089
  return values.filter((scope) => typeof scope === "string");
2068
2090
  }
2091
+ function printable(text) {
2092
+ return text.replace(
2093
+ /[^\x20-\x7e]/g,
2094
+ (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`
2095
+ );
2096
+ }
2097
+ function resolveOriginPolicy(host, cors) {
2098
+ if (!isLoopbackHost(host) || cors === true) {
2099
+ return { cors };
2100
+ }
2101
+ if (typeof cors === "object" && cors.origin) {
2102
+ const { origin } = cors;
2103
+ if (origin === "*") {
2104
+ return { cors };
2105
+ }
2106
+ return {
2107
+ allows: typeof origin === "function" ? origin : (candidate) => (Array.isArray(origin) ? origin : [origin]).includes(candidate),
2108
+ cors,
2109
+ refusal: "It is not one of the origins httpStream.cors.origin allows."
2110
+ };
2111
+ }
2112
+ return {
2113
+ allows: isLoopbackOrigin,
2114
+ cors: cors === false ? false : (
2115
+ // No credentials either: as with every origin, they take one named
2116
+ // in `cors.origin`. A page on another local port is same-site, so
2117
+ // its requests would carry this server's cookies.
2118
+ { ...cors, credentials: void 0, origin: isLoopbackOrigin }
2119
+ ),
2120
+ refusal: "A server bound to a loopback address answers pages served from loopback only; name the origins to answer in httpStream.cors.origin."
2121
+ };
2122
+ }
2069
2123
  async function sendOAuthProxyResponse(res, response) {
2070
2124
  const body = await response.text();
2071
2125
  const headers = {};
@@ -2080,6 +2134,14 @@ async function sendOAuthProxyResponse(res, response) {
2080
2134
  }
2081
2135
  res.writeHead(response.status, headers).end(body);
2082
2136
  }
2137
+ function serializeOrigin(header) {
2138
+ try {
2139
+ const { origin } = new URL(header);
2140
+ return origin === "null" ? header.trim() : origin;
2141
+ } catch {
2142
+ return header.trim();
2143
+ }
2144
+ }
2083
2145
  function stripBasePath(path, basePath) {
2084
2146
  if (!basePath) {
2085
2147
  return path;
@@ -2158,6 +2220,11 @@ var FastMCP = class extends FastMCPEventEmitter {
2158
2220
  #prompts = [];
2159
2221
  /** The auth provider's base URL, when it supplied the OAuth config. */
2160
2222
  #providerResourceBase;
2223
+ /**
2224
+ * Origins already reported as refused, so that a page retrying does not
2225
+ * fill the log. Capped, since the origin is whatever the request says.
2226
+ */
2227
+ #refusedOrigins = /* @__PURE__ */ new Set();
2161
2228
  #resources = [];
2162
2229
  #resourcesTemplates = [];
2163
2230
  #serverState = "stopped" /* Stopped */;
@@ -2582,6 +2649,10 @@ var FastMCP = class extends FastMCPEventEmitter {
2582
2649
  httpConfig.endpoint
2583
2650
  );
2584
2651
  this.#useEndpointAsResource(httpConfig.endpoint);
2652
+ const originPolicy = resolveOriginPolicy(
2653
+ httpConfig.host,
2654
+ httpConfig.cors
2655
+ );
2585
2656
  if (httpConfig.stateless) {
2586
2657
  this.#logger.info(
2587
2658
  `[FastMCP info] Starting server in stateless mode on HTTP Stream at ${protocol}://${httpConfig.host}:${httpConfig.port}${streamEndpoint}`
@@ -2589,9 +2660,13 @@ var FastMCP = class extends FastMCPEventEmitter {
2589
2660
  const authenticate = this.#authenticate ? this.#memoizedAuthenticate() : void 0;
2590
2661
  this.#httpStreamServer = await startHTTPServer({
2591
2662
  ...authenticate ? { authenticate } : {},
2592
- beforeDispatch: ({ message, server }) => this.#answerScopeChallenge(message, server),
2593
- cors: httpConfig.cors,
2663
+ beforeDispatch: ({ message, request, server }) => this.#originRefusal(request, originPolicy) ?? this.#answerScopeChallenge(message, server),
2664
+ cors: originPolicy.cors,
2594
2665
  createServer: async (request) => {
2666
+ const refusal = this.#originRefusal(request, originPolicy);
2667
+ if (refusal) {
2668
+ throw refusal;
2669
+ }
2595
2670
  let auth;
2596
2671
  if (authenticate) {
2597
2672
  auth = this.#requireAuthenticated(await authenticate(request));
@@ -2638,9 +2713,13 @@ var FastMCP = class extends FastMCPEventEmitter {
2638
2713
  const authenticate = this.#authenticate ? this.#memoizedAuthenticate() : void 0;
2639
2714
  this.#httpStreamServer = await startHTTPServer({
2640
2715
  ...authenticate ? { authenticate } : {},
2641
- beforeDispatch: ({ message, server }) => this.#answerScopeChallenge(message, server),
2642
- cors: httpConfig.cors,
2716
+ beforeDispatch: ({ message, request, server }) => this.#originRefusal(request, originPolicy) ?? this.#answerScopeChallenge(message, server),
2717
+ cors: originPolicy.cors,
2643
2718
  createServer: async (request) => {
2719
+ const refusal = this.#originRefusal(request, originPolicy);
2720
+ if (refusal) {
2721
+ throw refusal;
2722
+ }
2644
2723
  let auth;
2645
2724
  if (authenticate) {
2646
2725
  auth = this.#requireAuthenticated(await authenticate(request));
@@ -3412,6 +3491,40 @@ var FastMCP = class extends FastMCPEventEmitter {
3412
3491
  });
3413
3492
  }
3414
3493
  }
3494
+ /**
3495
+ * The 403 MCP asks for, for a request a browser sent on behalf of a page
3496
+ * the server does not answer (see `resolveOriginPolicy`). Checked before a
3497
+ * session is created, and for every message posted to one that exists. A
3498
+ * request without an `Origin` header does not come from a page, and passes.
3499
+ */
3500
+ #originRefusal(request, policy) {
3501
+ const header = request.headers.origin;
3502
+ if (!policy.allows || !header) {
3503
+ return void 0;
3504
+ }
3505
+ const origin = serializeOrigin(header);
3506
+ if (policy.allows(origin)) {
3507
+ return void 0;
3508
+ }
3509
+ const refused = printable(origin.slice(0, 200));
3510
+ if (!this.#refusedOrigins.has(refused) && this.#refusedOrigins.size < 50) {
3511
+ this.#refusedOrigins.add(refused);
3512
+ this.#logger.warn(
3513
+ `[FastMCP warning] Refused a request from the origin ${refused}. ${policy.refusal}`
3514
+ );
3515
+ }
3516
+ return new Response(
3517
+ JSON.stringify({
3518
+ error: {
3519
+ code: -32e3,
3520
+ message: `Forbidden: the origin ${refused} is not allowed`
3521
+ },
3522
+ id: null,
3523
+ jsonrpc: "2.0"
3524
+ }),
3525
+ { headers: { "Content-Type": "application/json" }, status: 403 }
3526
+ );
3527
+ }
3415
3528
  #parseRuntimeConfig(overrides) {
3416
3529
  const args = process.argv.slice(2);
3417
3530
  const getArg = (name) => {
@@ -3578,4 +3691,4 @@ export {
3578
3691
  FastMCPSession,
3579
3692
  FastMCP
3580
3693
  };
3581
- //# sourceMappingURL=chunk-GUHJKVLX.js.map
3694
+ //# sourceMappingURL=chunk-ASOZUCE2.js.map