@context-engine-bridge/context-engine-mcp-bridge 0.0.39 → 0.0.42
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 +13 -17
package/package.json
CHANGED
package/src/mcpServer.js
CHANGED
|
@@ -112,24 +112,21 @@ function _resolveAndContain(relPath, workspace) {
|
|
|
112
112
|
return null;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
const _PATH_FIELDS = ["host_path", "path", "rel_path"];
|
|
116
|
+
|
|
115
117
|
function _extractPaths(obj, paths, workspace, depth = 0) {
|
|
116
118
|
if (!obj || typeof obj !== "object" || depth > 20) return;
|
|
117
119
|
if (Array.isArray(obj)) {
|
|
118
120
|
for (const item of obj) _extractPaths(item, paths, workspace, depth + 1);
|
|
119
121
|
return;
|
|
120
122
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
rawPath = obj.path;
|
|
124
|
-
} else if (typeof obj.rel_path === "string" && obj.rel_path.length > 0) {
|
|
125
|
-
rawPath = obj.rel_path;
|
|
126
|
-
}
|
|
127
|
-
if (rawPath) {
|
|
123
|
+
const candidates = _PATH_FIELDS.map(f => obj[f]).filter(v => typeof v === "string" && v.length > 0);
|
|
124
|
+
for (const rawPath of candidates) {
|
|
128
125
|
if (workspace) {
|
|
129
126
|
const contained = _resolveAndContain(rawPath, workspace);
|
|
130
|
-
if (contained) paths.add(contained);
|
|
127
|
+
if (contained) { paths.add(contained); break; }
|
|
131
128
|
} else if (_isAbsolutePath(rawPath)) {
|
|
132
|
-
paths.add(rawPath);
|
|
129
|
+
paths.add(rawPath); break;
|
|
133
130
|
}
|
|
134
131
|
}
|
|
135
132
|
for (const [key, val] of Object.entries(obj)) {
|
|
@@ -156,7 +153,7 @@ function _callLspHandler(port, secret, operation, params) {
|
|
|
156
153
|
let data = "";
|
|
157
154
|
let exceeded = false;
|
|
158
155
|
const MAX_RESP = 5 * 1024 * 1024;
|
|
159
|
-
res.on("error", () => {});
|
|
156
|
+
res.on("error", () => { if (!exceeded) resolve(null); });
|
|
160
157
|
res.on("data", chunk => {
|
|
161
158
|
if (exceeded) return;
|
|
162
159
|
data += chunk;
|
|
@@ -188,8 +185,8 @@ async function _enrichWithLsp(result, lspConn, workspace) {
|
|
|
188
185
|
return result;
|
|
189
186
|
}
|
|
190
187
|
const target = _lspTarget(parsed);
|
|
191
|
-
if (!target.ok) return result;
|
|
192
|
-
|
|
188
|
+
if (!parsed.ok && !target.ok) return result;
|
|
189
|
+
parsed._lsp_status = await _resolveLspStatus(parsed, target, lspConn, workspace);
|
|
193
190
|
textBlock.text = JSON.stringify(parsed);
|
|
194
191
|
return result;
|
|
195
192
|
} catch (err) {
|
|
@@ -199,7 +196,7 @@ async function _enrichWithLsp(result, lspConn, workspace) {
|
|
|
199
196
|
}
|
|
200
197
|
}
|
|
201
198
|
|
|
202
|
-
async function _resolveLspStatus(target, lspConn, workspace) {
|
|
199
|
+
async function _resolveLspStatus(dest, target, lspConn, workspace) {
|
|
203
200
|
if (_lspCircuitOpen()) return "circuit_open";
|
|
204
201
|
const paths = new Set();
|
|
205
202
|
_extractPaths(target, paths, workspace);
|
|
@@ -211,7 +208,7 @@ async function _resolveLspStatus(target, lspConn, workspace) {
|
|
|
211
208
|
}
|
|
212
209
|
_lspCircuitRecordSuccess();
|
|
213
210
|
if (!diag.ok || !diag.files || diag.total === 0) return "no_diagnostics";
|
|
214
|
-
|
|
211
|
+
dest._lsp = { diagnostics: diag.files, total: diag.total };
|
|
215
212
|
return "ok";
|
|
216
213
|
}
|
|
217
214
|
|
|
@@ -1239,7 +1236,7 @@ async function createBridgeServer(options) {
|
|
|
1239
1236
|
let data = "";
|
|
1240
1237
|
let exceeded = false;
|
|
1241
1238
|
const MAX_RESP = 5 * 1024 * 1024;
|
|
1242
|
-
res.on("error", () => {});
|
|
1239
|
+
res.on("error", () => { if (!exceeded) resolve({ ok: false, error: "LSP response stream error" }); });
|
|
1243
1240
|
res.on("data", chunk => {
|
|
1244
1241
|
if (exceeded) return;
|
|
1245
1242
|
data += chunk;
|
|
@@ -1303,8 +1300,7 @@ async function createBridgeServer(options) {
|
|
|
1303
1300
|
const tb = Array.isArray(result?.content) && result.content.find(c => c.type === "text");
|
|
1304
1301
|
if (tb?.text) {
|
|
1305
1302
|
const p = JSON.parse(tb.text);
|
|
1306
|
-
|
|
1307
|
-
t._lsp_status = "not_available";
|
|
1303
|
+
p._lsp_status = "not_available";
|
|
1308
1304
|
tb.text = JSON.stringify(p);
|
|
1309
1305
|
}
|
|
1310
1306
|
} catch (e) { debugLog("[ctxce] LSP not_available inject failed: " + String(e)); }
|