@mcp-ts/sdk 2.3.1 → 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.
@@ -1642,6 +1642,13 @@ var RpcErrorCodes = {
1642
1642
  EXECUTION_ERROR: "EXECUTION_ERROR"};
1643
1643
 
1644
1644
  // src/server/mcp/oauth-client.ts
1645
+ function isInvalidRefreshTokenError(error) {
1646
+ if (!(error instanceof Error)) {
1647
+ return false;
1648
+ }
1649
+ const text = `${error.name} ${error.message}`.toLowerCase();
1650
+ 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);
1651
+ }
1645
1652
  var MCPClient = class _MCPClient {
1646
1653
  /**
1647
1654
  * Creates a new MCP client instance
@@ -2333,6 +2340,14 @@ var MCPClient = class _MCPClient {
2333
2340
  return true;
2334
2341
  } catch (error) {
2335
2342
  console.error("[OAuth] Token refresh failed:", error);
2343
+ if (isInvalidRefreshTokenError(error)) {
2344
+ try {
2345
+ await this.oauthProvider.invalidateCredentials?.("tokens");
2346
+ this.emitProgress("OAuth refresh token is invalid; requesting reauthorization...");
2347
+ } catch (invalidateError) {
2348
+ console.warn("[OAuth] Failed to invalidate stale refresh token credentials:", invalidateError);
2349
+ }
2350
+ }
2336
2351
  return false;
2337
2352
  }
2338
2353
  }