refactor(mcp): simplify tool inputs and inline results

This commit is contained in:
morluto
2026-09-29 11:22:00 +08:00
parent bd0e341572
commit f55c2b9267
70 changed files with 468 additions and 741 deletions
@@ -65,7 +65,6 @@ async function runInlineEvidenceScenarios(
name: "compare_application_versions",
arguments: {
...JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE,
unknown_registry_approved: true,
},
});
expect(compared.isError).not.toBe(true);
@@ -118,7 +118,7 @@ describe("application workflow MCP parity", () => {
result: {
source_evidence_id: left.value.evidence_id,
source_graph_id: analyzed.semantic_graph.graph_id,
summary: { retained_seed_matches: 1 },
summary: { total_seed_matches: 1 },
},
});
} finally {
@@ -61,7 +61,7 @@ describeBrowser("CdpBrowserProvider: document script 1", () => {
artifact: expect.objectContaining({
text: "export const observed = 'source-secret';",
bytes: 40,
uri: expect.stringMatching(/^rea:\/\/web-content\/sha256\//u),
sha256: expect.stringMatching(/^[a-f0-9]{64}$/u),
}),
}),
);
@@ -297,7 +297,7 @@ describeBrowser("CdpBrowserProvider: document script 3", () => {
expect(result.value).toMatchObject({
viewport: { width: 1, height: 1 },
artifact: {
uri: expect.stringMatching(/^rea:\/\/web-screenshot\/sha256\//u),
sha256: expect.stringMatching(/^[a-f0-9]{64}$/u),
bytes: 70,
media_type: "image/png",
},
+1 -1
View File
@@ -18,7 +18,7 @@ afterEach(async () => {
describe("browser CLI parity", () => {
it(
"returns the same Evidence v2 discovery and inspection contracts",
"returns the same Evidence discovery and inspection contracts",
async () => {
const browser = await startFakeCdpBrowser({
sessionTimeline: "same_origin",
-1
View File
@@ -407,7 +407,6 @@ it("returns full artifact graphs inline and compares changed inventories", async
arguments: {
left_evidence_id: evidence.evidence_id,
right_evidence_id: changedEvidence.evidence_id,
unknown_registry_approved: true,
},
});
expect(compared.isError).not.toBe(true);
+1 -1
View File
@@ -27,7 +27,7 @@ afterEach(async () => {
});
it(
"exposes CLI-equivalent Evidence v2 results and session tools",
"exposes CLI-equivalent Evidence results and session tools",
async () => {
const browser = await startFakeCdpBrowser({
sessionTimeline: "same_origin",
+37 -35
View File
@@ -106,7 +106,7 @@ const captureFor = (scenario: BrowserScenario): BrowserScenarioCapture => {
});
};
const scenario = (origin = "https://app.example.test") => ({
const minimalScenario = (origin = "https://app.example.test") => ({
browser: {
mode: "launch",
executable_path: process.execPath,
@@ -116,14 +116,17 @@ const scenario = (origin = "https://app.example.test") => ({
},
start_url: { url: `${origin}/`, query: [] },
allowed_origins: [origin],
environment: {
viewport: { width: 1_280, height: 720 },
locale: "en-US",
timezone: "UTC",
color_scheme: "light",
reduced_motion: "reduce",
service_workers: "block",
},
actions: [
{
step_id: "settle",
action: "wait_for_timeout",
duration_ms: 1,
},
],
});
const scenario = (origin = "https://app.example.test") => ({
...minimalScenario(origin),
actions: [
{
step_id: "login-input",
@@ -132,8 +135,6 @@ const scenario = (origin = "https://app.example.test") => ({
value: { source: "secret", secret_id: "login_input" },
},
],
storage: {},
request_replay: { mode: "disabled" },
secrets: [
{
secret_id: "login_input",
@@ -142,27 +143,6 @@ const scenario = (origin = "https://app.example.test") => ({
redaction: "replace-with-secret-reference",
},
],
redaction: {
secret_values: "replace-with-secret-reference",
query_parameter_names: [],
},
capture: { after_each_step: [], at_end: [], events: [] },
limits: {
max_duration_ms: 10_000,
action_timeout_ms: 1_000,
navigation_timeout_ms: 1_000,
max_events: 100,
max_frames: 10,
max_workers: 5,
max_popups: 2,
max_websockets: 10,
max_dom_nodes: 1_000,
max_accessibility_nodes: 1_000,
max_screenshots: 2,
max_screenshot_bytes: 1_048_576,
max_storage_entries: 100,
max_total_metadata_bytes: 1_048_576,
},
});
describe("browser scenario MCP tool", () => {
@@ -209,6 +189,28 @@ describe("browser scenario MCP tool", () => {
await server.connect(serverTransport);
await client.connect(clientTransport);
const minimal = await client.callTool({
name: "capture_browser_scenario",
arguments: minimalScenario(),
});
expect(minimal.isError, JSON.stringify(minimal)).not.toBe(true);
expect(provider.scenarios[0]).toMatchObject({
environment: { color_scheme: "light", service_workers: "block" },
storage: { cookies: [], local_storage: [], session_storage: [] },
request_replay: { mode: "disabled" },
redaction: {
secret_values: "replace-with-secret-reference",
header_names: [
"authorization",
"cookie",
"proxy-authorization",
"set-cookie",
],
},
capture: { after_each_step: [], at_end: ["url"], events: [] },
limits: { max_duration_ms: 60_000, max_total_metadata_bytes: 4_194_304 },
});
const captured = await client.callTool({
name: "capture_browser_scenario",
arguments: scenario(),
@@ -221,7 +223,7 @@ describe("browser scenario MCP tool", () => {
},
},
});
expect(provider.scenarios).toHaveLength(1);
expect(provider.scenarios).toHaveLength(2);
expect(JSON.stringify(captured.structuredContent)).not.toContain(
"correct horse battery staple",
);
@@ -258,7 +260,7 @@ describe("browser scenario MCP tool", () => {
arguments: scenario("https://other.example.test"),
});
expect(denied.isError).toBe(true);
expect(provider.scenarios).toHaveLength(1);
expect(provider.scenarios).toHaveLength(2);
const unapprovedEnvironment = scenario();
const secretDeclaration = unapprovedEnvironment.secrets.at(0);
@@ -270,6 +272,6 @@ describe("browser scenario MCP tool", () => {
arguments: unapprovedEnvironment,
});
expect(deniedSecret.isError).toBe(true);
expect(provider.scenarios).toHaveLength(1);
expect(provider.scenarios).toHaveLength(2);
});
});
+1 -1
View File
@@ -37,7 +37,7 @@ afterEach(async () => {
);
});
it("exposes root-confined Electron discovery and inspection as Evidence v2", async () => {
it("exposes root-confined Electron discovery and inspection as Evidence", async () => {
const root = await createTestTempDirectory("rea-electron-mcp-");
temporary.push(root);
await writeFile(join(root, "index.html"), "<script src='app.js'></script>");
@@ -188,15 +188,14 @@ describe("enhanced MCP tools", () => {
).toEqual(ENHANCED_TOOL_CONTRACTS.map(({ name }) => name).sort());
});
it("executes all thirteen tools through production registration", async () => {
it("executes all twelve tools through production registration", async () => {
const client = await connect();
const calls = [
["swift_classes", { pattern: "Fixture" }],
["get_objc_classes", { pattern: "Fixture" }],
["get_objc_protocols", {}],
["batch_decompile", { addresses: ["0x1", "0x2"] }],
["get_call_graph", { address: "0x1", direction: "forward" }],
["analyze_swift_types", {}],
["analyze_swift_types", { category: "classes", pattern: "Fixture" }],
["find_xrefs_to_name", { name: "entry" }],
["binary_overview", {}],
["analyze_function", { procedure: "0x1" }],
@@ -212,8 +211,7 @@ describe("enhanced MCP tools", () => {
);
expect(results[0]).toMatchObject({ count: 1 });
expect(results[1]).toMatchObject({ count: 1 });
expect(results[2]).toMatchObject({ count: 1 });
expect(results[3]).toEqual({
expect(results[2]).toEqual({
items: [
{ address: "0x1", status: "ok", pseudocode: "pseudo:0x1" },
{ address: "0x2", status: "ok", pseudocode: "pseudo:0x2" },
@@ -222,31 +220,39 @@ describe("enhanced MCP tools", () => {
succeeded: 2,
failed: 0,
});
expect(results[4]).toEqual({
expect(results[3]).toEqual({
"0": [{ address: "0x1", status: "ok", calls: ["0x2", "0x3"] }],
"1": [
{ address: "0x2", status: "ok", calls: ["0x1"] },
{ address: "0x3", status: "ok", calls: [] },
],
});
expect(results[5]).toMatchObject({ total: 6 });
expect(results[6]).toEqual({
expect(results[4]).toMatchObject({
total: 1,
categories: {
classes: {
count: 1,
items: [{ address: "0x1", name: "_TtC7Fixture5Class" }],
},
},
});
expect(results[5]).toEqual({
status: "resolved",
name: "entry",
address: "0x13",
xrefs: ["0x20", "0x21"],
});
expect(results[7]).toMatchObject({
expect(results[6]).toMatchObject({
document: "fixture",
segment_count: 1,
procedure_count: 6,
string_count: 1,
});
expect(results[8]).toMatchObject({
expect(results[7]).toMatchObject({
procedure: { address: "0x1", name: "entry" },
pseudocode: "return 0;",
});
expect(results[9]).toMatchObject({
expect(results[8]).toMatchObject({
procedure: { address: "0x1", name: "entry" },
boundary: { available: false },
unsupported_branches: [
@@ -262,7 +268,7 @@ describe("enhanced MCP tools", () => {
{ operation: "preserve_residual_unknowns", status: "completed" },
],
});
expect(results[10]).toMatchObject({
expect(results[9]).toMatchObject({
query: "hello",
search_mode: "literal",
truncated: false,
@@ -271,12 +277,12 @@ describe("enhanced MCP tools", () => {
{ target_address: "0x30", source_address: "0x21" },
],
});
expect(results[11]).toMatchObject({
expect(results[10]).toMatchObject({
query: "hello",
matches: [{ type: "string", address: "0x30", value: "hello" }],
truncated: false,
});
expect(results[12]).toMatchObject({
expect(results[11]).toMatchObject({
start: "0x1",
goal: "0x2",
direction: "forward",
@@ -278,10 +278,13 @@ describe("enhanced MCP tools", () => {
},
});
const result = jsonResult(
await client.callTool({ name: "swift_classes", arguments: {} }),
await client.callTool({ name: "analyze_swift_types", arguments: {} }),
);
expect(calls).toEqual(["list_procedures"]);
expect(result).toMatchObject({ count: 2 });
expect(result).toMatchObject({
total: 2,
categories: { classes: { count: 2 } },
});
});
it("returns cancellation when a complete inventory call is cancelled", async () => {
@@ -296,7 +299,7 @@ describe("enhanced MCP tools", () => {
};
const result = await new EnhancedTools(analysis).execute(
"swift_classes",
"analyze_swift_types",
{},
controller.signal,
);
@@ -269,7 +269,7 @@ describe("enhanced MCP tools", () => {
),
});
const result = await client.callTool({
name: "swift_classes",
name: "analyze_swift_types",
arguments: {},
});
expect(result.isError).toBe(true);
@@ -180,30 +180,4 @@ describe("enhanced MCP tools", () => {
JSON.stringify(result.structuredContent),
);
});
it("rejects legacy paged collection wrappers", async () => {
const malformedPort = fixturePort();
const client = await connect({
execute: async (name, arguments_, options) => {
const result = await malformedPort.execute(name, arguments_, options);
if (!result.ok || name !== "analyze_function") return result;
const dossier = result.value.result;
if (
typeof dossier !== "object" ||
dossier === null ||
Array.isArray(dossier)
)
return result;
return ok({
...dossier,
callers: { items: [], total: 1, returned: 0 },
});
},
});
const result = await client.callTool({
name: "analyze_function",
arguments: { procedure: "0x1" },
});
expect(result.isError).toBe(true);
});
});
@@ -177,7 +177,7 @@ describe("enhanced MCP input validation", () => {
execute: () => Promise.resolve(ok(["not", "a", "procedure", "map"])),
});
const result = await client.callTool({
name: "swift_classes",
name: "analyze_swift_types",
arguments: {},
});
expect(result.isError).toBe(true);
@@ -8,7 +8,7 @@ import { createServer } from "../../../src/server/createServer.js";
import { observed } from "../../fixtures/analysisExecution.js";
describe("function comparison MCP integration", () => {
it("records linked comparison Evidence and an approved residual unknown", async () => {
it("records linked comparison Evidence and its residual unknown", async () => {
const session = createTestBinarySession(() => ({
health: () => Promise.resolve(),
execute: () => Promise.resolve(observed(null)),
@@ -35,7 +35,6 @@ describe("function comparison MCP integration", () => {
arguments: {
left_evidence_id: FUNCTION_COMPARISON_EXAMPLE.left.evidence_id,
right_evidence_id: FUNCTION_COMPARISON_EXAMPLE.right.evidence_id,
unknown_registry_approved: true,
},
});
expect(result.isError).not.toBe(true);
@@ -40,7 +40,6 @@ describe("Ghidra MCP capability routing", () => {
name: "binary_overview",
available: true,
}),
expect.objectContaining({ name: "swift_classes", available: true }),
expect.objectContaining({
name: "get_objc_classes",
available: true,
@@ -38,7 +38,6 @@ it("aggregates comparison Evidence and records an approved runtime gap", async (
name: "find_changed_behavior",
arguments: {
comparisons: [comparison],
unknown_registry_approved: true,
},
});
expect(response.isError, JSON.stringify(response)).not.toBe(true);
@@ -123,7 +122,6 @@ it("records a safe unresolved call-path question", async () => {
functions: [dossier],
start: { address: "0x1000" },
goal: { address: "0x3000" },
unknown_registry_approved: true,
},
});
expect(response.isError, JSON.stringify(response)).not.toBe(true);
@@ -197,7 +195,6 @@ it("uses inline assembly observations without recording a false unknown", async
},
},
],
unknown_registry_approved: true,
},
});
expect(response.isError).not.toBe(true);
@@ -222,7 +219,6 @@ it("passes only the finite declared reconstruction specification", async () => {
name: "verify_reconstruction",
arguments: {
...INVESTIGATION_EXAMPLES.verify_reconstruction,
unknown_registry_approved: true,
},
});
expect(response.isError).not.toBe(true);
@@ -271,7 +267,6 @@ it("cannot omit a session-owned active unknown from reconstruction input", async
name: "verify_reconstruction",
arguments: {
...INVESTIGATION_EXAMPLES.verify_reconstruction,
unknown_registry_approved: true,
},
});
expect(response.isError).not.toBe(true);
@@ -42,7 +42,6 @@ const capture = {
],
} as const;
const traceSpecification: ProcessTraceSpecification = {
version: 1,
events: [
{
id: "before",
@@ -60,8 +60,6 @@ const statusCapability = (
} = { available: true },
) => ({
operation,
input_contract_version: 1,
output_contract_version: 1,
effects: {
mutates_artifact: false,
launches_process: false,
+3 -17
View File
@@ -75,7 +75,7 @@ const structured = (result: CallToolResult): Record<string, unknown> => {
return Object.fromEntries(Object.entries(result.structuredContent));
};
it("records approved typed capability unavailability without forwarding the flag", async () => {
it("does not record capability unavailability without supporting Evidence", async () => {
const received: Array<Readonly<Record<string, unknown>>> = [];
const analysis: AnalysisOperationPort = {
execute: (name, arguments_) => {
@@ -110,7 +110,6 @@ it("records approved typed capability unavailability without forwarding the flag
name: "procedure_pseudo_code",
arguments: {
procedure: "main",
unknown_registry_approved: true,
},
});
expect(unavailable.isError).toBe(true);
@@ -119,24 +118,12 @@ it("records approved typed capability unavailability without forwarding the flag
category: "unsupported_provider",
},
});
expect(received[0]).not.toHaveProperty("unknown_registry_approved");
expect(received[0]).toMatchObject({ procedure: "main" });
expect(
structured(await client.callTool({ name: "list_unknowns", arguments: {} })),
).toMatchObject({
result: {
items: [
{
domain: "analysis-capability",
question:
"The requested analysis is unavailable for the current target.",
recommended_probes: [
{
rationale:
"Choose another analysis or target that can answer this question.",
},
],
},
],
items: [],
},
});
});
@@ -214,7 +201,6 @@ it("records approved capture disagreement as a contradicted unknown", async () =
arguments: {
left_evidence_id: leftEvidence.evidence_id,
right_evidence_id: rightEvidence.evidence_id,
unknown_registry_approved: true,
},
});
expect(compared.isError).not.toBe(true);
@@ -43,6 +43,32 @@ const structured = (result: CallToolResult): Record<string, unknown> => {
return Object.fromEntries(Object.entries(result.structuredContent));
};
it("advertises the native function discovery-to-dossier workflow", async () => {
const client = await connect({
execute: () => Promise.resolve(ok(null)),
});
expect(client.getInstructions()).toContain(
"call binary_overview for target metadata and inventory counts, then search_procedures or list_procedures to choose a function",
);
const tools = new Map(
(await client.listTools()).tools.map((tool) => [tool.name, tool]),
);
expect(tools.get("binary_overview")?.description).toContain(
"follow with search_procedures or list_procedures, then pass a returned name or address to analyze_function",
);
expect(tools.get("analyze_function")?.description).toContain(
"typically selected from search_procedures or list_procedures",
);
expect(tools.get("analyze_function")?.inputSchema.properties).toHaveProperty(
"procedure",
);
expect(tools.get("inspect_native_api")?.description).toContain(
"use analyze_function for a general function dossier",
);
});
it("executes a realistic workflow: list methods, decompile selected, get xrefs", async () => {
const client = await connect({
execute: (name, args) => {
+1 -2
View File
@@ -229,7 +229,7 @@ describe("target-free MCP workflow", () => {
});
describe("process residuals over MCP", () => {
it("records approved process residuals in the unknown registry", async () => {
it("records process residuals linked to capture Evidence", async () => {
if (!(await probeProcessCaptureCapability()).available) return;
const session = createTestBinarySession(() => client("fixture", []));
const server = createServer(session, session, {
@@ -252,7 +252,6 @@ describe("process residuals over MCP", () => {
const captured = await mcp.callTool({
name: "capture_process_scenario",
arguments: {
unknown_registry_approved: true,
executable: process.execPath,
arguments: [processFixture, "partial"],
working_directory: dirname(processFixture),