fastmcp 4.28.2 → 4.28.3

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 (43) hide show
  1. package/dist/FastMCP.cjs +4 -4
  2. package/dist/FastMCP.d.cts +2 -2
  3. package/dist/FastMCP.d.ts +2 -2
  4. package/dist/FastMCP.js +3 -3
  5. package/dist/{OAuthProvider-DvIxa9N1.d.cts → OAuthProvider-D9JYSSem.d.cts} +1 -0
  6. package/dist/{OAuthProvider-DvIxa9N1.d.ts → OAuthProvider-D9JYSSem.d.ts} +1 -0
  7. package/dist/auth/index.cjs +2 -2
  8. package/dist/auth/index.d.cts +2 -2
  9. package/dist/auth/index.d.ts +2 -2
  10. package/dist/auth/index.js +1 -1
  11. package/dist/bin/fastmcp.cjs +0 -1
  12. package/dist/bin/fastmcp.cjs.map +1 -1
  13. package/dist/bin/fastmcp.js +0 -1
  14. package/dist/bin/fastmcp.js.map +1 -1
  15. package/dist/{chunk-76OY4FEK.js → chunk-2RLFFOY2.js} +32 -15
  16. package/dist/chunk-2RLFFOY2.js.map +1 -0
  17. package/dist/{chunk-HZJE6ZGH.cjs → chunk-A2TZVOOY.cjs} +36 -19
  18. package/dist/chunk-A2TZVOOY.cjs.map +1 -0
  19. package/dist/{chunk-AM3HVK4Z.js → chunk-B2QUCZGV.js} +42 -18
  20. package/dist/chunk-B2QUCZGV.js.map +1 -0
  21. package/dist/{chunk-MBIVAKUB.js → chunk-GAPP6V64.js} +11 -5
  22. package/dist/chunk-GAPP6V64.js.map +1 -0
  23. package/dist/{chunk-2NZFMD6I.cjs → chunk-OCCYKYIM.cjs} +42 -18
  24. package/dist/chunk-OCCYKYIM.cjs.map +1 -0
  25. package/dist/{chunk-GW5MENCI.cjs → chunk-SQS3SIW7.cjs} +17 -11
  26. package/dist/chunk-SQS3SIW7.cjs.map +1 -0
  27. package/dist/edge/index.cjs +3 -3
  28. package/dist/edge/index.js +1 -1
  29. package/dist/examples/custom-routes.cjs +4 -4
  30. package/dist/examples/custom-routes.js +3 -3
  31. package/dist/openapi/index.cjs +23 -12
  32. package/dist/openapi/index.cjs.map +1 -1
  33. package/dist/openapi/index.d.cts +1 -1
  34. package/dist/openapi/index.d.ts +1 -1
  35. package/dist/openapi/index.js +17 -6
  36. package/dist/openapi/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunk-2NZFMD6I.cjs.map +0 -1
  39. package/dist/chunk-76OY4FEK.js.map +0 -1
  40. package/dist/chunk-AM3HVK4Z.js.map +0 -1
  41. package/dist/chunk-GW5MENCI.cjs.map +0 -1
  42. package/dist/chunk-HZJE6ZGH.cjs.map +0 -1
  43. package/dist/chunk-MBIVAKUB.js.map +0 -1
@@ -2108,7 +2108,7 @@ var OAuthProxy = (_class4 = class {
2108
2108
  let errorCode = "server_error";
2109
2109
  let errorDescription;
2110
2110
  try {
2111
- const error = await tokenResponse.json();
2111
+ const error = await this.parseTokenResponseBody(tokenResponse);
2112
2112
  errorCode = error.error || "server_error";
2113
2113
  errorDescription = error.error_description;
2114
2114
  } catch (e9) {
@@ -2299,7 +2299,7 @@ var OAuthProxy = (_class4 = class {
2299
2299
  let errorCode = "invalid_grant";
2300
2300
  let errorDescription;
2301
2301
  try {
2302
- const error = await tokenResponse.json();
2302
+ const error = await this.parseTokenResponseBody(tokenResponse);
2303
2303
  errorCode = error.error || "invalid_grant";
2304
2304
  errorDescription = error.error_description;
2305
2305
  } catch (e10) {
@@ -2639,7 +2639,6 @@ var OAuthProxy = (_class4 = class {
2639
2639
  * GitHub Apps return URL-encoded format, most providers return JSON
2640
2640
  */
2641
2641
  async parseTokenResponse(response) {
2642
- const contentType = (response.headers.get("content-type") || "").toLowerCase();
2643
2642
  const tokenResponseSchema = _zod.z.object({
2644
2643
  access_token: _zod.z.string().min(1, "access_token cannot be empty"),
2645
2644
  expires_in: _zod.z.coerce.number().int().positive().optional(),
@@ -2653,13 +2652,9 @@ var OAuthProxy = (_class4 = class {
2653
2652
  ).optional(),
2654
2653
  token_type: _zod.z.string().optional()
2655
2654
  });
2656
- if (contentType.includes("application/x-www-form-urlencoded")) {
2657
- const text = await response.text();
2658
- const params = new URLSearchParams(text);
2659
- this.rejectUpstreamError({
2660
- error: params.get("error"),
2661
- error_description: params.get("error_description")
2662
- });
2655
+ const payload = await this.parseTokenResponseBody(response);
2656
+ if (payload instanceof URLSearchParams) {
2657
+ const params = payload;
2663
2658
  const rawData = {
2664
2659
  access_token: params.get("access_token") || "",
2665
2660
  expires_in: params.get("expires_in") ? parseInt(params.get("expires_in")) : void 0,
@@ -2671,9 +2666,31 @@ var OAuthProxy = (_class4 = class {
2671
2666
  };
2672
2667
  return tokenResponseSchema.parse(rawData);
2673
2668
  }
2674
- const rawJson = await response.json();
2675
- this.rejectUpstreamError(rawJson);
2676
- return tokenResponseSchema.parse(rawJson);
2669
+ this.rejectUpstreamError(payload);
2670
+ return tokenResponseSchema.parse(payload);
2671
+ }
2672
+ async parseTokenResponseBody(response) {
2673
+ const type = _nullishCoalesce(_optionalChain([response, 'access', _31 => _31.headers, 'access', _32 => _32.get, 'call', _33 => _33("content-type"), 'optionalAccess', _34 => _34.toLowerCase, 'call', _35 => _35()]), () => ( ""));
2674
+ const formType = "application/x-www-form-urlencoded";
2675
+ const isForm = response.ok ? type.includes(formType) : withoutOptionalWhitespace(type.split(";", 1)[0]) === formType;
2676
+ if (!isForm) return response.json();
2677
+ const text = await response.text();
2678
+ const params = new URLSearchParams(text);
2679
+ const error = params.get("error");
2680
+ if (!response.ok) {
2681
+ try {
2682
+ return JSON.parse(text);
2683
+ } catch (cause) {
2684
+ if (!error) throw cause;
2685
+ }
2686
+ }
2687
+ if (error) {
2688
+ return {
2689
+ error,
2690
+ error_description: _nullishCoalesce(params.get("error_description"), () => ( void 0))
2691
+ };
2692
+ }
2693
+ return params;
2677
2694
  }
2678
2695
  /**
2679
2696
  * Storage key for the client binding of a passthrough-mode upstream refresh
@@ -2760,7 +2777,7 @@ var OAuthProxy = (_class4 = class {
2760
2777
  let errorCode = "invalid_grant";
2761
2778
  let errorDescription = "Upstream refresh failed";
2762
2779
  try {
2763
- const error = await tokenResponse.json();
2780
+ const error = await this.parseTokenResponseBody(tokenResponse);
2764
2781
  errorCode = error.error || "invalid_grant";
2765
2782
  errorDescription = error.error_description || "Upstream refresh failed";
2766
2783
  } catch (e11) {
@@ -2874,7 +2891,7 @@ var OAuthProxy = (_class4 = class {
2874
2891
  this.cleanupInterval = setInterval(() => {
2875
2892
  this.cleanup();
2876
2893
  }, 6e4);
2877
- _optionalChain([this, 'access', _31 => _31.cleanupInterval, 'access', _32 => _32.unref, 'optionalCall', _33 => _33()]);
2894
+ _optionalChain([this, 'access', _36 => _36.cleanupInterval, 'access', _37 => _37.unref, 'optionalCall', _38 => _38()]);
2878
2895
  }
2879
2896
  /**
2880
2897
  * Atomically claim a token mapping, mirroring `OAuthProxyStateStore`: at most
@@ -3043,7 +3060,7 @@ var AuthProvider = class {
3043
3060
  if (!request) {
3044
3061
  return void 0;
3045
3062
  }
3046
- const authHeader = _optionalChain([request, 'access', _34 => _34.headers, 'optionalAccess', _35 => _35.authorization]);
3063
+ const authHeader = _optionalChain([request, 'access', _39 => _39.headers, 'optionalAccess', _40 => _40.authorization]);
3047
3064
  if (!authHeader || !/^Bearer /i.test(authHeader)) {
3048
3065
  return void 0;
3049
3066
  }
@@ -3261,7 +3278,7 @@ var DiskStore = (_class5 = class {
3261
3278
  this.cleanupInterval = setInterval(() => {
3262
3279
  void this.cleanup();
3263
3280
  }, cleanupIntervalMs);
3264
- _optionalChain([this, 'access', _36 => _36.cleanupInterval, 'access', _37 => _37.unref, 'optionalCall', _38 => _38()]);
3281
+ _optionalChain([this, 'access', _41 => _41.cleanupInterval, 'access', _42 => _42.unref, 'optionalCall', _43 => _43()]);
3265
3282
  }
3266
3283
  /**
3267
3284
  * Clean up expired entries
@@ -3438,7 +3455,7 @@ var DiskStore = (_class5 = class {
3438
3455
  await _promises.rename.call(void 0, source, destination);
3439
3456
  return;
3440
3457
  } catch (error) {
3441
- const code = _optionalChain([error, 'optionalAccess', _39 => _39.code]);
3458
+ const code = _optionalChain([error, 'optionalAccess', _44 => _44.code]);
3442
3459
  if (process.platform !== "win32" || attempt >= 5 || !["EACCES", "EBUSY", "EPERM"].includes(_nullishCoalesce(code, () => ( "")))) {
3443
3460
  throw error;
3444
3461
  }
@@ -3614,4 +3631,4 @@ Original error: ${error.message}`
3614
3631
 
3615
3632
 
3616
3633
  exports.cancelResponseBody = cancelResponseBody; exports.getAuthSession = getAuthSession; exports.requireAll = requireAll; exports.requireAny = requireAny; exports.requireAuth = requireAuth; exports.requireRole = requireRole; exports.requireScopes = requireScopes; exports.DEFAULT_ACCESS_TOKEN_TTL = DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_REFRESH_TOKEN_TTL = DEFAULT_REFRESH_TOKEN_TTL; exports.TOKEN_ENDPOINT_AUTH_METHODS = TOKEN_ENDPOINT_AUTH_METHODS; exports.DEFAULT_AUTHORIZATION_CODE_TTL = DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_TRANSACTION_TTL = DEFAULT_TRANSACTION_TTL; exports.ConsentManager = ConsentManager; exports.JWTIssuer = JWTIssuer; exports.PKCEUtils = PKCEUtils; exports.EncryptedTokenStorage = EncryptedTokenStorage; exports.MemoryTokenStorage = MemoryTokenStorage; exports.OAuthProxy = OAuthProxy; exports.OAuthProxyError = OAuthProxyError; exports.AuthProvider = AuthProvider; exports.AzureProvider = AzureProvider; exports.GitHubProvider = GitHubProvider; exports.GoogleProvider = GoogleProvider; exports.OAuthProvider = OAuthProvider; exports.DiskStore = DiskStore; exports.JWKSVerifier = JWKSVerifier;
3617
- //# sourceMappingURL=chunk-HZJE6ZGH.cjs.map
3634
+ //# sourceMappingURL=chunk-A2TZVOOY.cjs.map