@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.
package/dist/index.mjs CHANGED
@@ -4929,6 +4929,7 @@ var ToolRouter = class {
4929
4929
  __publicField(this, "index");
4930
4930
  __publicField(this, "allTools", []);
4931
4931
  __publicField(this, "pinnedTools", []);
4932
+ __publicField(this, "deferredTools", []);
4932
4933
  __publicField(this, "discoverableTools", []);
4933
4934
  __publicField(this, "groupsMap", /* @__PURE__ */ new Map());
4934
4935
  __publicField(this, "strategy");
@@ -4937,6 +4938,7 @@ var ToolRouter = class {
4937
4938
  __publicField(this, "activeGroups");
4938
4939
  __publicField(this, "customGroups");
4939
4940
  __publicField(this, "pinnedToolNames");
4941
+ __publicField(this, "deferredToolNames");
4940
4942
  __publicField(this, "excludeToolMatchers");
4941
4943
  __publicField(this, "initialized", false);
4942
4944
  this.strategy = options.strategy ?? "all";
@@ -4945,6 +4947,7 @@ var ToolRouter = class {
4945
4947
  this.activeGroups = new Set(options.activeGroups ?? []);
4946
4948
  this.customGroups = options.groups;
4947
4949
  this.pinnedToolNames = new Set(options.pinnedTools ?? []);
4950
+ this.deferredToolNames = new Set(options.deferredTools ?? []);
4948
4951
  this.excludeToolMatchers = (options.excludeTools ?? []).map(
4949
4952
  (pattern) => globToRegExp(pattern)
4950
4953
  );
@@ -4973,8 +4976,9 @@ var ToolRouter = class {
4973
4976
  return this.getGroupFilteredTools();
4974
4977
  case "all":
4975
4978
  default:
4979
+ const directlyVisibleTools = this.getDirectlyVisibleTools();
4976
4980
  if (this.compactSchemas) {
4977
- return this.allTools.map((t) => {
4981
+ return directlyVisibleTools.map((t) => {
4978
4982
  const compact = SchemaCompressor.toCompact(t);
4979
4983
  return {
4980
4984
  name: compact.name,
@@ -4983,7 +4987,7 @@ var ToolRouter = class {
4983
4987
  };
4984
4988
  });
4985
4989
  }
4986
- return [...this.allTools];
4990
+ return [...directlyVisibleTools];
4987
4991
  }
4988
4992
  }
4989
4993
  /**
@@ -5098,6 +5102,9 @@ var ToolRouter = class {
5098
5102
  const fetchedTools = await this.fetchAllTools();
5099
5103
  this.allTools = fetchedTools.filter((tool) => !this.matchesExcludedTool(tool.name));
5100
5104
  this.pinnedTools = this.allTools.filter((tool) => this.matchesPinnedTool(tool.name));
5105
+ this.deferredTools = this.allTools.filter(
5106
+ (tool) => !this.matchesPinnedTool(tool.name) && this.matchesDeferredTool(tool)
5107
+ );
5101
5108
  this.discoverableTools = this.allTools.filter((tool) => !this.matchesPinnedTool(tool.name));
5102
5109
  await this.index.buildIndex(this.discoverableTools);
5103
5110
  this.buildGroups();
@@ -5175,7 +5182,7 @@ var ToolRouter = class {
5175
5182
  }
5176
5183
  }
5177
5184
  }
5178
- const filtered = this.allTools.filter((t) => activeToolNames.has(t.name));
5185
+ const filtered = this.getDirectlyVisibleTools().filter((t) => activeToolNames.has(t.name));
5179
5186
  if (this.compactSchemas) {
5180
5187
  return filtered.slice(0, this.maxTools).map((t) => {
5181
5188
  const compact = SchemaCompressor.toCompact(t);
@@ -5201,9 +5208,19 @@ var ToolRouter = class {
5201
5208
  matchesPinnedTool(toolName) {
5202
5209
  return this.pinnedToolNames.has(toolName);
5203
5210
  }
5211
+ matchesDeferredTool(tool) {
5212
+ if (this.deferredToolNames.has(tool.name)) {
5213
+ return true;
5214
+ }
5215
+ const meta = tool._meta;
5216
+ return meta?.toolRouter?.deferred === true;
5217
+ }
5204
5218
  matchesExcludedTool(toolName) {
5205
5219
  return this.excludeToolMatchers.some((matcher) => matcher.test(toolName));
5206
5220
  }
5221
+ getDirectlyVisibleTools() {
5222
+ return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
5223
+ }
5207
5224
  };
5208
5225
  function globToRegExp(pattern) {
5209
5226
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");