@context-engine-bridge/context-engine-mcp-bridge 0.0.69 → 0.0.71

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 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-engine-bridge/context-engine-mcp-bridge",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
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
@@ -717,12 +717,12 @@ async function createBridgeServer(options) {
717
717
  const explicitCollection = options.collection;
718
718
 
719
719
  const config = loadConfig(workspace);
720
+ const configCollection = config && typeof config.default_collection === "string"
721
+ ? config.default_collection : null;
720
722
  const defaultCollection =
721
723
  explicitCollection && typeof explicitCollection === "string"
722
724
  ? explicitCollection
723
- : config && typeof config.default_collection === "string"
724
- ? config.default_collection
725
- : null;
725
+ : configCollection;
726
726
  const defaultMode =
727
727
  config && typeof config.default_mode === "string" ? config.default_mode : null;
728
728
  const defaultUnder =
@@ -1262,6 +1262,10 @@ 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
+
1265
1269
  const timeoutMs = getBridgeToolTimeoutMs();
1266
1270
  const maxAttempts = getBridgeRetryAttempts();
1267
1271
  const retryDelayMs = getBridgeRetryDelayMs();
@@ -1292,11 +1296,13 @@ async function createBridgeServer(options) {
1292
1296
  if (shouldFanOut) {
1293
1297
  const fanOutCallTimeoutMs = Math.min(timeoutMs, 10000);
1294
1298
  const fanOutDeadlineMs = Math.round(fanOutCallTimeoutMs * 0.8);
1295
- const allFanOutCollections = [defaultCollection || primaryCollection, ...additionalCollections].filter(Boolean);
1299
+ const allFanOutCollections = [...additionalCollections].filter(Boolean);
1296
1300
  const fanOutPromises = allFanOutCollections.map(col => {
1297
- const colArgs = { ...args, collection: col, output_format: "json", compact: false };
1301
+ const fanOutToolName = (name === "search" || name === "context_search") ? "repo_search" : name;
1302
+ const { session: _s, ...argsNoSession } = (args && typeof args === "object") ? args : {};
1303
+ const colArgs = { ...argsNoSession, collection: col, output_format: "json", compact: false };
1298
1304
  return targetClient.callTool(
1299
- { name, arguments: colArgs },
1305
+ { name: fanOutToolName, arguments: colArgs },
1300
1306
  undefined,
1301
1307
  { timeout: fanOutCallTimeoutMs },
1302
1308
  ).catch(err => {
@@ -1862,8 +1868,10 @@ function _isBatchTool(name) {
1862
1868
  }
1863
1869
 
1864
1870
  function _unwrapSearchEnvelope(obj) {
1865
- if (obj && obj.result && typeof obj.result === "object" && obj.result.ok !== undefined) {
1866
- return obj.result;
1871
+ if (obj && obj.result && typeof obj.result === "object") {
1872
+ if (obj.result.ok !== undefined || Array.isArray(obj.result.results) || Array.isArray(obj.result.results_json)) {
1873
+ return obj.result;
1874
+ }
1867
1875
  }
1868
1876
  return obj;
1869
1877
  }
@@ -1877,15 +1885,19 @@ function _getResultsArray(obj) {
1877
1885
  function _mergeResults(primaryText, additionalTexts) {
1878
1886
  try {
1879
1887
  const primary = JSON.parse(primaryText);
1880
- if (!primary || !primary.ok) return primaryText;
1888
+ const _primaryHasData = primary && (primary.ok || Array.isArray(primary.results) || (primary.result && Array.isArray(primary.result.results)));
1889
+ if (!_primaryHasData) return primaryText;
1881
1890
 
1882
1891
  const pInner = _unwrapSearchEnvelope(primary);
1883
1892
 
1893
+ const _perCall = [];
1894
+ let _totalAdded = 0;
1884
1895
  for (const addText of additionalTexts) {
1885
1896
  try {
1886
1897
  const additional = JSON.parse(addText);
1887
- if (!additional || !additional.ok) {
1888
- primary._merge_skip = { ok: additional?.ok, keys: additional ? Object.keys(additional).slice(0, 10) : [] };
1898
+ const _addHasData = additional && (additional.ok || Array.isArray(additional.results) || (additional.result && Array.isArray(additional.result.results)));
1899
+ if (!_addHasData) {
1900
+ _perCall.push({ ok: false, error: additional?.error || "not ok" });
1889
1901
  continue;
1890
1902
  }
1891
1903
 
@@ -1907,10 +1919,8 @@ function _mergeResults(primaryText, additionalTexts) {
1907
1919
  added++;
1908
1920
  }
1909
1921
  }
1910
- primary._merge_added = added;
1911
- primary._merge_pre_sort = pResults.length;
1912
- primary._merge_before_len = beforeLen;
1913
- primary._merge_a_len = aResults.length;
1922
+ _totalAdded += added;
1923
+ _perCall.push({ ok: true, a_len: aResults.length, added, before: beforeLen, after: pResults.length });
1914
1924
  if (Array.isArray(pInner.results_json)) {
1915
1925
  pInner.results_json = pResults;
1916
1926
  } else if (Array.isArray(pInner.results)) {
@@ -1920,12 +1930,12 @@ function _mergeResults(primaryText, additionalTexts) {
1920
1930
  }
1921
1931
  } else if (!pResults && aResults) {
1922
1932
  primary._merge_branch = "only_additional";
1923
- primary._merge_added = aResults.length;
1933
+ _totalAdded += aResults.length;
1934
+ _perCall.push({ ok: true, a_len: aResults.length, added: aResults.length, branch: "only_additional" });
1924
1935
  pInner.results_json = [...aResults];
1925
1936
  } else {
1926
1937
  primary._merge_branch = "no_merge";
1927
- primary._merge_p_type = pResults ? "array" : typeof pInner.results;
1928
- primary._merge_a_type = aResults ? "array" : typeof aInner.results;
1938
+ _perCall.push({ ok: true, branch: "no_merge", p_type: pResults ? "array" : typeof pInner.results, a_type: aResults ? "array" : typeof aInner.results });
1929
1939
  }
1930
1940
 
1931
1941
  if (typeof pInner.total === "number" && typeof aInner.total === "number") {
@@ -1957,11 +1967,10 @@ function _mergeResults(primaryText, additionalTexts) {
1957
1967
  primary._fanout_debug = {
1958
1968
  additional_count: additionalTexts.length,
1959
1969
  merged_count: Array.isArray(finalArr) ? finalArr.length : 0,
1960
- branch: primary._merge_branch || "none",
1961
- added: primary._merge_added || 0,
1970
+ total_added: _totalAdded,
1971
+ per_call: _perCall,
1962
1972
  };
1963
1973
  if (primary._merge_error) primary._fanout_debug.error = primary._merge_error;
1964
- if (primary._merge_skip) primary._fanout_debug.skip = primary._merge_skip;
1965
1974
  delete primary._merge_branch; delete primary._merge_added; delete primary._merge_pre_sort;
1966
1975
  delete primary._merge_before_len; delete primary._merge_a_len; delete primary._merge_error;
1967
1976
  delete primary._merge_skip; delete primary._merge_p_type; delete primary._merge_a_type;
@@ -1974,37 +1983,44 @@ function _mergeResults(primaryText, additionalTexts) {
1974
1983
  function _mergeBatchResults(primaryText, additionalTexts) {
1975
1984
  try {
1976
1985
  const primary = JSON.parse(primaryText);
1977
- if (!primary || !primary.ok || !Array.isArray(primary.results)) return primaryText;
1986
+ if (!primary || !primary.ok) return primaryText;
1987
+ const pBatch = Array.isArray(primary.results) ? primary.results : Array.isArray(primary.batch_results) ? primary.batch_results : null;
1988
+ if (!pBatch) return primaryText;
1978
1989
 
1979
1990
  for (const addText of additionalTexts) {
1980
1991
  try {
1981
1992
  const additional = JSON.parse(addText);
1982
- if (!additional || !additional.ok || !Array.isArray(additional.results)) continue;
1993
+ if (!additional || !additional.ok) continue;
1994
+ const aBatch = Array.isArray(additional.results) ? additional.results : Array.isArray(additional.batch_results) ? additional.batch_results : null;
1995
+ if (!aBatch) continue;
1983
1996
 
1984
- for (let i = 0; i < primary.results.length && i < additional.results.length; i++) {
1985
- const pItem = primary.results[i];
1986
- const aItem = additional.results[i];
1997
+ for (let i = 0; i < pBatch.length && i < aBatch.length; i++) {
1998
+ const pItem = pBatch[i];
1999
+ const aItem = aBatch[i];
1987
2000
  if (!pItem || !aItem) continue;
1988
2001
 
1989
2002
  const pInner = pItem.result || pItem;
1990
2003
  const aInner = aItem.result || aItem;
1991
2004
 
1992
- if (Array.isArray(pInner.results) && Array.isArray(aInner.results)) {
2005
+ const pResults = Array.isArray(pInner.results) ? pInner.results : Array.isArray(pInner.results_json) ? pInner.results_json : null;
2006
+ const aResults = Array.isArray(aInner.results) ? aInner.results : Array.isArray(aInner.results_json) ? aInner.results_json : null;
2007
+
2008
+ if (pResults && aResults) {
1993
2009
  const existingPaths = new Set(
1994
- pInner.results.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`)
2010
+ pResults.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`)
1995
2011
  );
1996
- for (const r of aInner.results) {
2012
+ for (const r of aResults) {
1997
2013
  const key = `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`;
1998
2014
  if (!existingPaths.has(key)) {
1999
- pInner.results.push(r);
2015
+ pResults.push(r);
2000
2016
  existingPaths.add(key);
2001
2017
  }
2002
2018
  }
2003
- if (pInner.results.length > 1) {
2004
- pInner.results.sort((a, b) => (b.score || 0) - (a.score || 0));
2019
+ if (pResults.length > 1) {
2020
+ pResults.sort((a, b) => (b.score || 0) - (a.score || 0));
2005
2021
  }
2006
- if (typeof pInner.total === "number") pInner.total = pInner.results.length;
2007
- if (typeof pInner.count === "number") pInner.count = pInner.results.length;
2022
+ if (typeof pInner.total === "number") pInner.total = pResults.length;
2023
+ if (typeof pInner.count === "number") pInner.count = pResults.length;
2008
2024
  }
2009
2025
  }
2010
2026
  } catch (_) {}