threenative-engine-mcp 0.2.12 → 0.2.13

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
@@ -6,10 +6,12 @@ owns the discovery order and plan record.
6
6
 
7
7
  The server exposes `engine_search_capabilities`, `engine_capability_detail`,
8
8
  `engine_search_references`, `engine_reference_detail`, and `engine_save_reference`.
9
- Capability search works offline. Full requests use `scope: "request"` (up to 15 deduplicated
10
- matches); mechanic searches use `scope: "mechanic"` (up to five). Inspect `matchedSituation`
11
- and the detail constraints before implementing. A `none` capability result includes up to three
12
- reference suggestions.
9
+ Capability search works offline and finds a capability by an exact exported symbol name as well as
10
+ by situation. Full requests use `scope: "request"` (up to 15 deduplicated
11
+ matches); mechanic searches use `scope: "mechanic"` (up to five). A row carries the answer —
12
+ `importPath`, `signature`, `example`, `constraints`, `overrides` and any deprecation — so read every
13
+ row and call `engine_capability_detail` only for a symbol the search did not return. A `none`
14
+ capability result includes up to three reference suggestions.
13
15
 
14
16
  First infer the concrete mechanics implied by the request. Call `engine_search_capabilities` once
15
17
  with that mechanically explicit request and `scope: "request"`, then once per mechanic with
package/dist/index.d.ts CHANGED
@@ -38,13 +38,21 @@ interface IStarterKitResult {
38
38
  readonly blurb: string;
39
39
  readonly command: string;
40
40
  }
41
+ /**
42
+ * One search answer, equal to the capability detail minus `situations` and `aliases`. `signature`,
43
+ * `overrides` and `deprecated` were the three fields a row lacked, so every hit cost a detail call
44
+ * that added nothing else an author works from.
45
+ */
41
46
  interface ICapabilitySearchResult {
42
47
  readonly symbol: string;
43
48
  readonly importPath: string;
49
+ readonly signature: string;
44
50
  readonly summary: string;
45
51
  readonly example: string;
46
52
  readonly constraints: readonly string[];
53
+ readonly overrides?: readonly string[];
47
54
  readonly requires?: readonly string[];
55
+ readonly deprecated?: readonly string[];
48
56
  readonly matchedSituation: string;
49
57
  readonly score: number;
50
58
  }
package/dist/index.js CHANGED
@@ -704,8 +704,11 @@ function suffixStripped(token) {
704
704
  return token;
705
705
  }
706
706
  var STOP_WORD_STEMS = new Set([...STOP_WORDS].map(stem));
707
+ function splitSymbolCase(value) {
708
+ return value.replace(/([a-z0-9])([A-Z])/gu, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/gu, "$1 $2");
709
+ }
707
710
  function capabilitySituationTokens(value) {
708
- return value.toLocaleLowerCase().split(/[^a-z0-9]+/u).filter((token) => token.length > 1 && !STOP_WORDS.has(token)).map(stem).filter((token) => !STOP_WORD_STEMS.has(token));
711
+ return splitSymbolCase(value).toLocaleLowerCase().split(/[^a-z0-9]+/u).filter((token) => token.length > 1 && !STOP_WORDS.has(token)).map(stem).filter((token) => !STOP_WORD_STEMS.has(token));
709
712
  }
710
713
  var tokens = capabilitySituationTokens;
711
714
  function tokenWeights(entries) {
@@ -725,6 +728,36 @@ function tokenWeights(entries) {
725
728
  function weightOf(weights, token) {
726
729
  return weights.get(token) ?? 0;
727
730
  }
731
+ function nameWords(value) {
732
+ return tokens(value.replace(/([a-zA-Z])(\d+)/gu, "$1 $2")).filter((token) => !/\d/u.test(token));
733
+ }
734
+ function normaliseName(value) {
735
+ return value.toLocaleLowerCase().replace(/[^a-z0-9]+/gu, "");
736
+ }
737
+ function spelledWords(value) {
738
+ return value.toLocaleLowerCase().split(/[^a-z0-9]+/u).filter((word) => word.length > 0);
739
+ }
740
+ function spellsName(situation, symbol) {
741
+ const words = spelledWords(situation);
742
+ const whole = normaliseName(symbol);
743
+ for (let start = 0; start < words.length; start += 1) {
744
+ let piece = "";
745
+ for (let end = start; end < words.length && end < start + 4; end += 1) {
746
+ piece += normaliseName(words[end] ?? "");
747
+ if (piece === whole) return true;
748
+ if (piece.length >= whole.length) break;
749
+ }
750
+ }
751
+ return false;
752
+ }
753
+ function nameTokenWeights(entries) {
754
+ return tokenWeights(
755
+ entries.map((entry) => ({
756
+ aliases: [nameWords(entry.symbol).join(" ")],
757
+ situations: [entry.summary]
758
+ }))
759
+ );
760
+ }
728
761
  var DISTINCTIVE_SITUATION_SHARE = 0.02;
729
762
  var DISTINCTIVE_FLOOR = Math.log(1 + 1 / DISTINCTIVE_SITUATION_SHARE);
730
763
  var AGREEMENT_WEIGHT = 0.4;
@@ -785,6 +818,62 @@ function situationScore(query, situations, aliases, weights) {
785
818
  const matchedSituation = readable.matchedSituation.length > 0 ? readable.matchedSituation : best >= RELEVANCE_FLOOR ? readable.bestReadableSituation : "";
786
819
  return matchedSituation.length > 0 ? { matchedSituation, score: best } : { matchedSituation: "", score: 0 };
787
820
  }
821
+ var EXACT_SYMBOL_LEAD = 4;
822
+ var NAME_BASE_LEAD = 2;
823
+ var NAME_SHARE_LEAD = 1.4;
824
+ var SYMBOL_WEIGHT_FLOOR = 4.2;
825
+ var SINGLE_WORD_SHARE_FLOOR = 0.3;
826
+ function scoreSymbolName(symbol, situation, queryTokens, weights) {
827
+ const name = [...new Set(nameWords(symbol))];
828
+ if (name.length === 0) return void 0;
829
+ const nameWeights = name.map((token) => weightOf(weights, token));
830
+ const specificity = nameWeights.reduce((sum, weight) => sum + weight, 0);
831
+ const requestTotal = [...queryTokens].reduce((sum, token) => sum + weightOf(weights, token), 0);
832
+ const share = requestTotal === 0 ? 0 : specificity / requestTotal;
833
+ const nameScore = NAME_BASE_LEAD + NAME_SHARE_LEAD * Math.min(1, share);
834
+ if (spellsName(situation, symbol)) {
835
+ if (normaliseName(situation) === normaliseName(symbol)) {
836
+ return { score: EXACT_SYMBOL_LEAD, specificity };
837
+ }
838
+ if (name.length === 1) {
839
+ if (weightOf(weights, name[0] ?? "") < SYMBOL_WEIGHT_FLOOR) return void 0;
840
+ if (share < SINGLE_WORD_SHARE_FLOOR) return void 0;
841
+ return { score: (NAME_BASE_LEAD + NAME_SHARE_LEAD) * Math.min(1, share), specificity };
842
+ }
843
+ return { score: nameScore, specificity };
844
+ }
845
+ if (name.length < 2) return void 0;
846
+ const queryWords = new Set(nameWords(situation));
847
+ if (!name.every((token) => queryWords.has(token))) return void 0;
848
+ if (Math.max(...nameWeights) < SYMBOL_WEIGHT_FLOOR) return void 0;
849
+ return { score: nameScore, specificity };
850
+ }
851
+ var SUMMARY_WEIGHT = 0.4;
852
+ function summaryScore(summary, queryTokens, queryText, weights) {
853
+ const candidate = scorePhrase(summary, queryTokens, queryText, weights);
854
+ return candidate === void 0 ? 0 : candidate.score * SUMMARY_WEIGHT;
855
+ }
856
+ function capabilityScore(query, entry, weights, nameWeights, situation) {
857
+ const situations = {
858
+ ...situationScore(query, entry.situations, entry.aliases, weights),
859
+ specificity: 0
860
+ };
861
+ if (query.length === 0) return situations;
862
+ const queryTokens = new Set(query);
863
+ const symbol = scoreSymbolName(entry.symbol, situation, queryTokens, nameWeights);
864
+ const summary = summaryScore(entry.summary, queryTokens, query.join(" "), nameWeights);
865
+ const symbolScore = symbol?.score ?? 0;
866
+ const best = Math.max(situations.score, symbolScore, summary);
867
+ if (best <= situations.score) return situations;
868
+ if (symbol !== void 0 && symbolScore >= best) {
869
+ return { matchedSituation: entry.symbol, score: symbolScore, specificity: symbol.specificity };
870
+ }
871
+ return {
872
+ matchedSituation: situations.matchedSituation || entry.situations[0] || entry.summary,
873
+ score: best,
874
+ specificity: 0
875
+ };
876
+ }
788
877
  function notOwnedSituationScore(query, situations) {
789
878
  if (query.length === 0) return { matchedSituation: "", score: 0 };
790
879
  const queryText = query.join(" ");
@@ -885,6 +974,7 @@ function searchMechanics(situation, manifest, scope) {
885
974
  const query = tokens(situation);
886
975
  const limit = scope === "request" ? MAX_COMPLETE_REQUEST_RESULTS : MAX_SITUATION_RESULTS;
887
976
  const weights = tokenWeights(manifest.entries);
977
+ const nameWeights = nameTokenWeights(manifest.entries);
888
978
  const notOwned = notOwnedMatch(manifest, query);
889
979
  if (notOwned !== void 0 && isSpecificNotOwnedMatch(query, notOwned.matchedSituation)) {
890
980
  return {
@@ -893,10 +983,10 @@ function searchMechanics(situation, manifest, scope) {
893
983
  verdict: "none"
894
984
  };
895
985
  }
896
- const results = manifest.entries.map((entry) => ({ entry, ...situationScore(query, entry.situations, entry.aliases, weights) })).filter(
986
+ const results = manifest.entries.map((entry) => ({ entry, ...capabilityScore(query, entry, weights, nameWeights, situation) })).filter(
897
987
  ({ matchedSituation, score }) => matchedSituation.length > 0 && score >= RELEVANCE_FLOOR
898
988
  ).sort(
899
- (left, right) => right.score - left.score || `${left.entry.importPath}:${left.entry.symbol}`.localeCompare(
989
+ (left, right) => right.score - left.score || right.specificity - left.specificity || `${left.entry.importPath}:${left.entry.symbol}`.localeCompare(
900
990
  `${right.entry.importPath}:${right.entry.symbol}`
901
991
  )
902
992
  ).filter(
@@ -905,11 +995,14 @@ function searchMechanics(situation, manifest, scope) {
905
995
  ) === index
906
996
  ).slice(0, limit).map(({ entry, matchedSituation, score }) => ({
907
997
  constraints: entry.constraints,
998
+ ...entry.deprecated === void 0 ? {} : { deprecated: entry.deprecated },
908
999
  example: entry.example,
909
1000
  importPath: entry.importPath,
910
1001
  matchedSituation,
1002
+ ...entry.overrides === void 0 ? {} : { overrides: entry.overrides },
911
1003
  ...entry.requires === void 0 ? {} : { requires: entry.requires },
912
1004
  score,
1005
+ signature: entry.signature,
913
1006
  summary: entry.summary,
914
1007
  symbol: entry.symbol
915
1008
  }));
@@ -944,7 +1037,7 @@ var TOOL_DEFINITIONS = [
944
1037
  {
945
1038
  annotations: { destructiveHint: false, openWorldHint: false, readOnlyHint: true },
946
1039
  name: "engine_search_capabilities",
947
- description: 'Search the installed engine by concrete gameplay mechanic. Decompose genres first. Use scope "request" for the mechanically explicit full request and "mechanic" for each focused search; matchedSituation and score explain every result. The response verdict "none" is an actionable answer with guidance, not a failed search.',
1040
+ description: 'Search the installed engine by concrete gameplay mechanic or by an exact exported symbol name. Decompose genres first. Use scope "request" for the mechanically explicit full request and "mechanic" for each focused search; matchedSituation and score explain every result. A row carries the answer (importPath, signature, example, constraints, overrides, deprecations), so call engine_capability_detail only for a symbol the search did not return. The response verdict "none" is an actionable answer with guidance, not a failed search.',
948
1041
  inputSchema: {
949
1042
  additionalProperties: false,
950
1043
  properties: {
@@ -1073,7 +1166,7 @@ function writeLine(value) {
1073
1166
  `);
1074
1167
  }
1075
1168
  function toolText(value) {
1076
- return { content: [{ text: JSON.stringify(value, null, 2), type: "text" }] };
1169
+ return { content: [{ text: JSON.stringify(value), type: "text" }] };
1077
1170
  }
1078
1171
  async function searchReferences(situation, limit = 5) {
1079
1172
  const local = loadLocalReferenceGames();
@@ -1266,7 +1359,7 @@ async function handleLine(line2, manifestFile) {
1266
1359
  capabilities: { tools: { listChanged: false } },
1267
1360
  instructions: AUTHORING_INSTRUCTIONS,
1268
1361
  protocolVersion: "2025-06-18",
1269
- serverInfo: { name: "threenative-engine-mcp", version: "0.2.12" }
1362
+ serverInfo: { name: "threenative-engine-mcp", version: "0.2.13" }
1270
1363
  });
1271
1364
  }
1272
1365
  if (request.method === "tools/list") {
@@ -1293,7 +1386,12 @@ async function runCli(argv, manifestFile = defaultManifestPath(), io = {
1293
1386
  { arguments: JSON.parse(json), name },
1294
1387
  manifestFile
1295
1388
  );
1296
- io.stdout(`${result.content[0].text}
1389
+ let text2 = result.content[0].text;
1390
+ try {
1391
+ text2 = JSON.stringify(JSON.parse(text2), null, 2);
1392
+ } catch {
1393
+ }
1394
+ io.stdout(`${text2}
1297
1395
  `);
1298
1396
  return 0;
1299
1397
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threenative-engine-mcp",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "license": "MIT",
5
5
  "description": "Offline MCP capability discovery for ThreeNative authoring agents.",
6
6
  "keywords": [