@mcp-ts/sdk 2.3.0 → 2.3.2

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.
Files changed (39) hide show
  1. package/dist/adapters/agui-adapter.d.mts +1 -1
  2. package/dist/adapters/agui-adapter.d.ts +1 -1
  3. package/dist/adapters/agui-adapter.js +9 -5
  4. package/dist/adapters/agui-adapter.js.map +1 -1
  5. package/dist/adapters/agui-adapter.mjs +9 -5
  6. package/dist/adapters/agui-adapter.mjs.map +1 -1
  7. package/dist/adapters/agui-middleware.d.mts +1 -1
  8. package/dist/adapters/agui-middleware.d.ts +1 -1
  9. package/dist/adapters/ai-adapter.d.mts +1 -1
  10. package/dist/adapters/ai-adapter.d.ts +1 -1
  11. package/dist/adapters/ai-adapter.js +9 -5
  12. package/dist/adapters/ai-adapter.js.map +1 -1
  13. package/dist/adapters/ai-adapter.mjs +9 -5
  14. package/dist/adapters/ai-adapter.mjs.map +1 -1
  15. package/dist/adapters/langchain-adapter.d.mts +1 -1
  16. package/dist/adapters/langchain-adapter.d.ts +1 -1
  17. package/dist/adapters/langchain-adapter.js +9 -5
  18. package/dist/adapters/langchain-adapter.js.map +1 -1
  19. package/dist/adapters/langchain-adapter.mjs +9 -5
  20. package/dist/adapters/langchain-adapter.mjs.map +1 -1
  21. package/dist/client/react.js.map +1 -1
  22. package/dist/client/react.mjs.map +1 -1
  23. package/dist/index.d.mts +1 -1
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.js +35 -6
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +35 -6
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/shared/index.d.mts +2 -2
  30. package/dist/shared/index.d.ts +2 -2
  31. package/dist/shared/index.js +35 -6
  32. package/dist/shared/index.js.map +1 -1
  33. package/dist/shared/index.mjs +35 -6
  34. package/dist/shared/index.mjs.map +1 -1
  35. package/dist/{tool-router-CdX8e9bk.d.ts → tool-router-BMzhoNYt.d.ts} +7 -0
  36. package/dist/{tool-router-C8hIA-tg.d.mts → tool-router-BhHsvBfP.d.mts} +7 -0
  37. package/package.json +1 -1
  38. package/src/shared/meta-tools.ts +16 -7
  39. package/src/shared/tool-router.ts +45 -1
package/dist/index.mjs CHANGED
@@ -4754,8 +4754,13 @@ function createExecuteToolDefinition() {
4754
4754
  };
4755
4755
  }
4756
4756
  async function executeMetaTool(toolName, args, router, callToolFn) {
4757
- const resolveToolSchema = (name, namespace, options) => {
4757
+ const resolveToolSchema = async (name, namespace, options) => {
4758
4758
  try {
4759
+ if (typeof router.resolveToolSchema === "function") {
4760
+ return {
4761
+ tool: await router.resolveToolSchema(name, namespace, options)
4762
+ };
4763
+ }
4759
4764
  return { tool: router.getToolSchema(name, namespace, options) };
4760
4765
  } catch (err) {
4761
4766
  const errorMessage = err instanceof Error ? err.message : String(err);
@@ -4807,13 +4812,12 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
4807
4812
  const searchOptions = { serverId, serverName };
4808
4813
  const selectMatch = query.match(/^select:(.+)$/i);
4809
4814
  if (selectMatch) {
4810
- await router.listTools({ serverId, serverName, limit: 1 });
4811
4815
  const requested = selectMatch[1].split(",").map((s) => s.trim()).filter(Boolean);
4812
4816
  const found = [];
4813
4817
  const errors = [];
4814
4818
  const namespace = serverId ?? serverName;
4815
4819
  for (const requestedToolName of requested) {
4816
- const { tool, error } = resolveToolSchema(requestedToolName, namespace, {
4820
+ const { tool, error } = await resolveToolSchema(requestedToolName, namespace, {
4817
4821
  allowServerNameFragment: Boolean(serverName && !serverId)
4818
4822
  });
4819
4823
  if (error) {
@@ -4877,7 +4881,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
4877
4881
  case "mcp_get_tool_schema": {
4878
4882
  const name = String(args.toolName ?? "");
4879
4883
  const namespace = String(args.serverId ?? "") || void 0;
4880
- const { tool, error } = resolveToolSchema(name, namespace);
4884
+ const { tool, error } = await resolveToolSchema(name, namespace);
4881
4885
  if (error) {
4882
4886
  return error;
4883
4887
  }
@@ -4919,7 +4923,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
4919
4923
  isError: true
4920
4924
  };
4921
4925
  }
4922
- const { tool, error } = resolveToolSchema(targetToolName, namespace);
4926
+ const { tool, error } = await resolveToolSchema(targetToolName, namespace);
4923
4927
  if (error) {
4924
4928
  return error;
4925
4929
  }
@@ -5086,7 +5090,7 @@ var ToolRouter = class {
5086
5090
  * If tool name is ambiguous, use namespace to specify the server.
5087
5091
  */
5088
5092
  getToolSchema(toolName, namespace, options = {}) {
5089
- const matches = this.index.getTool(toolName, namespace, options);
5093
+ const matches = this.getIndexedToolMatches(toolName, namespace, options);
5090
5094
  if (matches.length === 0) return void 0;
5091
5095
  if (matches.length > 1) {
5092
5096
  const servers = matches.map((m) => m.serverId).join(", ");
@@ -5096,6 +5100,14 @@ var ToolRouter = class {
5096
5100
  }
5097
5101
  return matches[0];
5098
5102
  }
5103
+ /**
5104
+ * Resolve the full tool definition by name, ensuring the router index has
5105
+ * been initialized first.
5106
+ */
5107
+ async resolveToolSchema(toolName, namespace, options = {}) {
5108
+ await this.ensureInitialized();
5109
+ return this.getToolSchema(toolName, namespace, options);
5110
+ }
5099
5111
  /**
5100
5112
  * Get compact (schema-less) summaries for all tools.
5101
5113
  */
@@ -5285,6 +5297,23 @@ var ToolRouter = class {
5285
5297
  getDirectlyVisibleTools() {
5286
5298
  return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
5287
5299
  }
5300
+ getIndexedToolMatches(toolName, namespace, options = {}) {
5301
+ const indexedMatches = this.index.getTool(toolName, namespace, options);
5302
+ if (indexedMatches.length > 0 || !this.matchesPinnedTool(toolName)) {
5303
+ return indexedMatches;
5304
+ }
5305
+ return this.matchTools(this.pinnedTools.filter((tool) => tool.name === toolName), namespace, options);
5306
+ }
5307
+ matchTools(tools, namespace, options = {}) {
5308
+ if (!namespace) return tools;
5309
+ const exactMatches = tools.filter(
5310
+ (tool) => tool.sessionId === namespace || tool.serverId === namespace
5311
+ );
5312
+ if (exactMatches.length > 0) return exactMatches;
5313
+ if (!options.allowServerNameFragment) return [];
5314
+ const namespaceLower = namespace.toLowerCase();
5315
+ return tools.filter((tool) => tool.serverName.toLowerCase().includes(namespaceLower));
5316
+ }
5288
5317
  };
5289
5318
  function globToRegExp(pattern) {
5290
5319
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");