IDALib MCP v2
by Spavvvv
README.md
# IDALib MCP v2
This package extends the pinned `ida-pro-mcp` 2.0.0 supervisor. It uses the existing Python and IDALib installation on the VM. Each database opened through v2 gets an owned headless worker. The workers retain every stock tool, including the stock Python and debugger extension groups.
## Copy-only installation
Run the following from this source directory on the VM. The installer copies only the `ida_mcp_v2` package into a separate directory. The stock venv, stock command and client entry stay available during use and rollback. The steps use no pip, wheels or new venv.
```powershell
$Tools = 'C:\Users\Soappp\Desktop\ShellcodePack_RE\tools'
Set-Location -LiteralPath (Join-Path $Tools 'ida_mcp_v2')
& .\install_v2.ps1 -StockVenv (Join-Path $Tools 'ida-mcp-venv2') `
-Destination (Join-Path $Tools 'ida-mcp-v2-copy')
```
To copy manually, put the inner `ida_mcp_v2` directory at `ida-mcp-v2-copy\ida_mcp_v2`. Set `PYTHONPATH` to the parent `ida-mcp-v2-copy` directory for the v2 command.
### Run over stdio
```powershell
$env:PYTHONPATH = Join-Path $Tools 'ida-mcp-v2-copy'
& "$Tools\ida-mcp-venv2\Scripts\python.exe" -B -m ida_mcp_v2 --stdio --unsafe
```
Use `--artifact-root` to select an absolute local artifact directory. The launcher creates it and passes it to every worker. With no flag, it uses `IDA_MCP_V2_ARTIFACT_ROOT` if set, then `%LOCALAPPDATA%\ida_mcp_v2\artifacts`, then `artifacts` next to the package. `--stdio` uses stdin/stdout for client messages. An invocation without it serves loopback HTTP on port `8746`. The v2 worker enables the full stock tool surface by default and accepts `--unsafe` explicitly. Python tools execute with the worker account's permissions. Use this endpoint with trusted clients and scripts.
```json
{
"command": "C:\\Users\\Soappp\\Desktop\\ShellcodePack_RE\\tools\\ida-mcp-venv2\\Scripts\\python.exe",
"args": ["-B", "-m", "ida_mcp_v2", "--stdio", "--unsafe", "--artifact-root", "C:\\Users\\Soappp\\Desktop\\ShellcodePack_RE\\tools\\ida-mcp-v2-artifacts"],
"env": {
"PYTHONPATH": "C:\\Users\\Soappp\\Desktop\\ShellcodePack_RE\\tools\\ida-mcp-v2-copy"
}
}
```
### Rollback
Close v2 sessions, stop the v2 supervisor, and switch the client back to its existing stock entry. Delete the copied `ida-mcp-v2-copy\ida_mcp_v2` package and remove the v2 entry's `PYTHONPATH`. Artifact files are in their own directory.
```powershell
& "$Tools\ida-mcp-venv2\Scripts\idalib-mcp.exe" --stdio
```
## Extension tools
Use the `session_id` returned by stock `idb_open`, or `database` from `v2_open_raw`, as the `database` parameter on routed tools. Addresses are hexadecimal strings and ranges are half-open.
| Tool | Contract |
| --- | --- |
| `v2_open_raw(path, arch="x86_64", bits=64, base="0x0", entry=None)` | Stages a private copy of a 1 byte to 1 MiB file and opens it with IDA's binary loader and autoanalysis off. The base is 16-byte aligned and the end is at or below `2^36`. Optional `entry` is an absolute address in the mapping. Publishes the database only after verifying the one segment, processor, 64-bit database and segment settings, and every staged byte. Success returns a database handle, verified mapping, SHA-256 and staged path. The working copy lives under the VM account's temporary directory. |
| `v2_define_code_range(database, start, end, dry_run=False)` | Preflights reads, decodes and overlaps for up to 64 KiB before writing. Dry run reports planned and existing heads. Apply reports `applied`, `already` and `failed` rows, first failing address and exact applied bytes from IDB readback. Large reports are saved as a JSON artifact and returned by ID. |
| `v2_define_func_range(database, start, end, prefix=None)` | Creates one function over contiguous existing instruction heads with explicit bounds. Repeating those bounds reports `already`. An optional identifier prefix names the function `prefix` followed by the lowercase hexadecimal start. |
| `v2_run_script(database, script_path, args=None, timeout_s=120, out_path=None)` | Runs a VM-local UTF-8 Python file of up to 1 MiB with `sys.argv` and `__file__`. If the script assigns `result`, the response includes it. |
| `v2_py_eval(database, code, timeout_s=60, out_path=None)` | Executes up to 256 KiB of inline Python and returns the final expression, if present. The worker keeps eval bindings for its database. |
| `v2_artifact_list()` | Lists committed artifacts independently of open databases. |
| `v2_artifact_read(artifact_id, offset=0, max_bytes=16384)` | Returns a base64 chunk, offset, next offset, total bytes and complete SHA-256. Follow `next_offset` until null and concatenate decoded chunks. |
| `sweep_range(database, start, end, out_path, format="jsonl", data=None)` | Exports up to 1 MiB of linear decode rows. Pass `data=[{start, end}]` to keep each declared half-open span as a single DATA row. Returns row counts, digest and input provenance. |
| `disasm_range(database, start, end, page_bytes=128, data=None)` | Returns complete rows and a `next_start` cursor. Reuse `end` and omit completed DATA spans when continuing. The byte target is 1 to 4,096. Oversized DATA rows retain their address and size and set `bytes_omitted`. |
| `export_annotations(database, out_path)` | Publishes an input-digest-bound bundle of names, address comments, type declarations, main function bounds, data-item kinds, stack names and outgoing xrefs. |
| `import_annotations(database, artifact_id=None, path=None, conflict="error", dry_run=False)` | Imports a published artifact or worker-local JSON bundle for the same input SHA-256. Returns per-field status and totals. |
| `export_fingerprints(database, out_path, start=None, end=None)` | Publishes JSONL with one row per function whose entry is in range. The default range is the whole database. |
| `match_fingerprints(artifact_a, artifact_b, out_path)` | Compares two published fingerprint artifacts on the supervisor and publishes a JSONL ledger with counts for both sides. No database handle is needed. |
| `run_analysis(database, start=None, end=None, wait=True, timeout_s=120)` | Schedules IDA analysis for mapped parts of the range and optionally drains the range's queues. Returns before and after counts, deadline status and the exact settings used. |
| `artifact_get(name, offset=0, limit=8192)` | Legacy receipt and chunk retrieval. Use `limit=0` for metadata. The maximum raw page is 12,288 bytes. |
| `artifact_list(offset=0, limit=25)` | Legacy paginated artifact listing. Its first page is also available at `ida://artifacts`. |
Script calls return an exit code, execution status, stream sizes, and the byte count and SHA-256 of the captured log. The log contains stdout followed by stderr, with a 128 MiB publication cap and an explicit truncation indicator. Python and file descriptor writes are redirected while the script runs. Script execution is exclusive in its worker. Concurrent tool requests in that worker receive `BUSY` and can be retried. Other workers and supervisor-local artifact tools remain available. Deadlines are cooperative for in-process Python. A blocking IDA or native call can delay timeout reporting until control returns to Python. Script and IDB edits performed before failure or timeout can persist in the worker.
`out_path` is a portable basename such as `range-1000.jsonl`. Committed files live at `<artifact-root>\<artifact-id>\payload` with a `manifest.json` beside the payload. An existing script log name is rejected before execution when already present. Supply a new basename or omit `out_path` for an automatic name.
### Compare fingerprint artifacts
Export one artifact per build. Each row combines the current function name, entry and main end address with its chunks, raw SHA-256, masked-byte SHA-256, canonical mnemonic-sequence SHA-256, basic-block count, resolved callees and IDA-recognized string references. Raw hashes cover concatenated chunks in address order. Masking uses checked x86 and x64 operand layouts for common immediate, displacement and branch fields. Rows with unavailable bytes or unverified encodings report their coverage in `raw_complete`, `mask_complete` and `mask_limitations`.
```text
export_fingerprints(database="build-a", out_path="build-a.jsonl", start="0x140001000", end="0x140004000")
export_fingerprints(database="build-b", out_path="build-b.jsonl")
match_fingerprints(artifact_a="build-a.jsonl", artifact_b="build-b.jsonl", out_path="build-matches.jsonl")
```
The matcher verifies both artifact payloads and tries complete masked hashes, mnemonic hashes and exact current names in that order. Hash comparisons are scoped to matching processors and bitness. Matches require a unique pair and agreement with any stronger collision candidates. Ambiguous ledger rows list candidates. Counts `ambiguous` and `unmatched` describe artifact A, and the `_b` counters describe artifact B. Matches are heuristic.
### Review and apply annotations
```text
export_annotations(database="db-reviewed", out_path="review.json")
import_annotations(database="db-copy", artifact_id="review.json", conflict="overwrite", dry_run=True)
import_annotations(database="db-copy", artifact_id="review.json", conflict="overwrite")
```
Supply exactly one of `artifact_id` and `path`. The importer accepts v1 and v2 bundles. Addresses are absolute and the stored input SHA-256 must match. `error` blocks writes on preflight conflicts or malformed records. `skip` applies eligible fields and preserves differing existing values. `overwrite` attempts to update differing values. In a dry run, `applied` means eligible for application. On a write, a setter must pass IDA readback to report `applied`. Individual writes can persist if a later setter fails. Xrefs are exported for review. Stack renames require existing frame members. Data-item kinds and declared types are captured, with referenced type libraries and auxiliary string or custom item metadata outside the bundle. Export reports unavailable frame and data APIs in `unavailable`.
### Analyze a raw or normal database
```text
run_analysis(database="raw-session", start="0x1000", end="0x3000", wait=True, timeout_s=120)
```
Omit both bounds to use the database extent. IDA queues `AU_CODE` for unknown intervals and `AU_USED` for reanalysis within the mapped parts of that extent. The receipt reports the existing `AF` and `AF2` flags, the temporary enable settings, the queue state and whether each count completed within the budget. Counts cover function entries and outgoing xrefs from defined heads in the range, including flow xrefs. `wait=False` queues work for a later explicit waiting call in headless mode. Both enable flags are restored before return. A native analysis step can overrun the cooperative deadline. IDA may follow dependencies beyond the requested range.
## Pinned stock inventory
The table enumerates the stock registrations in `c133c3853faa111a9b00ee615c013b720d0c4acd`. The worker contains 90 stock registrations and 10 extension tools. The supervisor presents 91 stock tool names and all 16 entries above. It serves `idb_open` and `idb_list` itself and adds `idb_close`. These counts are derived from the pinned source and extension registrations. [Pinned upstream source](https://github.com/mrexodia/ida-pro-mcp/tree/c133c3853faa111a9b00ee615c013b720d0c4acd/src/ida_pro_mcp)
| Stock module | Tool names |
| --- | --- |
| Database lifecycle | `idb_open`, `idb_list`, `idb_close` |
| Core | `server_health`, `lookup_funcs`, `int_convert`, `list_funcs`, `func_query`, `list_globals`, `entity_query`, `imports`, `imports_query`, `idb_save`, `find_regex`, `search_text` |
| Analysis | `decompile`, `disasm`, `func_profile`, `analyze_batch`, `xrefs_to`, `xref_query`, `xrefs_to_field`, `callees`, `find_bytes`, `basic_blocks`, `find`, `insn_query`, `export_funcs`, `callgraph` |
| Composite | `analyze_function`, `analyze_component`, `diff_before_after`, `trace_data_flow` |
| Debugger | `dbg_start`, `dbg_status`, `dbg_exit`, `dbg_continue`, `dbg_run_to`, `dbg_step_into`, `dbg_step_over`, `dbg_bps`, `dbg_add_bp`, `dbg_delete_bp`, `dbg_toggle_bp`, `dbg_set_bp_condition`, `dbg_regs_all`, `dbg_regs_remote`, `dbg_regs`, `dbg_gpregs_remote`, `dbg_gpregs`, `dbg_regs_named_remote`, `dbg_regs_named`, `dbg_stacktrace`, `dbg_read`, `dbg_write` |
| Memory | `get_bytes`, `get_int`, `get_string`, `get_global_value`, `patch`, `put_int` |
| Modify | `add_bookmark`, `set_comments`, `append_comments`, `patch_asm`, `rename`, `define_func`, `define_code`, `undefine`, `force_recompile`, `set_op_type`, `make_data` |
| Python | `py_eval`, `py_exec_file` |
| Signatures | `make_signature`, `make_signature_for_function`, `make_signature_for_range`, `find_xref_signatures` |
| Stack | `stack_frame`, `declare_stack`, `delete_stack` |
| Survey | `survey_binary` |
| Types | `declare_type`, `enum_upsert`, `read_struct`, `search_structs`, `type_query`, `type_inspect`, `set_type`, `type_apply_batch`, `infer_types` |
## Verification
Run these from the repository root. The artifact helpers support Python 3.10. Running the IDALib worker also requires the pinned upstream package, which declares Python 3.11 or later.
```powershell
python -m compileall tools/ida_mcp_v2
python tools/ida_mcp_v2/selftest.py
Push-Location tools/ida_mcp_v2
python -S -B -m ida_mcp_v2 --help
Pop-Location
```
The host tests use synthetic bytes and IDA stubs. On the VM, verify live `tools/list`, raw opens at `0x0` and `0x140000000`, and the native IDA write readbacks before using the result as VM evidence. The raw loader uses the pinned session manager for activation and IDALib's third open argument for command-line switches. Compare the returned input digest with independently hashed staged bytes. [IDA SDK open signature](https://cpp.docs.hex-rays.com/idalib_8hpp_source.html) [IDA command-line switches](https://docs.hex-rays.com/9.1/user-guide/configuration/command-line-switches)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues