@context-engine-bridge/context-engine-mcp-bridge 0.0.32 → 0.0.33

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 +29 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-engine-bridge/context-engine-mcp-bridge",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
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
@@ -74,16 +74,36 @@ const _LSP_ENRICHABLE_TOOLS = new Set([
74
74
  "search_config_for", "search_callers_for", "search_importers_for",
75
75
  ]);
76
76
 
77
- function _extractPaths(obj, paths, depth = 0) {
77
+ function _isAbsolutePath(p) {
78
+ return p.startsWith("/") || /^[a-zA-Z]:[/\\]/.test(p);
79
+ }
80
+
81
+ function _resolveAndContain(relPath, workspace) {
82
+ const resolved = path.resolve(workspace, relPath);
83
+ if (resolved === workspace || resolved.startsWith(workspace + path.sep)) return resolved;
84
+ return null;
85
+ }
86
+
87
+ function _extractPaths(obj, paths, workspace, depth = 0) {
78
88
  if (!obj || typeof obj !== "object" || depth > 20) return;
79
89
  if (Array.isArray(obj)) {
80
- for (const item of obj) _extractPaths(item, paths, depth + 1);
90
+ for (const item of obj) _extractPaths(item, paths, workspace, depth + 1);
81
91
  return;
82
92
  }
83
- if (typeof obj.path === "string" && (obj.path.startsWith("/") || /^[a-zA-Z]:[/\\]/.test(obj.path))) paths.add(obj.path);
93
+ if (typeof obj.path === "string" && obj.path.length > 0) {
94
+ if (_isAbsolutePath(obj.path)) {
95
+ paths.add(obj.path);
96
+ } else if (workspace) {
97
+ const contained = _resolveAndContain(obj.path, workspace);
98
+ if (contained) paths.add(contained);
99
+ }
100
+ } else if (typeof obj.rel_path === "string" && obj.rel_path.length > 0 && workspace) {
101
+ const contained = _resolveAndContain(obj.rel_path, workspace);
102
+ if (contained) paths.add(contained);
103
+ }
84
104
  for (const [key, val] of Object.entries(obj)) {
85
105
  if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
86
- if (val && typeof val === "object") _extractPaths(val, paths, depth + 1);
106
+ if (val && typeof val === "object") _extractPaths(val, paths, workspace, depth + 1);
87
107
  }
88
108
  }
89
109
 
@@ -105,6 +125,7 @@ function _callLspHandler(port, secret, operation, params) {
105
125
  let data = "";
106
126
  let exceeded = false;
107
127
  const MAX_RESP = 5 * 1024 * 1024;
128
+ res.on("error", () => {});
108
129
  res.on("data", chunk => {
109
130
  if (exceeded) return;
110
131
  data += chunk;
@@ -119,7 +140,7 @@ function _callLspHandler(port, secret, operation, params) {
119
140
  });
120
141
  }
121
142
 
122
- async function _enrichWithLsp(result, lspConn) {
143
+ async function _enrichWithLsp(result, lspConn, workspace) {
123
144
  try {
124
145
  if (!Array.isArray(result?.content)) return result;
125
146
  const textBlock = result.content.find(c => c.type === "text");
@@ -128,7 +149,7 @@ async function _enrichWithLsp(result, lspConn) {
128
149
  try { parsed = JSON.parse(textBlock.text); } catch { return result; }
129
150
  if (!parsed.ok) return result;
130
151
  const paths = new Set();
131
- _extractPaths(parsed, paths);
152
+ _extractPaths(parsed, paths, workspace);
132
153
  if (paths.size === 0) return result;
133
154
  const diag = await _callLspHandler(lspConn.port, lspConn.secret, "diagnostics_recent", { paths: [...paths] });
134
155
  if (!diag?.ok || !diag.files || diag.total === 0) return result;
@@ -1094,6 +1115,7 @@ async function createBridgeServer(options) {
1094
1115
  let data = "";
1095
1116
  let exceeded = false;
1096
1117
  const MAX_RESP = 5 * 1024 * 1024;
1118
+ res.on("error", () => {});
1097
1119
  res.on("data", chunk => {
1098
1120
  if (exceeded) return;
1099
1121
  data += chunk;
@@ -1146,7 +1168,7 @@ async function createBridgeServer(options) {
1146
1168
  );
1147
1169
  let finalResult = maybeRemapToolResult(name, result, workspace);
1148
1170
  const lspConn = includeLsp && _readLspConnection(workspace);
1149
- if (lspConn) finalResult = await _enrichWithLsp(finalResult, lspConn);
1171
+ if (lspConn) finalResult = await _enrichWithLsp(finalResult, lspConn, workspace);
1150
1172
  return finalResult;
1151
1173
  } catch (err) {
1152
1174
  lastError = err;