Repository navigation
feat(ida): support the official Hex-Rays IDA MCP headlessly - #4813
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] No new blocking code issue was found; the documented licensed-provider checks remain pending before integration. SummaryAdds the optional
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Selected executable or saved database] --> B[Create and verify private copy]
B --> C[Open Hex-Rays lease]
C --> D[Check inventory and backend]
D --> E[Check target identity]
E --> F[Run fixed read-only query]
F --> G[Keep result and source details]
G --> H[Release owned lease]
H --> I{Lease or workspace path still listed?}
I -- Yes --> J[Retain workspace for retry]
I -- No --> K[Close connection and remove workspace]
Reviews (22) · Last reviewed commit: "fix(ida): retain the worker backend in p..." · Reviewed by Greptile |
Hex-Rays IDA MCP serves database reads only through execute_python, so REA rejected it as an upstream. A `hexrays` headless stdio registration now leases a private idalib worker through open_database, answers the existing database-supervisor reads with a fixed, packaged, read-only query module, and releases the lease with close_database, verified by list_databases. Observations record execute_python, the query and the module digest. Tool errors are typed so a completed rejection is distinguished from an unknown outcome; an unconfirmed release is retried and a late lease on the private input is adopted. Validated IDA source and bridge tests, static checks, docs, and npm run verify:ida on Linux x64 against x86-64 and AArch64 ELF fixtures.
A registration without `protocol` that reaches the official Hex-Rays server failed with only the missing database-supervisor tools. Startup profile failures now report the advertised catalog, and when it is the Hex-Rays one the message and recovery name the `hexrays` registration. Refs morluto#1416
Upstream needs IDA 9.4 or later with idalib, Python 3.11 or later, uv and Git. The profile does not analyze databases open in the IDA GUI, and the server keeps its own session traces outside REA's workspace. Refs morluto#1416
The call scan decoded every head that FuncItems yields. Inline data such as a jump table can decode as a call and refer to a function or import, which reported false callees and call-graph edges. Skip non-code heads before decoding, as disassembly already does. Refs morluto#1416
The identity and readiness reads around each operation kept only their parsed result, dropping the bridge digest and any engine output. Keep them whole as health_observations beside the parsed metadata, in both successful and partial-failure Evidence. Refs morluto#1416
The packed-bridge verifier has required bridge/ida/hexrays_queries.py since the Hex-Rays profile landed, but three package tests still built their member lists without it. The verifier stopped at that file, so 21 cases failed or asserted on the wrong omission. Refs morluto#1416
A headless open re-ran auto-analysis from the input binary, discarding the names, types and comments of an existing database and taking far longer on large targets. Target admission now identifies IDA databases by their IDA1/IDA2 signature, and the hexrays profile opens a private copy of one; Hopper and the other IDA profiles reject them. The copy is required, not incidental: idalib repacks a database when its last lease is released, even without a save. A database reports the input it was created from, so the session is bound to the opened copy's idb_path, and health now reports the input SHA-256 it records. Validated with resolver, provider and session tests, check:fast, docs:check and test:changed, plus a real Hex-Rays MCP run against a 1.4 GB SC2 .i64 whose original file was left byte-identical. Refs morluto#1416
Resolve package.json, IdaProvider and IdaWorkspace conflicts, then adapt to main's async IDA registration reading: - add the hexrays-ida-mcp compatibility profile to main's extracted profile construction; - the synchronous target check now reports an IDA database as unknown, and inspectTargetSupportWithOptions resolves the registration and admits it only for the hexrays protocol (main's universal Mach-O pattern); - await readIdaConfiguration with a resource scope in the Hex-Rays registration test; - give main's new Hopper database test target its databaseEngine. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged latest Conflicts
Breakage from the merge (did not compile after merging)
Validation (local macOS, merged head)
Not verified: a real Hex-Rays |
|
Thanks for the merge. main moved again, so I merged it once more (one conflict, in
|
|
I merged the latest
The resolution keeps your |
|
Tested this branch against the current Hex-Rays
Raw { "instance_id": "63fc0d2ac660", "backend": "idat", "status": "current", "recovery": "none", "mcp_id": null }The A minimal fix that worked for me: accept --- a/src/ida/IdaHexRaysProtocol.ts
- backend: z.enum(["gui", "idalib"]),
+ backend: z.enum(["gui", "idalib", "idat"]),
...
- backend: z.enum(["gui", "idalib"]),
+ backend: z.enum(["gui", "idalib", "idat"]),
--- a/src/ida/IdaSessionClient.ts
- if (opened.backend !== "idalib")
+ // Newer servers lease idat workers; both headless backends are private to this server.
+ if (opened.backend === "gui")
throw new AnalysisProtocolError(
- "IDA attached a GUI database instead of a private idalib worker for the private input copy.",
+ "IDA attached a GUI database instead of a private headless worker for the private input copy.",
);The inventory mapping already treats any non- Results with the fix on Linux x64, IDA Pro 9.5 and
Separately, the branch currently conflicts with |
|
Hey @NaiJii, thanks for putting this together, the addition looks useful. What's left: it has merge conflicts with main in |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
|
@morluto can you please have a look again at this PR? I think this would be a truly valuable addition to REA as using the other MCP would downgrade the experience while using IDA. Thanks again |
|
我这边刚在两台 macOS 上配置了 REA 6.9.0 + IDA Pro 9.5,现有 mrexodia 路线已跑通反编译、反汇编和字符串搜索。但两台机器原本都装了 Hex-Rays 官方 MCP,为了接入 REA,还需要额外安装、配置和维护一套桥接依赖。 这个 PR 有实际需求。mrexodia 作者已在 README 中推荐使用官方 MCP,Hex-Rays 的安装说明也建议减少同时启用的其他 IDA MCP。能直接复用用户已有的官方安装,会减少配置和版本管理的负担。mrexodia 的说明、Hex-Rays 的说明。 接着前面关于 建议优先处理三处:
|
Keep main's removed legacy attached protocol, provider guide path, cancellation helpers, and packed-bridge checks, and keep the Hex-Rays headless profile, private database admission, and query bridge. Co-authored-by: morluto <[email protected]>
A list_databases row with instance_id null is a live owner, not a stopped database. Mapping it to the supervisor's released-worker shape made cleanup delete files another client still held. Unleased rows stay active, so the private path must leave inventory before the workspace is removed. Accept idat inventory rows, hash the query bridge with sha256Hex, and complete databaseEngine on Hopper fixtures added on main.
Summary
Adds a
hexraysprotocol to the IDA provider so REA can use the official Hex-Rays IDA MCP (HexRaysSA/ida-mcp) with either theidaliboridatheadless backend. Before this change, REA rejected the server at startup because it exposes database reads throughexecute_python.Related to #1416. The maintainer-approved
idatscope and remaining live verification are tracked in #12921.Problem and expected behavior
A registration such as
{ "command": "ida-mcp", "args": ["stdio", "--agent=rea"], "mode": "headless", "protocol": "hexrays" }now supports the same analyst operations as the database-supervisor headless profile: inventory and search, lookup, containment, pseudocode, assembly, instruction windows, callees, xrefs and dossiers. REA analyzes a private copy of the selected executable or packed
.idbor.i64. The registration uses the existing Hex-Rays installation. To forceidalib, setIDA_NEXUS_IDALIB_ONLY=1in the registration’senv.Change and scope
bridge/ida/hexrays_queries.py(new, packaged): a fixed, read-only query module. REA sends it with one trailing_rea_query(name, arguments_json)line, so caller input reaches it only as JSON data. Its replies use the database-supervisor shapes REA already validates.IdaHexRaysProtocol.ts(new): the catalog, the open/list/close schemas, andrunHexRaysQuery, which recordsexecute_python, the query, its arguments and the bridge SHA-256 rather than the module body.IdaOperationRunner: an optionalinvokehook. Forhexrays, the runner keeps its modern parsing and records the actual upstream observation.IdaSessionClientverifies that the open reply and inventory agree on the owned lease, backend, and private input. It checks IDA’s recorded hash when available for executable targets and the opened database path for saved IDBs. Cleanup retains the workspace while inventory lists the lease or any database path inside it.IdaConfiguration:protocol: "hexrays"requiresmode: "headless"and a stdio registration, because Hex-Rays leases belong to the server process.advertised_tools. When a registration withoutprotocolreaches a Hex-Rays server, the message and recovery name thehexraysregistration.IdaMcpConnection:isErrorreplies throwIdaToolRejection, a subclass ofAnalysisProtocolError. Lifecycle code can then tell a completed rejection apart from an unreadable or missing reply.scripts/verify-real-ida.mjsaccepts--expected-backend idator--expected-backend idalib. It verifies the backend that served CLI and MCP reads, checks release by workspace path, and verifies that the original target stays byte-identical and gains no sibling files.scripts/verify-packed-bridge.mjs: requires and parses the packed Hex-Rays bridge.docs/providers/ida-provider.mddocuments registration, backend selection, cleanup, and verification.Not included: attached use or databases already open in the IDA GUI (#1416 use case 4), HTTP registrations, direct callers, and any forwarding of caller Python. REA never calls
save_database.Contract and boundary impact
IdaConfiguration) and upstream lifecycle (IdaSessionClient).idatworker uses IDA’s Python and installed plugins. Live verification of the current patch remains required before integration.execute_python), bridge digest, and bound backend (raw_result.worker_backend). The compatibility profile ishexrays-ida-mcp.package.json#filesaddsbridge/ida/hexrays_queries.py. Nothing is installed.Expected effects:
idaliboridatworker.).i64inside REA's workspace. Upstream Hex-Rays MCP session traces under~/.idapro/mcp/sessions/. No process memory.)uvxpackage resolution and IDA licensing. REA makes no network calls.)Evidence and regression coverage
Tests added or updated:
src/ida/IdaHexRaysProtocol.test.tswith a statefulRecordingHexRaysIdaMcpfixture:idatdatabase path lies outside the private workspace or IDA reports a conflicting executable hashexecute_python, and a protocol-less registration pointed at Hex-Rays naming thehexraysregistrationclose_databasecall and the workspace retained_rea_queryline with adversarial lookup namesbridge/ida/test_hexrays_queries.py(8 tests, added tonpm run test:python): runs the bridge asexecute_pythonwould, against IDA module stand-ins. It covers paging and cursors, the snapshot bound, failure rows, callees keeping interior, non-function and pointer-slot targets, call-graph entries only, and xrefs excluding ordinary flow and duplicates.Base reproduction: on the base revision, a Hex-Rays registration fails at startup with
missing_toolscovering the whole database-supervisor catalog.Remaining proof gaps:
idatverification is pending on Linux and macOS. Windows, PE, and large-target coverage remain unverified. The bridge holds one enumeration snapshot, such as the full string list, while it is paged.Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation on the current head
At
52af35a144, the bridge uses typed IDA call references for graph edges and keeps Python execution budgets within the MCP deadline. The verifier's--verify-peer-cleanupoption checks that a second connection retains the private workspace until its lease is released. 539 source tests and 8 Python bridge tests passed. The verifier also passed end to end through the production CLI and MCP with a simulated two-client upstream. A licensed IDA run remains pending.The earlier startup-cleanup fix in
fce441e54dtreats generic Hex-Rays open errors as unverified startup outcomes. Nexus can return an error while a worker is still starting, so REA retains the private workspace even when inventory is initially empty. A regression covers the error, empty inventory, and late unleased worker. The 129 focused source tests, 7 compiled CLI startup tests, static checks, formatting, and documentation checks passed locally.Earlier local checks for
b3fe304795: 535 source tests, 22 additional compiled-boundary tests, and 8 Python bridge tests passed. Static, formatting, and documentation checks passed. These runs included simulated IDA backends.A live
idatrun was attempted with a source-built arm64 Mach-O fixture. The verifier stopped at preflight because this workspace lacks a licensed IDA installation and aREA_IDA_MCP_CONFIGregistration. No live result is claimed for this head.Before merge, run the live verifier with
--expected-backend idat --verify-peer-cleanupon licensed Linux and macOS hosts with the official plugin, a source-built executable, and a saved database. Run a forced-idalibcontrol as well. #12921 tracks the checklist. The Linux contributor report used an earlier patch, and the macOS report exercised the upstream server and query bridge.Historical validation
npm run test:local -- src/ida/*.test.ts tests/composition/idaProvider.test.ts: 20 files, 338 tests passed.npm run test:focused -- tests/boundary/cli/idaStartupAttributionCli.test.ts: passed."protocol": "hexrays".npm run test:python: passed, including 8 new bridge tests.npm run check:fast: typecheck and lint passed.npm run verify:test-discovery: all test files discovered exactly once.npm run docs:check: passed.npx oxfmt --check .: passed.npm run verify:ida -- --target <x86-64 ELF fixture> --procedure rea_fixture_add --expected-xref <call site>: passed (Linux x64, Hex-Rays IDA MCP 20261008.0.1).--expected-string, on the fixture plus one string literal: passed with no unverified items.--expected-xreftaken from the decodedBLinstruction): passed.main's callees came from the call-graph query.Compatibility, safety, and release
protocolgains a value; existing registrations are unchanged.files.Author readiness
Human owner: @NaiJii
Before merge
type(scope): outcome.Conflict-resolution validation (2026-11-05)
Merged current
maininto this branch, preserving upstream profile ownership, cancellation, target-file cleanup and isolated package verification. Updated the Hex-Rays bridge and database fixtures for those contracts.check:fastpassed.guiandidalibschema. The same refusal occurred withida-mcp==20261008.0.1. The current patch acceptsidatand still requires a new live run.