@mcp-ts/sdk 2.1.0 → 2.2.0

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.
@@ -1044,6 +1044,7 @@ var ToolRouter = class {
1044
1044
  __publicField(this, "index");
1045
1045
  __publicField(this, "allTools", []);
1046
1046
  __publicField(this, "pinnedTools", []);
1047
+ __publicField(this, "deferredTools", []);
1047
1048
  __publicField(this, "discoverableTools", []);
1048
1049
  __publicField(this, "groupsMap", /* @__PURE__ */ new Map());
1049
1050
  __publicField(this, "strategy");
@@ -1052,6 +1053,7 @@ var ToolRouter = class {
1052
1053
  __publicField(this, "activeGroups");
1053
1054
  __publicField(this, "customGroups");
1054
1055
  __publicField(this, "pinnedToolNames");
1056
+ __publicField(this, "deferredToolNames");
1055
1057
  __publicField(this, "excludeToolMatchers");
1056
1058
  __publicField(this, "initialized", false);
1057
1059
  this.strategy = options.strategy ?? "all";
@@ -1060,6 +1062,7 @@ var ToolRouter = class {
1060
1062
  this.activeGroups = new Set(options.activeGroups ?? []);
1061
1063
  this.customGroups = options.groups;
1062
1064
  this.pinnedToolNames = new Set(options.pinnedTools ?? []);
1065
+ this.deferredToolNames = new Set(options.deferredTools ?? []);
1063
1066
  this.excludeToolMatchers = (options.excludeTools ?? []).map(
1064
1067
  (pattern) => globToRegExp(pattern)
1065
1068
  );
@@ -1088,8 +1091,9 @@ var ToolRouter = class {
1088
1091
  return this.getGroupFilteredTools();
1089
1092
  case "all":
1090
1093
  default:
1094
+ const directlyVisibleTools = this.getDirectlyVisibleTools();
1091
1095
  if (this.compactSchemas) {
1092
- return this.allTools.map((t) => {
1096
+ return directlyVisibleTools.map((t) => {
1093
1097
  const compact = SchemaCompressor.toCompact(t);
1094
1098
  return {
1095
1099
  name: compact.name,
@@ -1098,7 +1102,7 @@ var ToolRouter = class {
1098
1102
  };
1099
1103
  });
1100
1104
  }
1101
- return [...this.allTools];
1105
+ return [...directlyVisibleTools];
1102
1106
  }
1103
1107
  }
1104
1108
  /**
@@ -1213,6 +1217,9 @@ var ToolRouter = class {
1213
1217
  const fetchedTools = await this.fetchAllTools();
1214
1218
  this.allTools = fetchedTools.filter((tool) => !this.matchesExcludedTool(tool.name));
1215
1219
  this.pinnedTools = this.allTools.filter((tool) => this.matchesPinnedTool(tool.name));
1220
+ this.deferredTools = this.allTools.filter(
1221
+ (tool) => !this.matchesPinnedTool(tool.name) && this.matchesDeferredTool(tool)
1222
+ );
1216
1223
  this.discoverableTools = this.allTools.filter((tool) => !this.matchesPinnedTool(tool.name));
1217
1224
  await this.index.buildIndex(this.discoverableTools);
1218
1225
  this.buildGroups();
@@ -1290,7 +1297,7 @@ var ToolRouter = class {
1290
1297
  }
1291
1298
  }
1292
1299
  }
1293
- const filtered = this.allTools.filter((t) => activeToolNames.has(t.name));
1300
+ const filtered = this.getDirectlyVisibleTools().filter((t) => activeToolNames.has(t.name));
1294
1301
  if (this.compactSchemas) {
1295
1302
  return filtered.slice(0, this.maxTools).map((t) => {
1296
1303
  const compact = SchemaCompressor.toCompact(t);
@@ -1316,9 +1323,19 @@ var ToolRouter = class {
1316
1323
  matchesPinnedTool(toolName) {
1317
1324
  return this.pinnedToolNames.has(toolName);
1318
1325
  }
1326
+ matchesDeferredTool(tool) {
1327
+ if (this.deferredToolNames.has(tool.name)) {
1328
+ return true;
1329
+ }
1330
+ const meta = tool._meta;
1331
+ return meta?.toolRouter?.deferred === true;
1332
+ }
1319
1333
  matchesExcludedTool(toolName) {
1320
1334
  return this.excludeToolMatchers.some((matcher) => matcher.test(toolName));
1321
1335
  }
1336
+ getDirectlyVisibleTools() {
1337
+ return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
1338
+ }
1322
1339
  };
1323
1340
  function globToRegExp(pattern) {
1324
1341
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");