fastmcp 4.24.5 → 4.25.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 (39) hide show
  1. package/dist/FastMCP.cjs +3 -3
  2. package/dist/FastMCP.d.cts +2 -2
  3. package/dist/FastMCP.d.ts +2 -2
  4. package/dist/FastMCP.js +2 -2
  5. package/dist/{OAuthProvider-84BWWDBF.d.cts → OAuthProvider-CPC9zG96.d.cts} +16 -0
  6. package/dist/{OAuthProvider-84BWWDBF.d.ts → OAuthProvider-CPC9zG96.d.ts} +16 -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 +1 -0
  12. package/dist/bin/fastmcp.cjs.map +1 -1
  13. package/dist/bin/fastmcp.js +1 -0
  14. package/dist/bin/fastmcp.js.map +1 -1
  15. package/dist/{chunk-CAQLTSJ5.js → chunk-3VYVXSBB.js} +42 -7
  16. package/dist/chunk-3VYVXSBB.js.map +1 -0
  17. package/dist/{chunk-BV4PWTT6.cjs → chunk-AKHG27NY.cjs} +42 -7
  18. package/dist/chunk-AKHG27NY.cjs.map +1 -0
  19. package/dist/{chunk-UYV7MFKA.js → chunk-SQSE766U.js} +39 -15
  20. package/dist/chunk-SQSE766U.js.map +1 -0
  21. package/dist/{chunk-P56ABHAK.cjs → chunk-VWHJYU4V.cjs} +42 -18
  22. package/dist/chunk-VWHJYU4V.cjs.map +1 -0
  23. package/dist/edge/index.cjs +6 -6
  24. package/dist/edge/index.cjs.map +1 -1
  25. package/dist/edge/index.js +6 -6
  26. package/dist/edge/index.js.map +1 -1
  27. package/dist/examples/custom-routes.cjs +3 -3
  28. package/dist/examples/custom-routes.js +2 -2
  29. package/dist/openapi/index.cjs +51 -34
  30. package/dist/openapi/index.cjs.map +1 -1
  31. package/dist/openapi/index.d.cts +8 -3
  32. package/dist/openapi/index.d.ts +8 -3
  33. package/dist/openapi/index.js +29 -12
  34. package/dist/openapi/index.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/chunk-BV4PWTT6.cjs.map +0 -1
  37. package/dist/chunk-CAQLTSJ5.js.map +0 -1
  38. package/dist/chunk-P56ABHAK.cjs.map +0 -1
  39. package/dist/chunk-UYV7MFKA.js.map +0 -1
@@ -852,7 +852,7 @@ var ConsentManager = class {
852
852
  </p>
853
853
  </div>
854
854
 
855
- <form method="POST" action="/oauth/consent">
855
+ <form method="POST" action="consent">
856
856
  <input type="hidden" name="transaction_id" value="${this.escapeHtml(transactionId)}">
857
857
  <div class="actions">
858
858
  <button type="submit" name="action" value="deny" class="deny">
@@ -1620,16 +1620,16 @@ var OAuthProxy = (_class4 = class {
1620
1620
  */
1621
1621
  getAuthorizationServerMetadata() {
1622
1622
  return {
1623
- authorizationEndpoint: `${this.config.baseUrl}/oauth/authorize`,
1623
+ authorizationEndpoint: this.getEndpointUrl("/oauth/authorize"),
1624
1624
  ...this.config.authorizationResponseIss ? { authorizationResponseIssParameterSupported: true } : {},
1625
1625
  ...this.config.enableCimd ? { clientIdMetadataDocumentSupported: true } : {},
1626
1626
  codeChallengeMethodsSupported: this.config.allowPlainPkce ? ["S256", "plain"] : ["S256"],
1627
1627
  grantTypesSupported: ["authorization_code", "refresh_token"],
1628
1628
  issuer: this.config.baseUrl,
1629
- registrationEndpoint: `${this.config.baseUrl}/oauth/register`,
1629
+ registrationEndpoint: this.getEndpointUrl("/oauth/register"),
1630
1630
  responseTypesSupported: ["code"],
1631
1631
  scopesSupported: this.config.scopes || [],
1632
- tokenEndpoint: `${this.config.baseUrl}/oauth/token`,
1632
+ tokenEndpoint: this.getEndpointUrl("/oauth/token"),
1633
1633
  // Public clients use PKCE instead of a secret: CIMD clients never
1634
1634
  // receive one, and DCR clients may register with "none".
1635
1635
  tokenEndpointAuthMethodsSupported: [
@@ -1940,7 +1940,7 @@ var OAuthProxy = (_class4 = class {
1940
1940
  code,
1941
1941
  code_verifier: transaction.proxyCodeVerifier,
1942
1942
  grant_type: "authorization_code",
1943
- redirect_uri: `${this.config.baseUrl}${this.config.redirectPath}`
1943
+ redirect_uri: this.getEndpointUrl(this.config.redirectPath)
1944
1944
  };
1945
1945
  if (!useBasicAuth) {
1946
1946
  bodyParams.client_id = this.config.upstreamClientId;
@@ -2089,6 +2089,10 @@ var OAuthProxy = (_class4 = class {
2089
2089
  );
2090
2090
  return `Basic ${Buffer.from(`${encodedClientId}:${encodedClientSecret}`).toString("base64")}`;
2091
2091
  }
2092
+ /** Join endpoint paths without changing the configured issuer identifier. */
2093
+ getEndpointUrl(path) {
2094
+ return `${this.config.baseUrl.replace(/\/+$/, "")}${path}`;
2095
+ }
2092
2096
  /**
2093
2097
  * Get provider name for display
2094
2098
  */
@@ -2451,6 +2455,10 @@ var OAuthProxy = (_class4 = class {
2451
2455
  if (contentType.includes("application/x-www-form-urlencoded")) {
2452
2456
  const text = await response.text();
2453
2457
  const params = new URLSearchParams(text);
2458
+ this.rejectUpstreamError({
2459
+ error: params.get("error"),
2460
+ error_description: params.get("error_description")
2461
+ });
2454
2462
  const rawData = {
2455
2463
  access_token: params.get("access_token") || "",
2456
2464
  expires_in: params.get("expires_in") ? parseInt(params.get("expires_in")) : void 0,
@@ -2463,6 +2471,7 @@ var OAuthProxy = (_class4 = class {
2463
2471
  return tokenResponseSchema.parse(rawData);
2464
2472
  }
2465
2473
  const rawJson = await response.json();
2474
+ this.rejectUpstreamError(rawJson);
2466
2475
  return tokenResponseSchema.parse(rawJson);
2467
2476
  }
2468
2477
  /**
@@ -2490,7 +2499,7 @@ var OAuthProxy = (_class4 = class {
2490
2499
  authUrl.searchParams.set("client_id", this.config.upstreamClientId);
2491
2500
  authUrl.searchParams.set(
2492
2501
  "redirect_uri",
2493
- `${this.config.baseUrl}${this.config.redirectPath}`
2502
+ this.getEndpointUrl(this.config.redirectPath)
2494
2503
  );
2495
2504
  authUrl.searchParams.set("response_type", "code");
2496
2505
  authUrl.searchParams.set("state", transaction.id);
@@ -2556,6 +2565,32 @@ var OAuthProxy = (_class4 = class {
2556
2565
  tokenType: tokens.token_type || "Bearer"
2557
2566
  };
2558
2567
  }
2568
+ /**
2569
+ * RFC 6749 §5.2: a provider refuses a token request by naming the error in
2570
+ * the response body. The status that carries it is not fixed — GitHub, whose
2571
+ * own branch exists above, answers every refusal with 200 — so a refusal is
2572
+ * recognised here, from the body, rather than left to fail the token schema
2573
+ * parse. Without this the upstream's own diagnosis (`bad_verification_code`,
2574
+ * `invalid_grant`, …) is replaced by a `ZodError`, which the routes answer as
2575
+ * `server_error` (callback) or `invalid_request` (token).
2576
+ *
2577
+ * The upstream's code is kept as the `OAuthProxyError` code, and its
2578
+ * description when it sent one, so the client is told what the provider
2579
+ * actually refused.
2580
+ */
2581
+ rejectUpstreamError(payload) {
2582
+ if (!payload || typeof payload !== "object") {
2583
+ return;
2584
+ }
2585
+ const { error, error_description } = payload;
2586
+ if (typeof error !== "string" || error === "") {
2587
+ return;
2588
+ }
2589
+ throw new OAuthProxyError(
2590
+ error,
2591
+ typeof error_description === "string" ? error_description : void 0
2592
+ );
2593
+ }
2559
2594
  /**
2560
2595
  * Resolve the client behind a `client_id`: a stored registration if there is
2561
2596
  * one, otherwise — when CIMD is enabled — the client's metadata document.
@@ -3324,4 +3359,4 @@ Original error: ${error.message}`
3324
3359
 
3325
3360
 
3326
3361
  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;
3327
- //# sourceMappingURL=chunk-BV4PWTT6.cjs.map
3362
+ //# sourceMappingURL=chunk-AKHG27NY.cjs.map