threenative-engine-mcp 0.2.12 → 0.2.15

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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { realpathSync, readFileSync, existsSync, mkdirSync, rmSync, writeFileSync, appendFileSync, mkdtempSync, renameSync, readdirSync } from 'fs';
2
+ import { realpathSync, statSync, readFileSync, existsSync, mkdirSync, rmSync, writeFileSync, appendFileSync, mkdtempSync, renameSync, readdirSync } from 'fs';
3
3
  import path from 'path';
4
4
  import { createInterface } from 'readline';
5
5
  import { fileURLToPath } from 'url';
@@ -673,15 +673,23 @@ function validateManifest(value, file) {
673
673
  }
674
674
  return value;
675
675
  }
676
+ var manifestCache = /* @__PURE__ */ new Map();
676
677
  function loadCapabilityManifest(file = defaultManifestPath()) {
677
678
  let raw;
679
+ let stamp;
678
680
  try {
681
+ const stat = statSync(file);
682
+ stamp = `${stat.mtimeMs}:${stat.size}`;
683
+ const cached = manifestCache.get(file);
684
+ if (cached?.stamp === stamp) return cached.manifest;
679
685
  raw = readFileSync(file, "utf8");
680
686
  } catch (error) {
681
687
  throw manifestError(file, `cannot read committed manifest: ${String(error)}`);
682
688
  }
683
689
  try {
684
- return validateManifest(JSON.parse(raw), file);
690
+ const manifest = validateManifest(JSON.parse(raw), file);
691
+ manifestCache.set(file, { stamp, manifest });
692
+ return manifest;
685
693
  } catch (error) {
686
694
  if (error instanceof Error && error.message.startsWith("TN_ENGINE_CAPABILITIES_MANIFEST:"))
687
695
  throw error;
@@ -704,10 +712,23 @@ function suffixStripped(token) {
704
712
  return token;
705
713
  }
706
714
  var STOP_WORD_STEMS = new Set([...STOP_WORDS].map(stem));
715
+ function splitSymbolCase(value) {
716
+ return value.replace(/([a-z0-9])([A-Z])/gu, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/gu, "$1 $2");
717
+ }
707
718
  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));
719
+ 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));
720
+ }
721
+ var tokenCache = /* @__PURE__ */ new Map();
722
+ var TOKEN_CACHE_LIMIT = 2e4;
723
+ function tokens(value) {
724
+ let cached = tokenCache.get(value);
725
+ if (cached === void 0) {
726
+ if (tokenCache.size >= TOKEN_CACHE_LIMIT) tokenCache.clear();
727
+ cached = Object.freeze(capabilitySituationTokens(value));
728
+ tokenCache.set(value, cached);
729
+ }
730
+ return cached;
709
731
  }
710
- var tokens = capabilitySituationTokens;
711
732
  function tokenWeights(entries) {
712
733
  const frequency = /* @__PURE__ */ new Map();
713
734
  let situations = 0;
@@ -725,6 +746,36 @@ function tokenWeights(entries) {
725
746
  function weightOf(weights, token) {
726
747
  return weights.get(token) ?? 0;
727
748
  }
749
+ function nameWords(value) {
750
+ return tokens(value.replace(/([a-zA-Z])(\d+)/gu, "$1 $2")).filter((token) => !/\d/u.test(token));
751
+ }
752
+ function normaliseName(value) {
753
+ return value.toLocaleLowerCase().replace(/[^a-z0-9]+/gu, "");
754
+ }
755
+ function spelledWords(value) {
756
+ return value.toLocaleLowerCase().split(/[^a-z0-9]+/u).filter((word) => word.length > 0);
757
+ }
758
+ function spellsName(situation, symbol) {
759
+ const words = spelledWords(situation);
760
+ const whole = normaliseName(symbol);
761
+ for (let start = 0; start < words.length; start += 1) {
762
+ let piece = "";
763
+ for (let end = start; end < words.length && end < start + 4; end += 1) {
764
+ piece += normaliseName(words[end] ?? "");
765
+ if (piece === whole) return true;
766
+ if (piece.length >= whole.length) break;
767
+ }
768
+ }
769
+ return false;
770
+ }
771
+ function nameTokenWeights(entries) {
772
+ return tokenWeights(
773
+ entries.map((entry) => ({
774
+ aliases: [nameWords(entry.symbol).join(" ")],
775
+ situations: [entry.summary]
776
+ }))
777
+ );
778
+ }
728
779
  var DISTINCTIVE_SITUATION_SHARE = 0.02;
729
780
  var DISTINCTIVE_FLOOR = Math.log(1 + 1 / DISTINCTIVE_SITUATION_SHARE);
730
781
  var AGREEMENT_WEIGHT = 0.4;
@@ -785,6 +836,62 @@ function situationScore(query, situations, aliases, weights) {
785
836
  const matchedSituation = readable.matchedSituation.length > 0 ? readable.matchedSituation : best >= RELEVANCE_FLOOR ? readable.bestReadableSituation : "";
786
837
  return matchedSituation.length > 0 ? { matchedSituation, score: best } : { matchedSituation: "", score: 0 };
787
838
  }
839
+ var EXACT_SYMBOL_LEAD = 4;
840
+ var NAME_BASE_LEAD = 2;
841
+ var NAME_SHARE_LEAD = 1.4;
842
+ var SYMBOL_WEIGHT_FLOOR = 4.2;
843
+ var SINGLE_WORD_SHARE_FLOOR = 0.3;
844
+ function scoreSymbolName(symbol, situation, queryTokens, weights) {
845
+ const name = [...new Set(nameWords(symbol))];
846
+ if (name.length === 0) return void 0;
847
+ const nameWeights = name.map((token) => weightOf(weights, token));
848
+ const specificity = nameWeights.reduce((sum, weight) => sum + weight, 0);
849
+ const requestTotal = [...queryTokens].reduce((sum, token) => sum + weightOf(weights, token), 0);
850
+ const share = requestTotal === 0 ? 0 : specificity / requestTotal;
851
+ const nameScore = NAME_BASE_LEAD + NAME_SHARE_LEAD * Math.min(1, share);
852
+ if (spellsName(situation, symbol)) {
853
+ if (normaliseName(situation) === normaliseName(symbol)) {
854
+ return { score: EXACT_SYMBOL_LEAD, specificity };
855
+ }
856
+ if (name.length === 1) {
857
+ if (weightOf(weights, name[0] ?? "") < SYMBOL_WEIGHT_FLOOR) return void 0;
858
+ if (share < SINGLE_WORD_SHARE_FLOOR) return void 0;
859
+ return { score: (NAME_BASE_LEAD + NAME_SHARE_LEAD) * Math.min(1, share), specificity };
860
+ }
861
+ return { score: nameScore, specificity };
862
+ }
863
+ if (name.length < 2) return void 0;
864
+ const queryWords = new Set(nameWords(situation));
865
+ if (!name.every((token) => queryWords.has(token))) return void 0;
866
+ if (Math.max(...nameWeights) < SYMBOL_WEIGHT_FLOOR) return void 0;
867
+ return { score: nameScore, specificity };
868
+ }
869
+ var SUMMARY_WEIGHT = 0.4;
870
+ function summaryScore(summary, queryTokens, queryText, weights) {
871
+ const candidate = scorePhrase(summary, queryTokens, queryText, weights);
872
+ return candidate === void 0 ? 0 : candidate.score * SUMMARY_WEIGHT;
873
+ }
874
+ function capabilityScore(query, entry, weights, nameWeights, situation) {
875
+ const situations = {
876
+ ...situationScore(query, entry.situations, entry.aliases, weights),
877
+ specificity: 0
878
+ };
879
+ if (query.length === 0) return situations;
880
+ const queryTokens = new Set(query);
881
+ const symbol = scoreSymbolName(entry.symbol, situation, queryTokens, nameWeights);
882
+ const summary = summaryScore(entry.summary, queryTokens, query.join(" "), nameWeights);
883
+ const symbolScore = symbol?.score ?? 0;
884
+ const best = Math.max(situations.score, symbolScore, summary);
885
+ if (best <= situations.score) return situations;
886
+ if (symbol !== void 0 && symbolScore >= best) {
887
+ return { matchedSituation: entry.symbol, score: symbolScore, specificity: symbol.specificity };
888
+ }
889
+ return {
890
+ matchedSituation: situations.matchedSituation || entry.situations[0] || entry.summary,
891
+ score: best,
892
+ specificity: 0
893
+ };
894
+ }
788
895
  function notOwnedSituationScore(query, situations) {
789
896
  if (query.length === 0) return { matchedSituation: "", score: 0 };
790
897
  const queryText = query.join(" ");
@@ -881,10 +988,19 @@ function withReferenceTools(situation, response) {
881
988
  guidance: `Reverse engineer the game with engine_search_references, then engine_reference_detail for its pinned cards. ${response.guidance}`
882
989
  };
883
990
  }
991
+ var weightCache = /* @__PURE__ */ new WeakMap();
992
+ function manifestWeights(entries) {
993
+ let cached = weightCache.get(entries);
994
+ if (cached === void 0) {
995
+ cached = { weights: tokenWeights(entries), nameWeights: nameTokenWeights(entries) };
996
+ weightCache.set(entries, cached);
997
+ }
998
+ return cached;
999
+ }
884
1000
  function searchMechanics(situation, manifest, scope) {
885
1001
  const query = tokens(situation);
886
1002
  const limit = scope === "request" ? MAX_COMPLETE_REQUEST_RESULTS : MAX_SITUATION_RESULTS;
887
- const weights = tokenWeights(manifest.entries);
1003
+ const { weights, nameWeights } = manifestWeights(manifest.entries);
888
1004
  const notOwned = notOwnedMatch(manifest, query);
889
1005
  if (notOwned !== void 0 && isSpecificNotOwnedMatch(query, notOwned.matchedSituation)) {
890
1006
  return {
@@ -893,10 +1009,10 @@ function searchMechanics(situation, manifest, scope) {
893
1009
  verdict: "none"
894
1010
  };
895
1011
  }
896
- const results = manifest.entries.map((entry) => ({ entry, ...situationScore(query, entry.situations, entry.aliases, weights) })).filter(
1012
+ const results = manifest.entries.map((entry) => ({ entry, ...capabilityScore(query, entry, weights, nameWeights, situation) })).filter(
897
1013
  ({ matchedSituation, score }) => matchedSituation.length > 0 && score >= RELEVANCE_FLOOR
898
1014
  ).sort(
899
- (left, right) => right.score - left.score || `${left.entry.importPath}:${left.entry.symbol}`.localeCompare(
1015
+ (left, right) => right.score - left.score || right.specificity - left.specificity || `${left.entry.importPath}:${left.entry.symbol}`.localeCompare(
900
1016
  `${right.entry.importPath}:${right.entry.symbol}`
901
1017
  )
902
1018
  ).filter(
@@ -905,11 +1021,14 @@ function searchMechanics(situation, manifest, scope) {
905
1021
  ) === index
906
1022
  ).slice(0, limit).map(({ entry, matchedSituation, score }) => ({
907
1023
  constraints: entry.constraints,
1024
+ ...entry.deprecated === void 0 ? {} : { deprecated: entry.deprecated },
908
1025
  example: entry.example,
909
1026
  importPath: entry.importPath,
910
1027
  matchedSituation,
1028
+ ...entry.overrides === void 0 ? {} : { overrides: entry.overrides },
911
1029
  ...entry.requires === void 0 ? {} : { requires: entry.requires },
912
1030
  score,
1031
+ signature: entry.signature,
913
1032
  summary: entry.summary,
914
1033
  symbol: entry.symbol
915
1034
  }));
@@ -944,7 +1063,7 @@ var TOOL_DEFINITIONS = [
944
1063
  {
945
1064
  annotations: { destructiveHint: false, openWorldHint: false, readOnlyHint: true },
946
1065
  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.',
1066
+ 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
1067
  inputSchema: {
949
1068
  additionalProperties: false,
950
1069
  properties: {
@@ -1073,7 +1192,7 @@ function writeLine(value) {
1073
1192
  `);
1074
1193
  }
1075
1194
  function toolText(value) {
1076
- return { content: [{ text: JSON.stringify(value, null, 2), type: "text" }] };
1195
+ return { content: [{ text: JSON.stringify(value), type: "text" }] };
1077
1196
  }
1078
1197
  async function searchReferences(situation, limit = 5) {
1079
1198
  const local = loadLocalReferenceGames();
@@ -1266,7 +1385,7 @@ async function handleLine(line2, manifestFile) {
1266
1385
  capabilities: { tools: { listChanged: false } },
1267
1386
  instructions: AUTHORING_INSTRUCTIONS,
1268
1387
  protocolVersion: "2025-06-18",
1269
- serverInfo: { name: "threenative-engine-mcp", version: "0.2.12" }
1388
+ serverInfo: { name: "threenative-engine-mcp", version: "0.2.15" }
1270
1389
  });
1271
1390
  }
1272
1391
  if (request.method === "tools/list") {
@@ -1293,7 +1412,12 @@ async function runCli(argv, manifestFile = defaultManifestPath(), io = {
1293
1412
  { arguments: JSON.parse(json), name },
1294
1413
  manifestFile
1295
1414
  );
1296
- io.stdout(`${result.content[0].text}
1415
+ let text2 = result.content[0].text;
1416
+ try {
1417
+ text2 = JSON.stringify(JSON.parse(text2), null, 2);
1418
+ } catch {
1419
+ }
1420
+ io.stdout(`${text2}
1297
1421
  `);
1298
1422
  return 0;
1299
1423
  } 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.15",
4
4
  "license": "MIT",
5
5
  "description": "Offline MCP capability discovery for ThreeNative authoring agents.",
6
6
  "keywords": [