@context-engine-bridge/context-engine-mcp-bridge 0.0.59 → 0.0.62

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 +50 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-engine-bridge/context-engine-mcp-bridge",
3
- "version": "0.0.59",
3
+ "version": "0.0.62",
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
@@ -1859,55 +1859,89 @@ function _isBatchTool(name) {
1859
1859
  return name && name.startsWith("batch_");
1860
1860
  }
1861
1861
 
1862
+ function _unwrapSearchEnvelope(obj) {
1863
+ if (obj && obj.result && typeof obj.result === "object" && obj.result.ok !== undefined) {
1864
+ return obj.result;
1865
+ }
1866
+ return obj;
1867
+ }
1868
+
1869
+ function _getResultsArray(obj) {
1870
+ if (Array.isArray(obj.results)) return obj.results;
1871
+ if (Array.isArray(obj.results_json)) return obj.results_json;
1872
+ return null;
1873
+ }
1874
+
1862
1875
  function _mergeResults(primaryText, additionalTexts) {
1863
1876
  try {
1864
1877
  const primary = JSON.parse(primaryText);
1865
1878
  if (!primary || !primary.ok) return primaryText;
1866
1879
 
1880
+ const pInner = _unwrapSearchEnvelope(primary);
1881
+
1867
1882
  for (const addText of additionalTexts) {
1868
1883
  try {
1869
1884
  const additional = JSON.parse(addText);
1870
1885
  if (!additional || !additional.ok) continue;
1871
1886
 
1872
- if (Array.isArray(primary.results) && Array.isArray(additional.results)) {
1887
+ const aInner = _unwrapSearchEnvelope(additional);
1888
+ const pResults = _getResultsArray(pInner);
1889
+ const aResults = _getResultsArray(aInner);
1890
+ if (pResults && aResults) {
1873
1891
  const existingPaths = new Set(
1874
- primary.results.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`)
1892
+ pResults.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`)
1875
1893
  );
1876
- for (const r of additional.results) {
1894
+ for (const r of aResults) {
1877
1895
  const key = `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`;
1878
1896
  if (!existingPaths.has(key)) {
1879
- primary.results.push(r);
1897
+ pResults.push(r);
1880
1898
  existingPaths.add(key);
1881
1899
  }
1882
1900
  }
1901
+ if (Array.isArray(pInner.results_json)) {
1902
+ pInner.results_json = pResults;
1903
+ } else if (Array.isArray(pInner.results)) {
1904
+ pInner.results = pResults;
1905
+ } else {
1906
+ pInner.results_json = pResults;
1907
+ }
1883
1908
  }
1884
1909
 
1885
- if (typeof primary.total === "number" && typeof additional.total === "number") {
1886
- primary.total = primary.results ? primary.results.length : primary.total + additional.total;
1910
+ if (typeof pInner.total === "number" && typeof aInner.total === "number") {
1911
+ const arr = _getResultsArray(pInner);
1912
+ pInner.total = Array.isArray(arr) ? arr.length : pInner.total + aInner.total;
1887
1913
  }
1888
- if (typeof primary.count === "number" && typeof additional.count === "number") {
1889
- primary.count = primary.results ? primary.results.length : primary.count + additional.count;
1914
+ if (typeof pInner.count === "number" && typeof aInner.count === "number") {
1915
+ const arr = _getResultsArray(pInner);
1916
+ pInner.count = Array.isArray(arr) ? arr.length : pInner.count + aInner.count;
1890
1917
  }
1891
1918
  } catch (_) {}
1892
1919
  }
1893
1920
 
1894
- if (Array.isArray(primary.results) && primary.results.length > 1) {
1895
- primary.results.sort((a, b) => (b.score || 0) - (a.score || 0));
1921
+ const resultsArr = _getResultsArray(pInner);
1922
+ if (Array.isArray(resultsArr) && resultsArr.length > 1) {
1923
+ resultsArr.sort((a, b) => (b.score || 0) - (a.score || 0));
1896
1924
  }
1897
1925
 
1898
- const originalLimit = primary._original_limit;
1899
- if (originalLimit && Array.isArray(primary.results) && primary.results.length > originalLimit) {
1900
- primary.results = primary.results.slice(0, originalLimit);
1901
- if (typeof primary.total === "number") primary.total = primary.results.length;
1902
- if (typeof primary.count === "number") primary.count = primary.results.length;
1926
+ const originalLimit = primary._original_limit || (pInner._original_limit);
1927
+ if (originalLimit && Array.isArray(resultsArr) && resultsArr.length > originalLimit) {
1928
+ const sliced = resultsArr.slice(0, originalLimit);
1929
+ if (Array.isArray(pInner.results_json)) {
1930
+ pInner.results_json = sliced;
1931
+ } else {
1932
+ pInner.results = sliced;
1933
+ }
1934
+ if (typeof pInner.total === "number") pInner.total = sliced.length;
1935
+ if (typeof pInner.count === "number") pInner.count = sliced.length;
1903
1936
  }
1904
1937
 
1905
1938
  primary._cross_collection = true;
1906
1939
  primary._fanout_debug = {
1907
1940
  additional_texts_count: additionalTexts.length,
1908
1941
  additional_ok_count: additionalTexts.filter(t => { try { return JSON.parse(t).ok; } catch(_) { return false; } }).length,
1909
- final_results_count: Array.isArray(primary.results) ? primary.results.length : 0,
1942
+ final_results_count: Array.isArray(resultsArr) ? resultsArr.length : 0,
1910
1943
  original_limit: originalLimit || null,
1944
+ envelope: pInner !== primary,
1911
1945
  };
1912
1946
  return JSON.stringify(primary);
1913
1947
  } catch (_) {