@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.
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
  }
@@ -5090,7 +5105,7 @@ var ToolRouter = class {
5090
5105
  * If tool name is ambiguous, use namespace to specify the server.
5091
5106
  */
5092
5107
  getToolSchema(toolName, namespace, options = {}) {
5093
- const matches = this.index.getTool(toolName, namespace, options);
5108
+ const matches = this.getIndexedToolMatches(toolName, namespace, options);
5094
5109
  if (matches.length === 0) return void 0;
5095
5110
  if (matches.length > 1) {
5096
5111
  const servers = matches.map((m) => m.serverId).join(", ");
@@ -5297,6 +5312,23 @@ var ToolRouter = class {
5297
5312
  getDirectlyVisibleTools() {
5298
5313
  return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
5299
5314
  }
5315
+ getIndexedToolMatches(toolName, namespace, options = {}) {
5316
+ const indexedMatches = this.index.getTool(toolName, namespace, options);
5317
+ if (indexedMatches.length > 0 || !this.matchesPinnedTool(toolName)) {
5318
+ return indexedMatches;
5319
+ }
5320
+ return this.matchTools(this.pinnedTools.filter((tool) => tool.name === toolName), namespace, options);
5321
+ }
5322
+ matchTools(tools, namespace, options = {}) {
5323
+ if (!namespace) return tools;
5324
+ const exactMatches = tools.filter(
5325
+ (tool) => tool.sessionId === namespace || tool.serverId === namespace
5326
+ );
5327
+ if (exactMatches.length > 0) return exactMatches;
5328
+ if (!options.allowServerNameFragment) return [];
5329
+ const namespaceLower = namespace.toLowerCase();
5330
+ return tools.filter((tool) => tool.serverName.toLowerCase().includes(namespaceLower));
5331
+ }
5300
5332
  };
5301
5333
  function globToRegExp(pattern) {
5302
5334
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");