# radareorg/radare2-mcp architecture

> Architecture diagram of the GitHub repository radareorg/radare2-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/radareorg/radare2-mcp
- Repository: https://github.com/radareorg/radare2-mcp

## Overview

##### Project Type and Purpose
- This is a small, C-based CLI application that implements an MCP (Model-Client Protocol) server adapter for radare2.
- Purpose: allow AI assistants (e.g., Claude Desktop) to communicate with radare2 via stdin/stdout, enabling binary analysis and file inspection.
- Key indicators: single C source file (`r2mcp.c`), Dockerfile, Makefile, README describing “MCP server for radare2 with AI assistants.”

##### File Structure Analysis
- Top-level files:
- `r2mcp.c`: core server implementation.
- `indent.py`, `.clang-format`: coding style tooling.
- `Makefile`, `Dockerfile`: build and containerization.
- `INSTALL.md`, `README.md`: installation and usage docs.
- `debug.txt`: runtime logs or development notes.
- No “frontend” or “backend” directories—this is a single-bin service.
- Presence of Dockerfile indicates optional container deployment.

##### Readme Insights
- Integration points: stdin/stdout message passing using JSON over pipes.
- External service: radare2 CLI (`r2pm` wraps `r2mcp`).
- Hosts: client is Claude Desktop, server is `r2mcp` (or Docker container).
- Configuration: Claude JSON config file specifies command+args.

##### Main Components
a. Claude Desktop (AI assistant client)
b. MCP Configuration File (`claude_desktop_config.json`)
c. r2mcp Process (C executable)
d. radare2 Process / Library (spawned or invoked by r2mcp)
e. File System (for binary/file exploration)
f. Optional Docker Container (hosts r2mcp + radare2)

##### Interactions and Data Flow
- Claude Desktop → (reads JSON config) → launches r2mcp
- Claude Desktop ↔ r2mcp over STDIN/STDOUT (JSON messages, commands & responses)
- r2mcp → spawns / pipes commands to radare2 → receives radare2 output
- r2mcp ↔ File System for directory/file listing or binary inspection
- (Optional) all of the above occur inside Docker container when configured

##### Architectural Patterns & Design Principles
- “Adapter” pattern: r2mcp adapts the MCP protocol to radare2’s CLI API
- Single-process, pipe-based RPC model (no HTTP or sockets)
- Separation of concerns:
- Client (AI assistant) concerns vs
- Server (r2mcp) mediation vs
- Analysis engine (radare2)

##### Technologies & Frameworks
- Language: C
- Build: Makefile
- Container: Docker
- Communication: JSON over stdin/stdout
- Integration: radare2 CLI via `r2pm` / direct binary

##### Essential Elements to Capture
- Clear component names & roles
- Data flows and directions (JSON, CLI commands, FS access)
- Optional vs mandatory paths (native launch vs Docker)
- Config file ingestion
- Distinction between AI client, adapter, and analysis engine

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Claude["Claude Desktop"]:::client
        Config["claude_desktop_config.json"]:::storage
    end

    %% Native Deployment
    subgraph "Native Deployment"
        R2MCP["r2mcp Process (C executable)"]:::server
        Radare2["radare2 Analysis Engine"]:::external
        FS["File System"]:::storage
    end

    %% Docker Deployment
    subgraph "Docker Deployment"
        subgraph "Docker Container"
            R2MCP_d["r2mcp Process (C executable)"]:::server
            Radare2_d["radare2 Analysis Engine"]:::external
            FS_d["File System"]:::storage
        end
    end

    %% Project Files and Tooling
    subgraph "Project Files"
        r2mcp_c["r2mcp.c"]:::docs
        Make["Makefile"]:::docs
        Dockerfile["Dockerfile"]:::docs
        indent["indent.py"]:::docs
        clang[".clang-format"]:::docs
        INSTALL["INSTALL.md"]:::docs
        README["README.md"]:::docs
        debug["debug.txt"]:::docs
    end

    %% Interactions Native
    Claude -->|reads JSON config| Config
    Claude -->|"JSON MCP over STDIO"| R2MCP
    R2MCP -->|"R2 Commands"| Radare2
    Radare2 -->|"CLI Output"| R2MCP
    R2MCP -->|"FS I/O"| FS

    %% Interactions Docker
    Claude -->|"JSON MCP over STDIO"| R2MCP_d
    R2MCP_d -->|"R2 Commands"| Radare2_d
    Radare2_d -->|"CLI Output"| R2MCP_d
    R2MCP_d -->|"FS I/O"| FS_d
    Dockerfile -->|"Defines Container"| Docker_Container

    %% File Associations
    r2mcp_c --> R2MCP
    Make --> R2MCP
    Dockerfile --> R2MCP_d
    indent --> r2mcp_c
    clang --> r2mcp_c
    INSTALL --> README
    debug --> r2mcp_c

    %% Click Events
    click R2MCP "https://github.com/radareorg/radare2-mcp/blob/main/r2mcp.c"
    click Make "https://github.com/radareorg/radare2-mcp/tree/main/Makefile"
    click Dockerfile "https://github.com/radareorg/radare2-mcp/tree/main/Dockerfile"
    click indent "https://github.com/radareorg/radare2-mcp/blob/main/indent.py"
    click clang "https://github.com/radareorg/radare2-mcp/blob/main/.clang-format"
    click INSTALL "https://github.com/radareorg/radare2-mcp/blob/main/INSTALL.md"
    click README "https://github.com/radareorg/radare2-mcp/blob/main/README.md"
    click debug "https://github.com/radareorg/radare2-mcp/blob/main/debug.txt"

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef storage fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef docs fill:#f8d7fa,stroke:#333,stroke-width:1px
```
