fastmcp 4.20.0 → 4.20.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/dist/FastMCP.cjs CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkKGXPEC7Jcjs = require('./chunk-KGXPEC7J.cjs');
14
+ var _chunkFFBZHCBQcjs = require('./chunk-FFBZHCBQ.cjs');
15
15
 
16
16
 
17
17
 
@@ -49,5 +49,5 @@ var _chunkYO76IUZ6cjs = require('./chunk-YO76IUZ6.cjs');
49
49
 
50
50
 
51
51
 
52
- exports.AuthProvider = _chunkYO76IUZ6cjs.AuthProvider; exports.AzureProvider = _chunkYO76IUZ6cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkKGXPEC7Jcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkKGXPEC7Jcjs.FastMCP; exports.FastMCPError = _chunkKGXPEC7Jcjs.FastMCPError; exports.FastMCPSession = _chunkKGXPEC7Jcjs.FastMCPSession; exports.GitHubProvider = _chunkYO76IUZ6cjs.GitHubProvider; exports.GoogleProvider = _chunkYO76IUZ6cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkKGXPEC7Jcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkYO76IUZ6cjs.OAuthProvider; exports.ServerState = _chunkKGXPEC7Jcjs.ServerState; exports.SessionError = _chunkKGXPEC7Jcjs.SessionError; exports.UnexpectedStateError = _chunkKGXPEC7Jcjs.UnexpectedStateError; exports.UserError = _chunkKGXPEC7Jcjs.UserError; exports.audioContent = _chunkKGXPEC7Jcjs.audioContent; exports.getAuthSession = _chunkYO76IUZ6cjs.getAuthSession; exports.imageContent = _chunkKGXPEC7Jcjs.imageContent; exports.jsonSchemaAdapter = _chunkKGXPEC7Jcjs.jsonSchemaAdapter; exports.requireAll = _chunkYO76IUZ6cjs.requireAll; exports.requireAny = _chunkYO76IUZ6cjs.requireAny; exports.requireAuth = _chunkYO76IUZ6cjs.requireAuth; exports.requireRole = _chunkYO76IUZ6cjs.requireRole; exports.requireScopes = _chunkYO76IUZ6cjs.requireScopes;
52
+ exports.AuthProvider = _chunkYO76IUZ6cjs.AuthProvider; exports.AzureProvider = _chunkYO76IUZ6cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkFFBZHCBQcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkFFBZHCBQcjs.FastMCP; exports.FastMCPError = _chunkFFBZHCBQcjs.FastMCPError; exports.FastMCPSession = _chunkFFBZHCBQcjs.FastMCPSession; exports.GitHubProvider = _chunkYO76IUZ6cjs.GitHubProvider; exports.GoogleProvider = _chunkYO76IUZ6cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkFFBZHCBQcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkYO76IUZ6cjs.OAuthProvider; exports.ServerState = _chunkFFBZHCBQcjs.ServerState; exports.SessionError = _chunkFFBZHCBQcjs.SessionError; exports.UnexpectedStateError = _chunkFFBZHCBQcjs.UnexpectedStateError; exports.UserError = _chunkFFBZHCBQcjs.UserError; exports.audioContent = _chunkFFBZHCBQcjs.audioContent; exports.getAuthSession = _chunkYO76IUZ6cjs.getAuthSession; exports.imageContent = _chunkFFBZHCBQcjs.imageContent; exports.jsonSchemaAdapter = _chunkFFBZHCBQcjs.jsonSchemaAdapter; exports.requireAll = _chunkYO76IUZ6cjs.requireAll; exports.requireAny = _chunkYO76IUZ6cjs.requireAny; exports.requireAuth = _chunkYO76IUZ6cjs.requireAuth; exports.requireRole = _chunkYO76IUZ6cjs.requireRole; exports.requireScopes = _chunkYO76IUZ6cjs.requireScopes;
53
53
  //# sourceMappingURL=FastMCP.cjs.map
package/dist/FastMCP.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  audioContent,
12
12
  imageContent,
13
13
  jsonSchemaAdapter
14
- } from "./chunk-XJWV6G5Q.js";
14
+ } from "./chunk-LMDKR42T.js";
15
15
  import {
16
16
  AuthProvider,
17
17
  AzureProvider,
@@ -2097,13 +2097,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2097
2097
  enableJsonResponse: httpConfig.enableJsonResponse,
2098
2098
  eventStore: httpConfig.eventStore,
2099
2099
  host: httpConfig.host,
2100
- ..._optionalChain([this, 'access', _46 => _46.#options, 'access', _47 => _47.oauth, 'optionalAccess', _48 => _48.enabled]) && _optionalChain([this, 'access', _49 => _49.#options, 'access', _50 => _50.oauth, 'access', _51 => _51.protectedResource, 'optionalAccess', _52 => _52.resource]) ? {
2101
- oauth: {
2102
- protectedResource: {
2103
- resource: this.#options.oauth.protectedResource.resource
2104
- }
2105
- }
2106
- } : {},
2100
+ ...this.#httpStreamOAuthConfig(),
2107
2101
  // In stateless mode, we don't track sessions
2108
2102
  onClose: async () => {
2109
2103
  },
@@ -2145,13 +2139,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2145
2139
  enableJsonResponse: httpConfig.enableJsonResponse,
2146
2140
  eventStore: httpConfig.eventStore,
2147
2141
  host: httpConfig.host,
2148
- ..._optionalChain([this, 'access', _53 => _53.#options, 'access', _54 => _54.oauth, 'optionalAccess', _55 => _55.enabled]) && _optionalChain([this, 'access', _56 => _56.#options, 'access', _57 => _57.oauth, 'access', _58 => _58.protectedResource, 'optionalAccess', _59 => _59.resource]) ? {
2149
- oauth: {
2150
- protectedResource: {
2151
- resource: this.#options.oauth.protectedResource.resource
2152
- }
2153
- }
2154
- } : {},
2142
+ ...this.#httpStreamOAuthConfig(),
2155
2143
  onClose: async (session) => {
2156
2144
  const sessionIndex = this.#sessions.indexOf(session);
2157
2145
  if (sessionIndex !== -1) this.#sessions.splice(sessionIndex, 1);
@@ -2251,7 +2239,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2251
2239
  */
2252
2240
  #createUnauthorizedResponse(message) {
2253
2241
  const oauth = this.#options.oauth;
2254
- const resource = _optionalChain([oauth, 'optionalAccess', _60 => _60.enabled]) ? _optionalChain([oauth, 'access', _61 => _61.protectedResource, 'optionalAccess', _62 => _62.resource]) : void 0;
2242
+ const resource = _optionalChain([oauth, 'optionalAccess', _46 => _46.enabled]) ? _optionalChain([oauth, 'access', _47 => _47.protectedResource, 'optionalAccess', _48 => _48.resource]) : void 0;
2255
2243
  const wwwAuthenticateParts = [
2256
2244
  'error="invalid_token"',
2257
2245
  `error_description="${message.replace(/"/g, '\\"')}"`
@@ -2377,7 +2365,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2377
2365
  }
2378
2366
  }
2379
2367
  const oauthConfig = this.#options.oauth;
2380
- if (_optionalChain([oauthConfig, 'optionalAccess', _63 => _63.enabled]) && req.method === "GET") {
2368
+ if (_optionalChain([oauthConfig, 'optionalAccess', _49 => _49.enabled]) && req.method === "GET") {
2381
2369
  const url2 = new URL(req.url || "", `http://${host}`);
2382
2370
  const authorizationServerMetadataPath = joinPaths(
2383
2371
  "",
@@ -2411,8 +2399,8 @@ var FastMCP = class extends FastMCPEventEmitter {
2411
2399
  }
2412
2400
  }
2413
2401
  }
2414
- const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _64 => _64.proxy]);
2415
- if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _65 => _65.enabled])) {
2402
+ const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _50 => _50.proxy]);
2403
+ if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _51 => _51.enabled])) {
2416
2404
  const url2 = new URL(req.url || "", `http://${host}`);
2417
2405
  const oauthPath = basePathRelativePath;
2418
2406
  try {
@@ -2465,7 +2453,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2465
2453
  const statusCode = error.statusCode || 400;
2466
2454
  res.writeHead(statusCode, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(
2467
2455
  JSON.stringify(
2468
- _optionalChain([error, 'access', _66 => _66.toJSON, 'optionalCall', _67 => _67()]) || {
2456
+ _optionalChain([error, 'access', _52 => _52.toJSON, 'optionalCall', _53 => _53()]) || {
2469
2457
  error: "invalid_request"
2470
2458
  }
2471
2459
  )
@@ -2492,7 +2480,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2492
2480
  } catch (error) {
2493
2481
  res.writeHead(400, { "Content-Type": "application/json" }).end(
2494
2482
  JSON.stringify(
2495
- _optionalChain([error, 'access', _68 => _68.toJSON, 'optionalCall', _69 => _69()]) || {
2483
+ _optionalChain([error, 'access', _54 => _54.toJSON, 'optionalCall', _55 => _55()]) || {
2496
2484
  error: "invalid_request"
2497
2485
  }
2498
2486
  )
@@ -2514,7 +2502,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2514
2502
  } catch (error) {
2515
2503
  res.writeHead(400, { "Content-Type": "application/json" }).end(
2516
2504
  JSON.stringify(
2517
- _optionalChain([error, 'access', _70 => _70.toJSON, 'optionalCall', _71 => _71()]) || {
2505
+ _optionalChain([error, 'access', _56 => _56.toJSON, 'optionalCall', _57 => _57()]) || {
2518
2506
  error: "server_error"
2519
2507
  }
2520
2508
  )
@@ -2583,7 +2571,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2583
2571
  } catch (error) {
2584
2572
  res.writeHead(400, { "Content-Type": "application/json" }).end(
2585
2573
  JSON.stringify(
2586
- _optionalChain([error, 'access', _72 => _72.toJSON, 'optionalCall', _73 => _73()]) || {
2574
+ _optionalChain([error, 'access', _58 => _58.toJSON, 'optionalCall', _59 => _59()]) || {
2587
2575
  error: "server_error"
2588
2576
  }
2589
2577
  )
@@ -2641,8 +2629,8 @@ var FastMCP = class extends FastMCPEventEmitter {
2641
2629
  const basicAuth = parseBasicAuthHeader(
2642
2630
  req.headers.authorization
2643
2631
  );
2644
- const clientId = _optionalChain([basicAuth, 'optionalAccess', _74 => _74.clientId]) || params.get("client_id") || "";
2645
- const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _75 => _75.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
2632
+ const clientId = _optionalChain([basicAuth, 'optionalAccess', _60 => _60.clientId]) || params.get("client_id") || "";
2633
+ const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _61 => _61.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
2646
2634
  let response;
2647
2635
  if (grantType === "authorization_code") {
2648
2636
  response = await oauthProxy.exchangeAuthorizationCode({
@@ -2672,7 +2660,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2672
2660
  const statusCode = error.statusCode || 400;
2673
2661
  res.writeHead(statusCode, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(
2674
2662
  JSON.stringify(
2675
- _optionalChain([error, 'access', _76 => _76.toJSON, 'optionalCall', _77 => _77()]) || {
2663
+ _optionalChain([error, 'access', _62 => _62.toJSON, 'optionalCall', _63 => _63()]) || {
2676
2664
  error: "invalid_request"
2677
2665
  }
2678
2666
  )
@@ -2690,6 +2678,26 @@ var FastMCP = class extends FastMCPEventEmitter {
2690
2678
  }
2691
2679
  }
2692
2680
  };
2681
+ /**
2682
+ * Only advertise `resource_metadata` when OAuth is enabled: the
2683
+ * `/.well-known/oauth-protected-resource` endpoint is served only under
2684
+ * `oauth.enabled`, so gating here avoids pointing clients at a URL that
2685
+ * would 404. mcp-proxy emits the `WWW-Authenticate` challenge on every 401
2686
+ * regardless (RFC 7235), so no config is needed just to get the header.
2687
+ */
2688
+ #httpStreamOAuthConfig() {
2689
+ const resource = _optionalChain([this, 'access', _64 => _64.#options, 'access', _65 => _65.oauth, 'optionalAccess', _66 => _66.enabled]) ? _optionalChain([this, 'access', _67 => _67.#options, 'access', _68 => _68.oauth, 'access', _69 => _69.protectedResource, 'optionalAccess', _70 => _70.resource]) : void 0;
2690
+ if (!resource) {
2691
+ return {};
2692
+ }
2693
+ return {
2694
+ oauth: {
2695
+ protectedResource: {
2696
+ resource
2697
+ }
2698
+ }
2699
+ };
2700
+ }
2693
2701
  /**
2694
2702
  * On `httpStream`, `authenticate` is handed to both mcp-proxy (which calls it
2695
2703
  * once per request to gate the 401) and this server's own `createServer`
@@ -2777,23 +2785,23 @@ var FastMCP = class extends FastMCPEventEmitter {
2777
2785
  const envBasePath = process.env.FASTMCP_BASE_PATH;
2778
2786
  const envStateless = process.env.FASTMCP_STATELESS;
2779
2787
  const envHost = process.env.FASTMCP_HOST;
2780
- const transportType = _optionalChain([overrides, 'optionalAccess', _78 => _78.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
2788
+ const transportType = _optionalChain([overrides, 'optionalAccess', _71 => _71.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
2781
2789
  if (transportType === "httpStream") {
2782
2790
  const port = parseInt(
2783
- _optionalChain([overrides, 'optionalAccess', _79 => _79.httpStream, 'optionalAccess', _80 => _80.port, 'optionalAccess', _81 => _81.toString, 'call', _82 => _82()]) || portArg || envPort || "8080"
2791
+ _optionalChain([overrides, 'optionalAccess', _72 => _72.httpStream, 'optionalAccess', _73 => _73.port, 'optionalAccess', _74 => _74.toString, 'call', _75 => _75()]) || portArg || envPort || "8080"
2784
2792
  );
2785
- const host = _optionalChain([overrides, 'optionalAccess', _83 => _83.httpStream, 'optionalAccess', _84 => _84.host]) || hostArg || envHost || "localhost";
2786
- const endpoint = _optionalChain([overrides, 'optionalAccess', _85 => _85.httpStream, 'optionalAccess', _86 => _86.endpoint]) || endpointArg || envEndpoint || "/mcp";
2793
+ const host = _optionalChain([overrides, 'optionalAccess', _76 => _76.httpStream, 'optionalAccess', _77 => _77.host]) || hostArg || envHost || "localhost";
2794
+ const endpoint = _optionalChain([overrides, 'optionalAccess', _78 => _78.httpStream, 'optionalAccess', _79 => _79.endpoint]) || endpointArg || envEndpoint || "/mcp";
2787
2795
  const basePath = normalizeBasePath(
2788
- _optionalChain([overrides, 'optionalAccess', _87 => _87.httpStream, 'optionalAccess', _88 => _88.basePath]) || basePathArg || envBasePath
2796
+ _optionalChain([overrides, 'optionalAccess', _80 => _80.httpStream, 'optionalAccess', _81 => _81.basePath]) || basePathArg || envBasePath
2789
2797
  );
2790
- const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _89 => _89.httpStream, 'optionalAccess', _90 => _90.enableJsonResponse]) || false;
2791
- const stateless = _optionalChain([overrides, 'optionalAccess', _91 => _91.httpStream, 'optionalAccess', _92 => _92.stateless]) || statelessArg === "true" || envStateless === "true" || false;
2792
- const cors = _optionalChain([overrides, 'optionalAccess', _93 => _93.httpStream, 'optionalAccess', _94 => _94.cors]);
2793
- const eventStore = _optionalChain([overrides, 'optionalAccess', _95 => _95.httpStream, 'optionalAccess', _96 => _96.eventStore]);
2794
- const sslCa = _optionalChain([overrides, 'optionalAccess', _97 => _97.httpStream, 'optionalAccess', _98 => _98.sslCa]);
2795
- const sslCert = _optionalChain([overrides, 'optionalAccess', _99 => _99.httpStream, 'optionalAccess', _100 => _100.sslCert]);
2796
- const sslKey = _optionalChain([overrides, 'optionalAccess', _101 => _101.httpStream, 'optionalAccess', _102 => _102.sslKey]);
2798
+ const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _82 => _82.httpStream, 'optionalAccess', _83 => _83.enableJsonResponse]) || false;
2799
+ const stateless = _optionalChain([overrides, 'optionalAccess', _84 => _84.httpStream, 'optionalAccess', _85 => _85.stateless]) || statelessArg === "true" || envStateless === "true" || false;
2800
+ const cors = _optionalChain([overrides, 'optionalAccess', _86 => _86.httpStream, 'optionalAccess', _87 => _87.cors]);
2801
+ const eventStore = _optionalChain([overrides, 'optionalAccess', _88 => _88.httpStream, 'optionalAccess', _89 => _89.eventStore]);
2802
+ const sslCa = _optionalChain([overrides, 'optionalAccess', _90 => _90.httpStream, 'optionalAccess', _91 => _91.sslCa]);
2803
+ const sslCert = _optionalChain([overrides, 'optionalAccess', _92 => _92.httpStream, 'optionalAccess', _93 => _93.sslCert]);
2804
+ const sslKey = _optionalChain([overrides, 'optionalAccess', _94 => _94.httpStream, 'optionalAccess', _95 => _95.sslKey]);
2797
2805
  return {
2798
2806
  httpStream: {
2799
2807
  basePath,
@@ -2892,4 +2900,4 @@ var FastMCP = class extends FastMCPEventEmitter {
2892
2900
 
2893
2901
 
2894
2902
  exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.FastMCPError = FastMCPError; exports.SessionError = SessionError; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ServerState = ServerState; exports.FastMCPSession = FastMCPSession; exports.FastMCP = FastMCP;
2895
- //# sourceMappingURL=chunk-KGXPEC7J.cjs.map
2903
+ //# sourceMappingURL=chunk-FFBZHCBQ.cjs.map