@ttoss/http-server-mcp 0.34.1 → 0.34.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.
package/README.md CHANGED
@@ -484,7 +484,7 @@ registerTools({ server: fullServer, tools });
484
484
  registerTools({ server: deferredServer, tools, defer: true });
485
485
  ```
486
486
 
487
- A schema enters the model's context only for the tools it is about to use. `call` enforces the tool's schema as a direct call would, and its errors help the model recover: an unknown name answers suggestions (near-miss names, then tools the name's words match; a lone prefix in a description is not enough), and invalid arguments, a tool's own error result, or a thrown error carry the input schema, so a `call` made without `describe` corrects itself in one retry.
487
+ A schema enters the model's context only for the tools it is about to use. `call` enforces the tool's schema as a direct call would, and its errors help the model recover: an unknown name answers suggestions (close typos first, then near-misses and tools sharing the name's words, by how much they share), and invalid arguments, a tool's own error result, or a thrown error carry the input schema, so a `call` made without `describe` corrects itself in one retry.
488
488
 
489
489
  Pass options instead of `true` to tune it:
490
490
 
package/dist/index.cjs CHANGED
@@ -507,7 +507,6 @@ var defineTool = ({
507
507
  //#region src/toolSearch.ts
508
508
  var SUMMARY_MAX_LENGTH = 160;
509
509
  var SUGGESTION_COUNT = 3;
510
- var MIN_RELATED_SCORE = 1;
511
510
  /** Plural and singular forms rank alike: `agents` finds `get-agent`. */
512
511
  var stem = term => {
513
512
  if (term.length > 4 && term.endsWith("ies")) return `${term.slice(0, -3)}y`;
@@ -660,39 +659,47 @@ var editDistance = (a, b) => {
660
659
  }
661
660
  return row[b.length];
662
661
  };
663
- /** Names a model probably meant: near-misses first, then related tools. */
662
+ /**
663
+ * Names a model probably meant: close typos first, nearest first; then the
664
+ * near-misses and the tools sharing the name's words, by word score, so a tool
665
+ * holding every word outranks a distant near-miss.
666
+ */
664
667
  var suggestionsFor = ({
665
668
  name,
666
669
  tools
667
670
  }) => {
668
671
  const tolerance = Math.max(2, Math.floor(name.length / 3));
669
- const nearMisses = tools.map(tool => {
672
+ const scores = new Map((scoreTools({
673
+ query: name,
674
+ tools
675
+ }) ?? []).map(({
676
+ tool,
677
+ score
678
+ }) => {
679
+ return [tool, score];
680
+ }));
681
+ const rankOf = distance => {
682
+ return Math.min(distance, 3);
683
+ };
684
+ return tools.map((tool, index) => {
670
685
  return {
671
- name: tool.name,
672
- distance: editDistance(name, tool.name)
686
+ tool,
687
+ index,
688
+ distance: editDistance(name, tool.name),
689
+ score: scores.get(tool) ?? 0
673
690
  };
674
691
  }).filter(({
675
- distance
676
- }) => {
677
- return distance <= tolerance;
678
- }).sort((a, b) => {
679
- return a.distance - b.distance;
680
- }).map(candidate => {
681
- return candidate.name;
682
- });
683
- const related = (scoreTools({
684
- query: name,
685
- tools
686
- }) ?? []).filter(({
692
+ distance,
687
693
  score
688
694
  }) => {
689
- return score >= MIN_RELATED_SCORE;
695
+ return distance <= tolerance || score > 0;
696
+ }).sort((a, b) => {
697
+ return rankOf(a.distance) - rankOf(b.distance) || b.score - a.score || a.distance - b.distance || a.index - b.index;
690
698
  }).slice(0, SUGGESTION_COUNT).map(({
691
699
  tool
692
700
  }) => {
693
701
  return tool.name;
694
702
  });
695
- return [...new Set([...nearMisses, ...related])].slice(0, SUGGESTION_COUNT);
696
703
  };
697
704
 
698
705
  //#endregion
package/dist/index.mjs CHANGED
@@ -504,7 +504,6 @@ var defineTool = ({
504
504
  //#region src/toolSearch.ts
505
505
  var SUMMARY_MAX_LENGTH = 160;
506
506
  var SUGGESTION_COUNT = 3;
507
- var MIN_RELATED_SCORE = 1;
508
507
  /** Plural and singular forms rank alike: `agents` finds `get-agent`. */
509
508
  var stem = term => {
510
509
  if (term.length > 4 && term.endsWith("ies")) return `${term.slice(0, -3)}y`;
@@ -657,39 +656,47 @@ var editDistance = (a, b) => {
657
656
  }
658
657
  return row[b.length];
659
658
  };
660
- /** Names a model probably meant: near-misses first, then related tools. */
659
+ /**
660
+ * Names a model probably meant: close typos first, nearest first; then the
661
+ * near-misses and the tools sharing the name's words, by word score, so a tool
662
+ * holding every word outranks a distant near-miss.
663
+ */
661
664
  var suggestionsFor = ({
662
665
  name,
663
666
  tools
664
667
  }) => {
665
668
  const tolerance = Math.max(2, Math.floor(name.length / 3));
666
- const nearMisses = tools.map(tool => {
669
+ const scores = new Map((scoreTools({
670
+ query: name,
671
+ tools
672
+ }) ?? []).map(({
673
+ tool,
674
+ score
675
+ }) => {
676
+ return [tool, score];
677
+ }));
678
+ const rankOf = distance => {
679
+ return Math.min(distance, 3);
680
+ };
681
+ return tools.map((tool, index) => {
667
682
  return {
668
- name: tool.name,
669
- distance: editDistance(name, tool.name)
683
+ tool,
684
+ index,
685
+ distance: editDistance(name, tool.name),
686
+ score: scores.get(tool) ?? 0
670
687
  };
671
688
  }).filter(({
672
- distance
673
- }) => {
674
- return distance <= tolerance;
675
- }).sort((a, b) => {
676
- return a.distance - b.distance;
677
- }).map(candidate => {
678
- return candidate.name;
679
- });
680
- const related = (scoreTools({
681
- query: name,
682
- tools
683
- }) ?? []).filter(({
689
+ distance,
684
690
  score
685
691
  }) => {
686
- return score >= MIN_RELATED_SCORE;
692
+ return distance <= tolerance || score > 0;
693
+ }).sort((a, b) => {
694
+ return rankOf(a.distance) - rankOf(b.distance) || b.score - a.score || a.distance - b.distance || a.index - b.index;
687
695
  }).slice(0, SUGGESTION_COUNT).map(({
688
696
  tool
689
697
  }) => {
690
698
  return tool.name;
691
699
  });
692
- return [...new Set([...nearMisses, ...related])].slice(0, SUGGESTION_COUNT);
693
700
  };
694
701
 
695
702
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/http-server-mcp",
3
- "version": "0.34.1",
3
+ "version": "0.34.2",
4
4
  "description": "Model Context Protocol (MCP) server integration for @ttoss/http-server",
5
5
  "keywords": [
6
6
  "ai",