Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(mcp): flag semantic CLI errors (#490)

Hiro-Chibaa7fc07c7e2d8
diff --git a/ix-cli/src/cli/__tests__/mcp.test.ts b/ix-cli/src/cli/__tests__/mcp.test.ts
index 25a4678c..49bd0e79 100644
--- a/ix-cli/src/cli/__tests__/mcp.test.ts
+++ b/ix-cli/src/cli/__tests__/mcp.test.ts
@@ -108,9 +108,43 @@ describe("ix mcp", () => {
});
expect(calls).toEqual([["locate", "--format=llm", "--", "Widget"]]);
+ expect(result.isError).toBeFalsy();
expect(result.content).toEqual([{ type: "text", text: "match name=Widget" }]);
});
+ it("marks a structured LLM error as an MCP error when the CLI exits successfully", async () => {
+ const error = 'error code=unknown_target message="No graph entity found for \\"Missing\\"."';
+ const client = await connect(async () => ({
+ ok: true,
+ stdout: error,
+ stderr: 'No entity found matching "Missing".',
+ }));
+
+ const result = await client.callTool({
+ name: "ix_locate",
+ arguments: { symbol: "Missing" },
+ });
+
+ expect(result.isError).toBe(true);
+ expect(result.content).toEqual([{ type: "text", text: error }]);
+ });
+
+ it("keeps error-like source lines after a successful LLM record as data", async () => {
+ const output = [
+ "content target=fixture.ts lines=1",
+ 'error code=source_text message="This is source, not a tool error."',
+ ].join("\n");
+ const client = await connect(async () => ({ ok: true, stdout: output, stderr: "" }));
+
+ const result = await client.callTool({
+ name: "ix_read",
+ arguments: { symbol: "fixture.ts" },
+ });
+
+ expect(result.isError).toBeFalsy();
+ expect(result.content).toEqual([{ type: "text", text: output }]);
+ });
+
it("forwards ix_context target and bounded budgets as the CLI contract", async () => {
const calls: string[][] = [];
const client = await connect(async (args) => {
diff --git a/ix-cli/src/mcp/server.ts b/ix-cli/src/mcp/server.ts
index d3fa75e9..65ca0b3a 100644
--- a/ix-cli/src/mcp/server.ts
+++ b/ix-cli/src/mcp/server.ts
@@ -553,7 +553,14 @@ async function runFormatted(
argv: IxArgv,
timeoutMs = DEFAULT_TIMEOUT_MS,
): Promise<CallToolResult> {
- return runCommand(runIx, tool, toArgv(argv, "llm"), timeoutMs);
+ const result = await runCommand(runIx, tool, toArgv(argv, "llm"), timeoutMs);
+ if (result.isError) return result;
+
+ const first = result.content[0];
+ // Only the leading record governs status. `ix_read` may contain error-like
+ // source lines after its successful `content` record.
+ const semanticError = first?.type === "text" && first.text.startsWith("error code=");
+ return semanticError ? { ...result, isError: true } : result;
}
async function runJson(