feat(ida): add read-only GUI and headless MCP providers (#754)

This commit is contained in:
N0zoM1z0
2026-10-07 01:47:05 +08:00
committed by GitHub
parent c8e66c704a
commit 8238232485
50 changed files with 3770 additions and 43 deletions
@@ -37,6 +37,7 @@ import {
GHIDRA_PROVIDER_TOOL_CONTRACTS,
} from "../../../src/ghidra/GhidraProvider.js";
import { NATIVE_MACOS_PROVIDER_IDENTITY } from "../../../src/native/NativeMacOSProvider.js";
import { IDA_PROVIDER_IDENTITY } from "../../../src/ida/IdaProvider.js";
import {
assertDocumentationFacts,
documentationFactIssues,
@@ -101,6 +102,7 @@ describe("canonical product catalog", () => {
BINWALK_PROVIDER_IDENTITY,
UNBLOB_PROVIDER_IDENTITY,
GHIDRA_PROVIDER_IDENTITY,
IDA_PROVIDER_IDENTITY,
NATIVE_MACOS_PROVIDER_IDENTITY,
ARTIFACT_GRAPH_PROVIDER,
MANAGED_STATIC_PROVIDER,
@@ -49,7 +49,7 @@ describe("direct analysis snapshot files", () => {
details: {
selection_reason: "unknown_provider",
requested_provider_id: "request-provider",
candidate_ids: ["ghidra", "hopper"],
candidate_ids: ["ghidra", "hopper", "ida"],
},
});
});
+7 -4
View File
@@ -97,7 +97,7 @@ describe("Ghidra MCP evidence parity", () => {
);
expect(analyzed).toMatchObject({
operation: "analyze_function",
provider: { id: "rea-workflow", version: "1" },
provider: { id: "ghidra", version: "12.1.4" },
normalized_result: {
procedure: {
address: "0x401000",
@@ -121,9 +121,12 @@ describe("Ghidra MCP evidence parity", () => {
),
]),
},
limitations: [
"Derived by an REA workflow from one or more provider observations.",
],
limitations: expect.arrayContaining([
expect.stringContaining("default auto-analysis complete"),
expect.stringContaining(
"original executable bytes are never written",
),
]),
});
const directAnalyzed = await new EnhancedTools(session).execute(
"analyze_function",
+137
View File
@@ -0,0 +1,137 @@
import { createServer } from "node:http";
import { afterEach, expect, it } from "vitest";
import { z } from "zod";
import { createIdaMcpConnection } from "../../../src/ida/IdaMcpConnection.js";
import type { IdaMcpConnection } from "../../../src/ida/IdaMcpConnection.js";
const cleanups: (() => Promise<void>)[] = [];
afterEach(async () => {
for (const cleanup of cleanups.splice(0).reverse()) await cleanup();
});
const requestSchema = z.object({
id: z.union([z.string(), z.number()]).optional(),
method: z.string(),
params: z
.object({
protocolVersion: z.string().optional(),
cursor: z.string().optional(),
})
.passthrough()
.optional(),
});
const fixture = async (redirectUrl?: string, cycle = false) => {
const methods: string[] = [];
const headers: (string | undefined)[] = [];
const server = createServer(async (request, response) => {
if (redirectUrl !== undefined) {
response.writeHead(307, { Location: redirectUrl });
response.end();
return;
}
if (request.method !== "POST") {
response.writeHead(405);
response.end();
return;
}
let body = "";
for await (const chunk of request) body += String(chunk);
const input = requestSchema.parse(JSON.parse(body));
methods.push(input.method);
headers.push(request.headers.authorization);
if (input.id === undefined) {
response.writeHead(202);
response.end();
return;
}
const result =
input.method === "initialize"
? {
protocolVersion: input.params?.protocolVersion,
capabilities: { tools: {} },
serverInfo: {
name: "ida-transport-fixture",
version: "observed-server-version",
},
}
: input.method === "tools/list"
? {
tools: [
{
name: input.params?.cursor === undefined ? "first" : "second",
inputSchema: { type: "object", properties: {} },
},
],
...(input.params?.cursor === undefined
? { nextCursor: "next-page" }
: cycle
? {
nextCursor:
input.params.cursor === "next-page"
? "other-page"
: "next-page",
}
: {}),
}
: { content: [], structuredContent: { observed: true } };
response.writeHead(200, { "Content-Type": "application/json" });
response.end(JSON.stringify({ jsonrpc: "2.0", id: input.id, result }));
});
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
cleanups.push(
() =>
new Promise<void>((resolve, reject) => {
server.close((error) =>
error === undefined ? resolve() : reject(error),
);
server.closeAllConnections();
}),
);
const address = server.address();
if (address === null || typeof address === "string")
throw new Error("Missing HTTP fixture address");
const connection: IdaMcpConnection = createIdaMcpConnection({
url: `http://127.0.0.1:${address.port}/mcp`,
headers: { Authorization: "Bearer transport-fixture-secret" },
mode: "headless",
timeoutMs: 2000,
});
cleanups.push(() => connection.close());
return {
connection,
methods,
headers,
url: `http://127.0.0.1:${address.port}/mcp`,
};
};
it("uses the pinned SDK for a local Streamable HTTP handshake, paged discovery, structured results, and configured authentication", async () => {
const { connection, methods, headers } = await fixture();
expect(await connection.connect()).toEqual(["first", "second"]);
expect(connection.serverInfo()).toEqual({
name: "ida-transport-fixture",
version: "observed-server-version",
});
expect(await connection.call("first", {})).toEqual({ observed: true });
expect(methods).toContain("notifications/initialized");
expect(methods.filter((name) => name === "tools/list")).toHaveLength(2);
expect(
headers.every((value) => value === "Bearer transport-fixture-secret"),
).toBe(true);
});
it("rejects redirects instead of forwarding transport credentials to another endpoint", async () => {
const destination = await fixture();
const { connection } = await fixture(destination.url);
await expect(connection.connect()).rejects.toThrow();
expect(destination.headers).toEqual([]);
});
it("rejects nonterminating SDK pagination instead of returning a partial tool catalog", async () => {
const { connection, methods } = await fixture(undefined, true);
await expect(connection.connect()).rejects.toThrow(
"pagination did not terminate",
);
expect(
methods.filter((method) => method === "tools/list").length,
).toBeGreaterThan(2);
});