@mcp-ts/sdk 2.3.2 → 2.3.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.
package/dist/index.mjs CHANGED
@@ -1713,6 +1713,13 @@ var RpcErrorCodes = {
1713
1713
  };
1714
1714
 
1715
1715
  // src/server/mcp/oauth-client.ts
1716
+ function isInvalidRefreshTokenError(error) {
1717
+ if (!(error instanceof Error)) {
1718
+ return false;
1719
+ }
1720
+ const text = `${error.name} ${error.message}`.toLowerCase();
1721
+ return text.includes("invalidgrant") || text.includes("invalid_grant") || text.includes("invalid refresh token") || /refresh\s+token\s+(?:is\s+)?(?:invalid|expired|revoked)/i.test(text);
1722
+ }
1716
1723
  var MCPClient = class _MCPClient {
1717
1724
  /**
1718
1725
  * Creates a new MCP client instance
@@ -2404,6 +2411,14 @@ var MCPClient = class _MCPClient {
2404
2411
  return true;
2405
2412
  } catch (error) {
2406
2413
  console.error("[OAuth] Token refresh failed:", error);
2414
+ if (isInvalidRefreshTokenError(error)) {
2415
+ try {
2416
+ await this.oauthProvider.invalidateCredentials?.("tokens");
2417
+ this.emitProgress("OAuth refresh token is invalid; requesting reauthorization...");
2418
+ } catch (invalidateError) {
2419
+ console.warn("[OAuth] Failed to invalidate stale refresh token credentials:", invalidateError);
2420
+ }
2421
+ }
2407
2422
  return false;
2408
2423
  }
2409
2424
  }