Skip to content

Repository files navigation

rbinr2

rbinr2 is a Model Context Protocol server for radare2-backed binary analysis.

It runs as a stdio MCP server, opens binaries in persistent radare2 sessions, and exposes named tools for metadata, disassembly, search, xrefs, byte extraction, graphing, and static triage.

The target use case is repeatable static analysis from an MCP client. Give the tools an absolute binary path and an address, symbol, flag, or search pattern. rbinr2 keeps the radare2 session open until you close it or the server exits.

Requirements

  • Rust 1.88 or newer
  • radare2 5.9 or newer on PATH
  • An MCP client that can run stdio servers

Check the runtime dependency:

r2 -v

Optional decompiler support for r2_decompile mode=code requires an r2 decompiler plugin such as r2ghidra or r2dec. mode=meta works without those plugins.

Install

From a local checkout:

git clone https://github.com/kirkderp/rbinr2
cd rbinr2
cargo install --path crates/rbm-server --locked

From git:

cargo install --git https://github.com/kirkderp/rbinr2 --package rbm-server --locked

The installed executable is named rbinr2.

Run it directly:

RBM_CACHE_DIR=./rbinr2-cache rbinr2

The process waits for MCP JSON-RPC messages on stdin and writes responses to stdout.

MCP Configuration

Example stdio server configuration:

{
  "mcpServers": {
    "rbinr2": {
      "command": "/absolute/path/to/rbinr2",
      "args": [],
      "env": {
        "RBM_CACHE_DIR": "/absolute/path/to/rbinr2-cache"
      }
    }
  }
}

Use an absolute path for command. Use an absolute path for RBM_CACHE_DIR when the client may start the server from different working directories.

How It Works

MCP client
  -> stdio JSON-RPC
  -> rbinr2
  -> one persistent radare2 process per binary
  -> bounded r2 commands
  -> JSON/text tool responses

rbinr2 canonicalizes binary paths and reuses the same radare2 session for later calls. The first call for a binary performs radare2 startup analysis. Later calls use the existing session.

Use r2_close to close one binary session. Use r2_sessions to list open sessions.

Example Tool Calls

MCP clients call tools by name. These examples show the tool arguments.

Open a binary with r2_open:

{
  "binary_path": "/absolute/path/to/sample.exe"
}

Read binary metadata with r2_metadata:

{
  "binary_path": "/absolute/path/to/sample.exe",
  "mode": "info"
}

List functions with r2_metadata:

{
  "binary_path": "/absolute/path/to/sample.exe",
  "mode": "functions",
  "limit": 25
}

Inspect a function with r2_function_view:

{
  "binary_path": "/absolute/path/to/sample.exe",
  "addr": "entry0",
  "mode": "profile"
}

Extract bytes without writing files with r2_extract_bytes:

{
  "binary_path": "/absolute/path/to/sample.exe",
  "addr": "entry0",
  "count": 256
}

Close the session with r2_close:

{
  "binary_path": "/absolute/path/to/sample.exe"
}

Configuration

Variable Default Description
RBM_CACHE_DIR ./rbinr2-cache Cache root for guarded overflow output.
RBM_R2_OPEN_TIMEOUT 120 Timeout in seconds for opening a new radare2 session.
RBM_TOOL_TIMEOUT_SECS 30 Timeout in seconds for each radare2 command.

Tool Reference

rbinr2 exposes 39 MCP tools.

Sessions

Tool Purpose
r2_open Open a binary and start a persistent radare2 session.
r2_close Close one binary session.
r2_sessions List open sessions.

Metadata

Tool Purpose
r2_metadata Mode-driven metadata: info, headers, version info, entry points, sections, relocations, resources, libraries, imports, exports, symbols, strings, and functions.
r2_classes List classes or inspect one class.
r2_vtables Return bounded native vtable discovery from avj.
r2_types Read r2 type-system data: lists, functions, structs, enums, unions, typedefs, C declarations, views, formats, casts, xrefs, links, and calling conventions.
r2_imports_grouped Group imports by usage category with caller data when r2 provides it.
r2_plugins List r2 asm, analysis, binary, hash, and decompiler capabilities.
r2_flags Read flags, real names, or flagspaces with filtering and pagination.
r2_lookup_address Resolve an address to its flag, symbol, module, and enclosing function.
r2_address_info Return r2 address classification metadata from aij.
r2_calculate Evaluate an r2 math expression and return hex, decimal, and binary.

Disassembly

Tool Purpose
r2_disassemble Disassemble a bounded instruction window or containing function as JSON or text.
r2_opcodes Return structured opcode-analysis rows from aoj.
r2_decompile Return decompiler output or compact decompiler metadata.
r2_function_view Inspect a function: analyze, info, signature, vars, profile, strings, constants, callees, refs, or cfg.
r2_graph Export native r2 graphs for functions, callgraphs, imports, refs, xrefs, and data refs.

Bytes

Tool Purpose
r2_get_bytes Read raw bytes as a hex string.
r2_extract_bytes Extract a bounded byte range with SHA-256, hex/ascii previews, lookup data, and section/file-offset mapping.
r2_block_hash Compute a bounded r2 ph hash or entropy value.
r2_pointer_scan Read pointer/reference-like words from a bounded memory range using pxrj.
r2_string_at Decode a string at an address as auto, ascii, utf16, utf32, or pascal.

Search

Tool Purpose
r2_find Search functions, strings, imports, or bytes.
r2_semantic_search Run bounded opcode-type, disasm-text, wide-string, value, refs, ROP, or hex searches.
r2_find_xrefs Search and resolve xrefs to each hit in one bounded pass.

Xrefs And Flow

Tool Purpose
r2_xrefs Get xrefs to or from an address.
r2_global_xrefs Return a paginated global xref inventory.
r2_trace_data_flow Traverse xrefs forward or backward with bounded depth.
r2_var_xrefs List function variable read/write xrefs from afvxj.
r2_esil_accesses Summarize ESIL-derived register and memory accesses.
r2_value_trace Trace a seeded register or memory value through a bounded disassembly window.

Static Triage

Tool Purpose
r2_security Return checksec-style hardening fields or per-section entropy.
r2_path_digest Summarize branches, calls, constants, markers, local buffers, and state writes over a bounded path.
r2_artifact_summary Summarize decoded branch artifacts, strings, callsites, and unsupported branches.
r2_field_xrefs Map raw memory field references with symbolic root tracking.
r2_jump_table_slices Summarize computed jump-table targets.
r2_windows_driver_dispatch Recover Windows DRIVER_OBJECT dispatch and notify callback anchors from an init routine.

Raw r2 Query

Tool Purpose
r2_cmd Run one read-only r2 query command with guarded output.

r2_cmd rejects command separators, shell escapes, writes, seeks, and eval-setting mutations. Prefer named tools when one exists.

Usage Notes

  • binary_path must be an absolute path.
  • Address arguments accept numeric addresses, symbols, and r2 flags.
  • Most tools clamp counts and limits before calling r2.
  • r2_extract_bytes returns bytes, hashes, previews, and mapping data. It does not write extracted bytes to disk.
  • r2_decompile mode=code depends on installed r2 decompiler plugins. Use mode=meta for plugin-independent metadata.
  • r2_cmd is for read-only queries. Use named tools for normal workflows.

Development

Build and test:

cargo fmt --check
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo test --workspace --locked

Run from source:

RBM_CACHE_DIR=./rbinr2-cache cargo run --bin rbinr2

Fresh local install:

cargo install --path crates/rbm-server --locked

Project Layout

crates/
  rbm-server/    MCP server, radare2 session management, and tool implementations

License

MIT. See LICENSE.

About

MCP server for radare2-based binary analysis

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages