@context-engine-bridge/context-engine-mcp-bridge 0.0.60 → 0.0.63
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/package.json +1 -1
- package/src/mcpServer.js +44 -20
package/package.json
CHANGED
package/src/mcpServer.js
CHANGED
|
@@ -1859,22 +1859,35 @@ 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
|
-
const
|
|
1873
|
-
const
|
|
1887
|
+
const aInner = _unwrapSearchEnvelope(additional);
|
|
1888
|
+
const pResults = _getResultsArray(pInner);
|
|
1889
|
+
const aResults = _getResultsArray(aInner);
|
|
1874
1890
|
if (pResults && aResults) {
|
|
1875
|
-
if (!Array.isArray(primary.results)) {
|
|
1876
|
-
primary.results_json = pResults;
|
|
1877
|
-
}
|
|
1878
1891
|
const existingPaths = new Set(
|
|
1879
1892
|
pResults.map(r => `${r.path || ""}:${r.start_line || 0}:${r.symbol || ""}`)
|
|
1880
1893
|
);
|
|
@@ -1885,46 +1898,57 @@ function _mergeResults(primaryText, additionalTexts) {
|
|
|
1885
1898
|
existingPaths.add(key);
|
|
1886
1899
|
}
|
|
1887
1900
|
}
|
|
1888
|
-
if (
|
|
1889
|
-
|
|
1901
|
+
if (Array.isArray(pInner.results_json)) {
|
|
1902
|
+
pInner.results_json = pResults;
|
|
1903
|
+
} else if (Array.isArray(pInner.results)) {
|
|
1904
|
+
pInner.results = pResults;
|
|
1890
1905
|
} else {
|
|
1891
|
-
|
|
1906
|
+
pInner.results_json = pResults;
|
|
1892
1907
|
}
|
|
1893
1908
|
}
|
|
1894
1909
|
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
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;
|
|
1898
1913
|
}
|
|
1899
|
-
if (typeof
|
|
1900
|
-
|
|
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;
|
|
1901
1917
|
}
|
|
1902
1918
|
} catch (_) {}
|
|
1903
1919
|
}
|
|
1904
1920
|
|
|
1905
|
-
const resultsArr =
|
|
1921
|
+
const resultsArr = _getResultsArray(pInner);
|
|
1906
1922
|
if (Array.isArray(resultsArr) && resultsArr.length > 1) {
|
|
1907
1923
|
resultsArr.sort((a, b) => (b.score || 0) - (a.score || 0));
|
|
1908
1924
|
}
|
|
1909
1925
|
|
|
1910
|
-
const originalLimit = primary._original_limit;
|
|
1926
|
+
const originalLimit = primary._original_limit || (pInner._original_limit);
|
|
1911
1927
|
if (originalLimit && Array.isArray(resultsArr) && resultsArr.length > originalLimit) {
|
|
1912
1928
|
const sliced = resultsArr.slice(0, originalLimit);
|
|
1913
|
-
if (Array.isArray(
|
|
1914
|
-
|
|
1929
|
+
if (Array.isArray(pInner.results_json)) {
|
|
1930
|
+
pInner.results_json = sliced;
|
|
1915
1931
|
} else {
|
|
1916
|
-
|
|
1932
|
+
pInner.results = sliced;
|
|
1917
1933
|
}
|
|
1918
|
-
if (typeof
|
|
1919
|
-
if (typeof
|
|
1934
|
+
if (typeof pInner.total === "number") pInner.total = sliced.length;
|
|
1935
|
+
if (typeof pInner.count === "number") pInner.count = sliced.length;
|
|
1920
1936
|
}
|
|
1921
1937
|
|
|
1922
1938
|
primary._cross_collection = true;
|
|
1939
|
+
const _aFirst = additionalTexts.length > 0 ? (() => { try { const a = JSON.parse(additionalTexts[0]); const ai = _unwrapSearchEnvelope(a); return { keys: Object.keys(ai), results_type: typeof ai.results, results_json_type: typeof ai.results_json, results_is_array: Array.isArray(ai.results), results_json_is_array: Array.isArray(ai.results_json) }; } catch(_) { return "parse_error"; } })() : null;
|
|
1923
1940
|
primary._fanout_debug = {
|
|
1924
1941
|
additional_texts_count: additionalTexts.length,
|
|
1925
1942
|
additional_ok_count: additionalTexts.filter(t => { try { return JSON.parse(t).ok; } catch(_) { return false; } }).length,
|
|
1926
1943
|
final_results_count: Array.isArray(resultsArr) ? resultsArr.length : 0,
|
|
1927
1944
|
original_limit: originalLimit || null,
|
|
1945
|
+
envelope: pInner !== primary,
|
|
1946
|
+
p_inner_keys: Object.keys(pInner),
|
|
1947
|
+
p_results_type: typeof pInner.results,
|
|
1948
|
+
p_results_json_type: typeof pInner.results_json,
|
|
1949
|
+
p_results_is_array: Array.isArray(pInner.results),
|
|
1950
|
+
p_results_json_is_array: Array.isArray(pInner.results_json),
|
|
1951
|
+
a_first: _aFirst,
|
|
1928
1952
|
};
|
|
1929
1953
|
return JSON.stringify(primary);
|
|
1930
1954
|
} catch (_) {
|