fix(mcp): deliver typed errors without invalid structured output (#1277)
* fix(mcp): deliver tool errors within advertised schema contracts Retain complete typed JSON error content while omitting non-conforming structured errors at the public transport boundary. Recover oversized diagnostics into Evidence before removing their private structured carrier. Update schema-validated client readers and cover actual stdio delivery. Closes #1261 Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * test(mcp): read typed errors in canonical Evidence regressions * test(mcp): validate public error diagnostics in acceptance workflows
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { parseMcpToolError } from "../fixtures/mcpToolError.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
@@ -67,8 +68,8 @@ for (const { jarConfigured, setting } of [
|
||||
arguments: { path: apk },
|
||||
});
|
||||
expect(response.isError).toBe(true);
|
||||
expect(response.structuredContent).toEqual({ error: cliResult.json });
|
||||
expect(JSON.stringify(response.structuredContent)).toContain(setting);
|
||||
expect(parseMcpToolError(response)).toEqual({ error: cliResult.json });
|
||||
expect(JSON.stringify(parseMcpToolError(response))).toContain(setting);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -92,8 +93,8 @@ cliTest.skipIf(process.platform !== "linux")(
|
||||
arguments: { path },
|
||||
});
|
||||
expect(response.isError).toBe(true);
|
||||
expect(response.structuredContent).toEqual({ error: cliResult.json });
|
||||
expect(JSON.stringify(response.structuredContent)).toContain(
|
||||
expect(parseMcpToolError(response)).toEqual({ error: cliResult.json });
|
||||
expect(JSON.stringify(parseMcpToolError(response))).toContain(
|
||||
"REA_BINWALK_COMMAND",
|
||||
);
|
||||
},
|
||||
@@ -145,8 +146,8 @@ cliTest(
|
||||
arguments: { path, output_directory: join(root, "output") },
|
||||
});
|
||||
expect(response.isError).toBe(true);
|
||||
expect(response.structuredContent).toEqual({ error: cliResult.json });
|
||||
expect(JSON.stringify(response.structuredContent)).toContain(
|
||||
expect(parseMcpToolError(response)).toEqual({ error: cliResult.json });
|
||||
expect(JSON.stringify(parseMcpToolError(response))).toContain(
|
||||
"REA_WAKARU_COMMAND",
|
||||
);
|
||||
},
|
||||
@@ -183,7 +184,7 @@ cliTest(
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(response.isError).toBe(true);
|
||||
expect(response.structuredContent).toEqual({ error: result.json });
|
||||
expect(parseMcpToolError(response)).toEqual({ error: result.json });
|
||||
expect(result.json).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { expect, it } from "vitest";
|
||||
|
||||
import { WEB_NETWORK_CAPTURE_LIMITS } from "../../../src/domain/webNetworkCapture.js";
|
||||
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
@@ -56,7 +57,7 @@ it("reports real HAR heap exhaustion through CLI and MCP and preserves server us
|
||||
sensitive_values: ["caller-marked"],
|
||||
});
|
||||
expect(response.isError).toBe(true);
|
||||
expect(response.structuredContent).toMatchObject({
|
||||
expect(parseMcpToolError(response)).toMatchObject({
|
||||
error: {
|
||||
code: "resource_constraint",
|
||||
retryable: false,
|
||||
@@ -110,7 +111,7 @@ it("reports real HAR heap exhaustion through CLI and MCP and preserves server us
|
||||
capture_path: path,
|
||||
format: "har",
|
||||
});
|
||||
expect(oversized.structuredContent).toMatchObject({
|
||||
expect(parseMcpToolError(oversized)).toMatchObject({
|
||||
error: { code: "invalid_request" },
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
@@ -6,6 +6,7 @@ import { expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
it("observes a real Node Inspector and releases attachments after cancellation and failures", async () => {
|
||||
@@ -62,7 +63,7 @@ it("observes a real Node Inspector and releases attachments after cancellation a
|
||||
target_id: "../missing-target",
|
||||
});
|
||||
expect(missing.isError).toBe(true);
|
||||
expect(missing.structuredContent).toMatchObject({
|
||||
expect(parseMcpToolError(missing)).toMatchObject({
|
||||
error: {
|
||||
code: "target_unavailable",
|
||||
message: expect.stringContaining("Refresh target discovery"),
|
||||
@@ -114,7 +115,7 @@ it("observes a real Node Inspector and releases attachments after cancellation a
|
||||
inspector_endpoint: endpoint,
|
||||
});
|
||||
expect(unreachable.isError).toBe(true);
|
||||
expect(unreachable.structuredContent).toMatchObject({
|
||||
expect(parseMcpToolError(unreachable)).toMatchObject({
|
||||
error: {
|
||||
code: "provider_unavailable",
|
||||
message: expect.stringContaining(
|
||||
|
||||
@@ -9,6 +9,7 @@ import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { itWithCaptureCapability as captureTest } from "../../boundary/process/processCaptureCapability.js";
|
||||
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
@@ -180,7 +181,7 @@ captureTest(
|
||||
const failed = await call("capture_process_scenario", {
|
||||
executable: missing,
|
||||
});
|
||||
expect(failed.structuredContent).toMatchObject({
|
||||
expect(parseMcpToolError(failed)).toMatchObject({
|
||||
error: {
|
||||
code: "process_capture_failed",
|
||||
message: expect.stringContaining(missing),
|
||||
|
||||
Reference in New Issue
Block a user