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): fail truncated in-process output

Hiro-Chiba5e2bdcfa5ae6
diff --git a/ix-cli/src/cli/__tests__/mcp-runner.test.ts b/ix-cli/src/cli/__tests__/mcp-runner.test.ts
index b8e25519..64c78a32 100644
--- a/ix-cli/src/cli/__tests__/mcp-runner.test.ts
+++ b/ix-cli/src/cli/__tests__/mcp-runner.test.ts
@@ -403,7 +403,7 @@ describe("in-process ix runner", () => {
});
});
- it("truncates output instead of growing the server heap without bound", async () => {
+ it("fails the run when output is truncated to protect the server heap", async () => {
const run = createInProcessRunner({
createProgram: createTestProgram,
maxOutputBytes: 500,
@@ -411,6 +411,7 @@ describe("in-process ix runner", () => {
const result = await run(["flood"]);
+ expect(result.ok).toBe(false);
expect(result.stdout.length).toBeLessThanOrEqual(500);
expect(result.stderr).toContain("exceeded 500 bytes and was truncated");
});
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 fb4fb998..16c712eb 100644
--- a/ix-cli/src/cli/__tests__/mcp-structured-output.test.ts
+++ b/ix-cli/src/cli/__tests__/mcp-structured-output.test.ts
@@ -1,9 +1,11 @@
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
+import { Command } from "commander";
import { afterEach, describe, expect, it } from "vitest";
import { createIxMcpServer, type IxRunner } from "../../mcp/server.js";
+import { createInProcessRunner } from "../../mcp/runner.js";
const clients: Client[] = [];
@@ -52,6 +54,33 @@ describe("ix mcp structured output", () => {
expect(result.content[0]).toEqual({ type: "text", text: "not json at all" });
});
+ it("returns an MCP error without structured content when in-process output is truncated", async () => {
+ const runIx = createInProcessRunner({
+ maxOutputBytes: 100,
+ createProgram: () => {
+ const program = new Command();
+ program
+ .command("map")
+ .option("--format <format>")
+ .action(() => console.log(JSON.stringify({ payload: "x".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];
+ expect(content?.type).toBe("text");
+ 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 12929426..691a6c54 100644
--- a/ix-cli/src/mcp/runner.ts
+++ b/ix-cli/src/mcp/runner.ts
@@ -468,7 +468,7 @@ async function executeInProcess(
}
}
- const ok = failure === null && (commandExitCode === undefined || commandExitCode === 0);
+ const ok = !run.truncated && failure === null && (commandExitCode === undefined || commandExitCode === 0);
return {
ok,
stdout: run.stdout.join(""),