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): cap thrown error output

Hiro-Chiba033181fb5747
diff --git a/ix-cli/src/cli/__tests__/mcp-runner.test.ts b/ix-cli/src/cli/__tests__/mcp-runner.test.ts
index 64c78a32..05eb78fe 100644
--- a/ix-cli/src/cli/__tests__/mcp-runner.test.ts
+++ b/ix-cli/src/cli/__tests__/mcp-runner.test.ts
@@ -416,6 +416,26 @@ describe("in-process ix runner", () => {
expect(result.stderr).toContain("exceeded 500 bytes and was truncated");
});
+ it("applies the output cap to thrown error messages", async () => {
+ const run = createInProcessRunner({
+ maxOutputBytes: 500,
+ createProgram: () => {
+ const program = new Command();
+ program.command("throw-long").action(() => {
+ throw new Error("E".repeat(2_000));
+ });
+ return program;
+ },
+ });
+
+ const result = await run(["throw-long"]);
+
+ expect(result.ok).toBe(false);
+ expect(Buffer.byteLength(result.stderr)).toBeLessThanOrEqual(500);
+ expect(result.stderr).toContain("exceeded 500 bytes and was truncated");
+ expect(result.stderr).not.toContain("E".repeat(500));
+ });
+
it("reports an unknown command as a failure with commander's message", async () => {
const run = testRunner();
diff --git a/ix-cli/src/cli/__tests__/mcp-structured-output.test.ts b/ix-cli/src/cli/__tests__/mcp-structured-output.test.ts
index 16c712eb..dab0e853 100644
--- a/ix-cli/src/cli/__tests__/mcp-structured-output.test.ts
+++ b/ix-cli/src/cli/__tests__/mcp-structured-output.test.ts
@@ -81,6 +81,34 @@ describe("ix mcp structured output", () => {
});
});
+ it("caps thrown command errors before returning them through MCP", async () => {
+ const runIx = createInProcessRunner({
+ maxOutputBytes: 100,
+ createProgram: () => {
+ const program = new Command();
+ program
+ .command("map")
+ .option("--format <format>")
+ .action(() => {
+ throw new Error("E".repeat(500));
+ });
+ return program;
+ },
+ });
+ const client = await connect(runIx);
+
+ const result = (await client.callTool({ name: "ix_map", arguments: {} })) as CallToolResult;
+
+ expect(result.isError).toBe(true);
+ expect(result.structuredContent).toBeUndefined();
+ const content = result.content[0];
+ const error = JSON.parse(content?.type === "text" ? content.text : "{}");
+ expect(error).toEqual({
+ error: "[ix mcp] output exceeded 100 bytes and was truncated",
+ tool: "ix_map",
+ });
+ });
+
it("exposes the filtered smell candidates as structuredContent", async () => {
const client = await connect(async () => ({
ok: true,
diff --git a/ix-cli/src/mcp/runner.ts b/ix-cli/src/mcp/runner.ts
index 691a6c54..7f850539 100644
--- a/ix-cli/src/mcp/runner.ts
+++ b/ix-cli/src/mcp/runner.ts
@@ -422,6 +422,7 @@ async function executeInProcess(
} finally {
commandExitCode = commandExitCode ?? (exitCodeIsOurs ? process.exitCode : undefined);
process.exitCode = callerExitCode;
+ if (failure !== null) appendChunk(run, "stderr", failure);
run.closed = true;
activeRun = null;
@@ -472,7 +473,7 @@ async function executeInProcess(
return {
ok,
stdout: run.stdout.join(""),
- stderr: run.stderr.join("") + (failure ?? ""),
+ stderr: run.stderr.join(""),
};
}