From 360892a7bd4968366de4aea32d5d8173f27560ad Mon Sep 17 00:00:00 2001 From: Reese Date: Sat, 13 Dec 2025 01:19:11 +0000 Subject: [PATCH] fix(bridge): make repo_search path mapping visible for compact + structured results - Derive mapping inputs from hit.path when host_path/container_path are missing (compact hits) - When override is enabled, set hit.path to client_path so IDEs display user-local absolute paths - Always rewrite content[].text JSON even when structuredContent is present --- ctx-mcp-bridge/src/resultPathMapping.js | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/ctx-mcp-bridge/src/resultPathMapping.js b/ctx-mcp-bridge/src/resultPathMapping.js index 97f30ce3..f091ccaf 100644 --- a/ctx-mcp-bridge/src/resultPathMapping.js +++ b/ctx-mcp-bridge/src/resultPathMapping.js @@ -102,8 +102,15 @@ function remapHitPaths(hit, workspaceRoot) { if (!hit || typeof hit !== "object") { return hit; } - const hostPath = typeof hit.host_path === "string" ? hit.host_path : ""; - const containerPath = typeof hit.container_path === "string" ? hit.container_path : ""; + const rawPath = typeof hit.path === "string" ? hit.path : ""; + let hostPath = typeof hit.host_path === "string" ? hit.host_path : ""; + let containerPath = typeof hit.container_path === "string" ? hit.container_path : ""; + if (!hostPath && rawPath) { + hostPath = rawPath; + } + if (!containerPath && rawPath) { + containerPath = rawPath; + } const relPath = computeWorkspaceRelativePath(containerPath, hostPath); const out = { ...hit }; if (relPath) { @@ -158,8 +165,12 @@ function remapHitPaths(hit, workspaceRoot) { } } const overridePath = envTruthy(process.env.CTXCE_BRIDGE_OVERRIDE_PATH, true); - if (overridePath && relPath) { - out.path = relPath; + if (overridePath) { + if (typeof out.client_path === "string" && out.client_path) { + out.path = out.client_path; + } else if (relPath) { + out.path = relPath; + } } return out; } @@ -302,24 +313,25 @@ export function maybeRemapToolResult(name, result, workspaceRoot) { } const mapped = applyPathMappingToPayload(parsed.value, workspaceRoot); + let outResult = result; if (parsed.mode === "structured") { - return { ...result, structuredContent: mapped }; + outResult = { ...result, structuredContent: mapped }; } // Replace text payload for clients that only read `content[].text` try { - const content = Array.isArray(result.content) ? result.content.slice() : []; + const content = Array.isArray(outResult.content) ? outResult.content.slice() : []; const idx = content.findIndex( (c) => c && c.type === "text" && typeof c.text === "string", ); if (idx >= 0) { content[idx] = { ...content[idx], text: JSON.stringify(mapped) }; - return { ...result, content }; + outResult = { ...outResult, content }; } } catch { // ignore } - return result; + return outResult; } catch { return result; }