@context-engine-bridge/context-engine-mcp-bridge 0.0.70 → 0.0.72

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/mcpServer.js +77 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-engine-bridge/context-engine-mcp-bridge",
3
- "version": "0.0.70",
3
+ "version": "0.0.72",
4
4
  "description": "Context Engine MCP bridge (http/stdio proxy combining indexer + memory servers)",
5
5
  "bin": {
6
6
  "ctxce": "bin/ctxce.js",
package/src/mcpServer.js CHANGED
@@ -1262,10 +1262,6 @@ async function createBridgeServer(options) {
1262
1262
  debugLog(`[ctxce] Fan-out: ${name} across ${additionalCollections.length} additional collection(s): ${additionalCollections.join(", ")}`);
1263
1263
  }
1264
1264
 
1265
- if (shouldFanOut && args && typeof args === "object") {
1266
- args = { ...args, output_format: "json", compact: false };
1267
- }
1268
-
1269
1265
  const timeoutMs = getBridgeToolTimeoutMs();
1270
1266
  const maxAttempts = getBridgeRetryAttempts();
1271
1267
  const retryDelayMs = getBridgeRetryDelayMs();
@@ -1868,8 +1864,10 @@ function _isBatchTool(name) {
1868
1864
  }
1869
1865
 
1870
1866
  function _unwrapSearchEnvelope(obj) {
1871
- if (obj && obj.result && typeof obj.result === "object" && obj.result.ok !== undefined) {
1872
- return obj.result;
1867
+ if (obj && obj.result && typeof obj.result === "object") {
1868
+ if (obj.result.ok !== undefined || Array.isArray(obj.result.results) || Array.isArray(obj.result.results_json)) {
1869
+ return obj.result;
1870
+ }
1873
1871
  }
1874
1872
  return obj;
1875
1873
  }
@@ -1880,10 +1878,34 @@ function _getResultsArray(obj) {
1880
1878
  return null;
1881
1879
  }
1882
1880
 
1881
+ function _parseToonResults(toonStr) {
1882
+ if (typeof toonStr !== "string") return null;
1883
+ try {
1884
+ const lines = toonStr.split("\n");
1885
+ const results = [];
1886
+ for (let i = 1; i < lines.length; i++) {
1887
+ const line = lines[i].trim();
1888
+ if (!line) continue;
1889
+ const parts = line.split(",");
1890
+ if (parts.length < 4) continue;
1891
+ const clean = s => (s || "").replace(/^["'\s]+|["'\s]+$/g, "");
1892
+ results.push({
1893
+ score: parseFloat(parts[0]) || 0,
1894
+ path: clean(parts[1]),
1895
+ symbol: clean(parts[2]),
1896
+ start_line: parseInt(parts[3], 10) || 0,
1897
+ end_line: parseInt(parts[4], 10) || 0,
1898
+ });
1899
+ }
1900
+ return results.length > 0 ? results : null;
1901
+ } catch (_) { return null; }
1902
+ }
1903
+
1883
1904
  function _mergeResults(primaryText, additionalTexts) {
1884
1905
  try {
1885
1906
  const primary = JSON.parse(primaryText);
1886
- if (!primary || !primary.ok) return primaryText;
1907
+ const _primaryHasData = primary && (primary.ok || Array.isArray(primary.results) || (primary.result && Array.isArray(primary.result.results)));
1908
+ if (!_primaryHasData) return primaryText;
1887
1909
 
1888
1910
  const pInner = _unwrapSearchEnvelope(primary);
1889
1911
 
@@ -1892,7 +1914,8 @@ function _mergeResults(primaryText, additionalTexts) {
1892
1914
  for (const addText of additionalTexts) {
1893
1915
  try {
1894
1916
  const additional = JSON.parse(addText);
1895
- if (!additional || !additional.ok) {
1917
+ const _addHasData = additional && (additional.ok || Array.isArray(additional.results) || (additional.result && Array.isArray(additional.result.results)));
1918
+ if (!_addHasData) {
1896
1919
  _perCall.push({ ok: false, error: additional?.error || "not ok" });
1897
1920
  continue;
1898
1921
  }
@@ -1925,10 +1948,25 @@ function _mergeResults(primaryText, additionalTexts) {
1925
1948
  pInner.results_json = pResults;
1926
1949
  }
1927
1950
  } else if (!pResults && aResults) {
1928
- primary._merge_branch = "only_additional";
1929
- _totalAdded += aResults.length;
1930
- _perCall.push({ ok: true, a_len: aResults.length, added: aResults.length, branch: "only_additional" });
1931
- pInner.results_json = [...aResults];
1951
+ const parsedToon = _parseToonResults(pInner.results);
1952
+ if (parsedToon) {
1953
+ primary._merge_branch = "toon_parsed";
1954
+ const existingPaths = new Set(parsedToon.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`));
1955
+ let added = 0;
1956
+ for (const r of aResults) {
1957
+ const key = `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`;
1958
+ if (!existingPaths.has(key)) { parsedToon.push(r); existingPaths.add(key); added++; }
1959
+ }
1960
+ parsedToon.sort((a, b) => (b.score || 0) - (a.score || 0));
1961
+ _totalAdded += added;
1962
+ _perCall.push({ ok: true, a_len: aResults.length, added, branch: "toon_parsed", before: parsedToon.length - added, after: parsedToon.length });
1963
+ pInner.results_json = parsedToon;
1964
+ } else {
1965
+ primary._merge_branch = "only_additional";
1966
+ _totalAdded += aResults.length;
1967
+ _perCall.push({ ok: true, a_len: aResults.length, added: aResults.length, branch: "only_additional" });
1968
+ pInner.results_json = [...aResults];
1969
+ }
1932
1970
  } else {
1933
1971
  primary._merge_branch = "no_merge";
1934
1972
  _perCall.push({ ok: true, branch: "no_merge", p_type: pResults ? "array" : typeof pInner.results, a_type: aResults ? "array" : typeof aInner.results });
@@ -1979,37 +2017,51 @@ function _mergeResults(primaryText, additionalTexts) {
1979
2017
  function _mergeBatchResults(primaryText, additionalTexts) {
1980
2018
  try {
1981
2019
  const primary = JSON.parse(primaryText);
1982
- if (!primary || !primary.ok || !Array.isArray(primary.results)) return primaryText;
2020
+ if (!primary || !primary.ok) return primaryText;
2021
+ const pBatch = Array.isArray(primary.results) ? primary.results : Array.isArray(primary.batch_results) ? primary.batch_results : null;
2022
+ if (!pBatch) return primaryText;
1983
2023
 
1984
2024
  for (const addText of additionalTexts) {
1985
2025
  try {
1986
2026
  const additional = JSON.parse(addText);
1987
- if (!additional || !additional.ok || !Array.isArray(additional.results)) continue;
2027
+ if (!additional || !additional.ok) continue;
2028
+ const aBatch = Array.isArray(additional.results) ? additional.results : Array.isArray(additional.batch_results) ? additional.batch_results : null;
2029
+ if (!aBatch) continue;
1988
2030
 
1989
- for (let i = 0; i < primary.results.length && i < additional.results.length; i++) {
1990
- const pItem = primary.results[i];
1991
- const aItem = additional.results[i];
2031
+ for (let i = 0; i < pBatch.length && i < aBatch.length; i++) {
2032
+ const pItem = pBatch[i];
2033
+ const aItem = aBatch[i];
1992
2034
  if (!pItem || !aItem) continue;
1993
2035
 
1994
2036
  const pInner = pItem.result || pItem;
1995
2037
  const aInner = aItem.result || aItem;
1996
2038
 
1997
- if (Array.isArray(pInner.results) && Array.isArray(aInner.results)) {
2039
+ let pResults = Array.isArray(pInner.results) ? pInner.results : Array.isArray(pInner.results_json) ? pInner.results_json : null;
2040
+ const aResults = Array.isArray(aInner.results) ? aInner.results : Array.isArray(aInner.results_json) ? aInner.results_json : null;
2041
+
2042
+ if (!pResults && typeof pInner.results === "string") {
2043
+ pResults = _parseToonResults(pInner.results);
2044
+ }
2045
+
2046
+ if (pResults && aResults) {
1998
2047
  const existingPaths = new Set(
1999
- pInner.results.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`)
2048
+ pResults.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`)
2000
2049
  );
2001
- for (const r of aInner.results) {
2050
+ for (const r of aResults) {
2002
2051
  const key = `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`;
2003
2052
  if (!existingPaths.has(key)) {
2004
- pInner.results.push(r);
2053
+ pResults.push(r);
2005
2054
  existingPaths.add(key);
2006
2055
  }
2007
2056
  }
2008
- if (pInner.results.length > 1) {
2009
- pInner.results.sort((a, b) => (b.score || 0) - (a.score || 0));
2057
+ if (pResults.length > 1) {
2058
+ pResults.sort((a, b) => (b.score || 0) - (a.score || 0));
2010
2059
  }
2011
- if (typeof pInner.total === "number") pInner.total = pInner.results.length;
2012
- if (typeof pInner.count === "number") pInner.count = pInner.results.length;
2060
+ pInner.results_json = pResults;
2061
+ if (typeof pInner.total === "number") pInner.total = pResults.length;
2062
+ if (typeof pInner.count === "number") pInner.count = pResults.length;
2063
+ } else if (!pResults && aResults) {
2064
+ pInner.results_json = [...aResults];
2013
2065
  }
2014
2066
  }
2015
2067
  } catch (_) {}