@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
@@ -805,8 +805,13 @@ function createExecuteToolDefinition() {
805
805
  };
806
806
  }
807
807
  async function executeMetaTool(toolName, args, router, callToolFn) {
808
- const resolveToolSchema = (name, namespace, options) => {
808
+ const resolveToolSchema = async (name, namespace, options) => {
809
809
  try {
810
+ if (typeof router.resolveToolSchema === "function") {
811
+ return {
812
+ tool: await router.resolveToolSchema(name, namespace, options)
813
+ };
814
+ }
810
815
  return { tool: router.getToolSchema(name, namespace, options) };
811
816
  } catch (err) {
812
817
  const errorMessage = err instanceof Error ? err.message : String(err);
@@ -858,13 +863,12 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
858
863
  const searchOptions = { serverId, serverName };
859
864
  const selectMatch = query.match(/^select:(.+)$/i);
860
865
  if (selectMatch) {
861
- await router.listTools({ serverId, serverName, limit: 1 });
862
866
  const requested = selectMatch[1].split(",").map((s) => s.trim()).filter(Boolean);
863
867
  const found = [];
864
868
  const errors = [];
865
869
  const namespace = serverId ?? serverName;
866
870
  for (const requestedToolName of requested) {
867
- const { tool, error } = resolveToolSchema(requestedToolName, namespace, {
871
+ const { tool, error } = await resolveToolSchema(requestedToolName, namespace, {
868
872
  allowServerNameFragment: Boolean(serverName && !serverId)
869
873
  });
870
874
  if (error) {
@@ -928,7 +932,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
928
932
  case "mcp_get_tool_schema": {
929
933
  const name = String(args.toolName ?? "");
930
934
  const namespace = String(args.serverId ?? "") || void 0;
931
- const { tool, error } = resolveToolSchema(name, namespace);
935
+ const { tool, error } = await resolveToolSchema(name, namespace);
932
936
  if (error) {
933
937
  return error;
934
938
  }
@@ -970,7 +974,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
970
974
  isError: true
971
975
  };
972
976
  }
973
- const { tool, error } = resolveToolSchema(targetToolName, namespace);
977
+ const { tool, error } = await resolveToolSchema(targetToolName, namespace);
974
978
  if (error) {
975
979
  return error;
976
980
  }
@@ -1137,7 +1141,7 @@ var ToolRouter = class {
1137
1141
  * If tool name is ambiguous, use namespace to specify the server.
1138
1142
  */
1139
1143
  getToolSchema(toolName, namespace, options = {}) {
1140
- const matches = this.index.getTool(toolName, namespace, options);
1144
+ const matches = this.getIndexedToolMatches(toolName, namespace, options);
1141
1145
  if (matches.length === 0) return void 0;
1142
1146
  if (matches.length > 1) {
1143
1147
  const servers = matches.map((m) => m.serverId).join(", ");
@@ -1147,6 +1151,14 @@ var ToolRouter = class {
1147
1151
  }
1148
1152
  return matches[0];
1149
1153
  }
1154
+ /**
1155
+ * Resolve the full tool definition by name, ensuring the router index has
1156
+ * been initialized first.
1157
+ */
1158
+ async resolveToolSchema(toolName, namespace, options = {}) {
1159
+ await this.ensureInitialized();
1160
+ return this.getToolSchema(toolName, namespace, options);
1161
+ }
1150
1162
  /**
1151
1163
  * Get compact (schema-less) summaries for all tools.
1152
1164
  */
@@ -1336,6 +1348,23 @@ var ToolRouter = class {
1336
1348
  getDirectlyVisibleTools() {
1337
1349
  return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
1338
1350
  }
1351
+ getIndexedToolMatches(toolName, namespace, options = {}) {
1352
+ const indexedMatches = this.index.getTool(toolName, namespace, options);
1353
+ if (indexedMatches.length > 0 || !this.matchesPinnedTool(toolName)) {
1354
+ return indexedMatches;
1355
+ }
1356
+ return this.matchTools(this.pinnedTools.filter((tool) => tool.name === toolName), namespace, options);
1357
+ }
1358
+ matchTools(tools, namespace, options = {}) {
1359
+ if (!namespace) return tools;
1360
+ const exactMatches = tools.filter(
1361
+ (tool) => tool.sessionId === namespace || tool.serverId === namespace
1362
+ );
1363
+ if (exactMatches.length > 0) return exactMatches;
1364
+ if (!options.allowServerNameFragment) return [];
1365
+ const namespaceLower = namespace.toLowerCase();
1366
+ return tools.filter((tool) => tool.serverName.toLowerCase().includes(namespaceLower));
1367
+ }
1339
1368
  };
1340
1369
  function globToRegExp(pattern) {
1341
1370
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");