Skip to content

About

Headless Ghidra analysis for MCP clients. Clients can start sessions, decompile code, examine symbols, and change Ghidra programs.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ghidra-mcp

English | 中文 | 日本語

Rust MCP CI License

ghidra-mcp is an MCP server and a command-line tool for headless Ghidra analysis.

One local daemon runs the Ghidra sessions on Linux, macOS and Windows. MCP clients connect to the daemon through stdio or HTTP. The command-line tool uses the same daemon. The MD5 of a binary identifies its session for all clients.

Important

The daemon keeps configuration, binaries and analysis in the persistent home. The default persistent home is ~/.ghidra-mcp on Linux and macOS, and %LOCALAPPDATA%\ghidra-mcp on Windows. To use a different directory, set GHIDRA_MCP_HOME. The daemon keeps temporary files in a private runtime directory. If the daemon does not run, stdio clients and the command-line tool start it.

System Architecture

Contents

Features

  • MCP through stdio, Streamable HTTP, or legacy SSE. One daemon keeps the shared state.
  • Command-line client. It lists the tools locally. It calls the tools through the daemon. It also starts, stops and examines the daemon, its sessions and its jobs.
  • Sessions identified by MD5. The daemon uses a session again or opens the saved analysis again.
  • Persistent sessions and jobs. Sessions and analysis jobs continue after a client disconnects.
  • Remote upload. A client that is not on the daemon host sends a binary through a separate HTTP endpoint.
  • Raw firmware import. The daemon imports .bin, .hex, .ihex and .srec files with processor, compiler, loader and base address flags.
  • Local .gpr projects. The daemon attaches a local Ghidra .gpr project in place and keeps its custom memory map.
  • Full Ghidra access. The Java bridge gives program data, functions, decompilation, symbols, references, memory and comments.
  • One executable. The executable contains the bridge JAR and its launcher scripts.
  • Background jobs. ghidra_job list, ghidra_job get and ghidra_job wait monitor a long analysis.

Sessions can change the program by default. Coding agents must get approval from the user before they use an operation that changes the program.

Get started

For client setup snippets and walkthroughs, read the First Steps guide.

Prerequisites

  • Linux, macOS or Windows.
  • Java 21.
  • A local Ghidra installation that has analyzeHeadless (analyzeHeadless.bat on Windows).

Install with npm

If you have Node.js 18 or later, npm can install the executable for your platform:

npx @ghidra-mcp/cli tools

Or install the command for all projects:

npm install --global @ghidra-mcp/cli
ghidra-mcp tools

To use npx from an MCP client:

{
  "command": "npx",
  "args": ["-y", "@ghidra-mcp/cli"]
}

npm installs one platform package, such as @ghidra-mcp/linux-x64. Do not use --omit=optional, because the platform packages are optional dependencies. The Linux packages need glibc. On musl systems, such as Alpine, use Build from source. The executable must also find Ghidra (see Find Ghidra).

Use a prebuilt executable

  1. Download the file for your platform from GitHub Releases.

    Platform x86_64 ARM64
    macOS ghidra-mcp-macos-x86_64 ghidra-mcp-macos-arm64
    Linux ghidra-mcp-linux-x86_64 ghidra-mcp-linux-arm64
    Windows ghidra-mcp-windows-x86_64.exe ghidra-mcp-windows-arm64.exe
  2. Rename the file to ghidra-mcp (ghidra-mcp.exe on Windows).

  3. On Linux and macOS, make the file executable with chmod +x ghidra-mcp.

  4. Make sure that the executable can find Ghidra (see Find Ghidra). For example, on Windows:

    $env:GHIDRA_INSTALL_DIR = 'C:\Tools\ghidra_12.1.4_PUBLIC'
    .\ghidra-mcp.exe tools
  5. Add the executable to your MCP client:

    {
      "command": "C:\\Tools\\ghidra-mcp.exe",
      "args": []
    }

The executable needs only Ghidra and Java. It writes the bridge files into the runtime directory when it opens a session.

Build from source

To build from source, you also need:

  • A Rust toolchain.
  • The bridge/ submodule. The build uses the Gradle wrapper of the submodule.
  • A Ghidra installation in GHIDRA_INSTALL_DIR or GHIDRA_HOME. The bridge compiles against this installation.
  1. If you cloned the repository without submodules, get the bridge:

    git submodule update --init --recursive
  2. Build the release executable:

    cargo xtask build --release --locked --bin ghidra-mcp

The result is target/release/ghidra-mcp (ghidra-mcp.exe on Windows). This one file is the complete distribution.

The command cargo xtask build builds the bridge with Gradle. Then it embeds the bridge JAR, Bridge.java and GhidraMcp.java in the executable. The operation catalog comes from the bridge contract bridge/docs/asyncapi.yaml at compile time.

To embed a bridge JAR that you built before, set GHIDRA_MCP_BRIDGE_JAR. A relative path starts at the workspace root. The build then makes only Bridge.java and GhidraMcp.java, and does not compile the bridge.

Find Ghidra

Before it serves MCP, the daemon checks that it can find an executable analyzeHeadless. If this check fails, it writes the error to stderr and daemon.log, then exits with status 1.

The daemon finds analyzeHeadless in this order:

  1. [ghidra].analyze_headless in config.toml.
  2. The installation in [ghidra].home, GHIDRA_INSTALL_DIR or GHIDRA_HOME.
  3. analyzeHeadless on PATH.
  4. The installation of ghidraRun on PATH.
  5. On Unix, the Homebrew Cellar and directories named ghidra* in /Applications, ~, ~/Applications and ~/opt.

Tip

If a computer has more than one Ghidra installation, set GHIDRA_INSTALL_DIR.

Usage

The default configuration does not need environment variables. These optional variables change the defaults:

Variable Purpose
GHIDRA_INSTALL_DIR The Ghidra installation directory.
GHIDRA_HOME Another name for the installation directory. GHIDRA_INSTALL_DIR has priority.
GHIDRA_MCP_HOME The persistent home.

Ghidra also uses the standard Java variables JAVA_HOME and JAVA_TOOL_OPTIONS. On Unix, XDG_RUNTIME_DIR and TMPDIR set the location of the runtime directory.

Stdio server

An MCP client starts ghidra-mcp without arguments and talks to it through stdio:

{
  "command": "/path/to/ghidra-mcp",
  "args": []
}

This process sends each tool call to the daemon. If the daemon does not run, the process starts it. The process connects to the daemon through a local socket. On Unix, the socket is a private Unix domain socket. On Windows, the socket is a named pipe.

The process reuses this connection across tool calls to avoid repeated handshake delays. If the daemon stops, the process reconnects on the next call.

To run from a source checkout, use cargo run -- as the command.

HTTP server

To run the daemon in the foreground, use this command:

ghidra-mcp daemon run

The daemon serves these endpoints on one listener:

Endpoint Purpose
http://127.0.0.1:18489/mcp MCP through Streamable HTTP or legacy SSE.
/upload Binary uploads.
/ws/agent The WebSocket of the Ghidra bridge.

The daemon accepts only loopback addresses. To use a different address, use --listen:

ghidra-mcp daemon run --listen 127.0.0.1:18490

With --listen 127.0.0.1:0, the system selects a free port. The daemon writes the address in server.json and daemon.log in the runtime directory.

The daemon continues to run after all clients disconnect. To stop a foreground daemon, press Ctrl-C. To stop a daemon in the background, use ghidra-mcp daemon stop. On Unix, SIGINT, SIGTERM and SIGHUP also stop it. When the daemon stops, it closes its Ghidra sessions. You can open the saved projects again later.

Manage the daemon

Use these commands to manage the shared daemon:

Command Purpose
ghidra-mcp daemon start [--listen ADDR] Start the daemon in the background. Wait until it is ready.
ghidra-mcp daemon stop [--force] Stop the daemon. It closes its sessions first.
ghidra-mcp daemon restart [--force] [--listen ADDR] Stop the daemon, then start it again.
ghidra-mcp daemon status [--json] Show the process ID, version, MCP URL, sessions and jobs.
ghidra-mcp daemon logs [-n N] [-f] Show the last lines of daemon.log. With -f, show new lines until Ctrl-C.
ghidra-mcp setup [DIR] [--json] Write Bridge.java, GhidraMcp.java and ghidra-bridge.jar into a script directory (default ~/ghidra_scripts).
ghidra-mcp paths [--json] Show the persistent home, the runtime directory and their files.
ghidra-mcp config path|show|edit|check Find, show, change or check config.toml.
ghidra-mcp session list|get|open|attach|close|checkpoint|reset|delete Manage the sessions and checkpoints of the daemon.
ghidra-mcp job list|get|wait Examine the background jobs of the daemon.

If a session is live or a job runs, daemon stop does not stop the daemon. To stop it, add --force. If no daemon runs, daemon status exits with status 3, and daemon stop is successful.

These commands write text. For scripts, add --json. MCP clients can also use ghidra_daemon shutdown. Then the daemon stops for all clients.

Command-line tool

The command-line tool uses the same tool catalog as MCP.

To list the tools without a daemon, use this command:

ghidra-mcp tools

To call a tool through the daemon, use this command:

ghidra-mcp call ghidra_session '{"operation":"list"}'

call TOOL [JSON] accepts one JSON object. The default is {}. If necessary, the command starts the daemon. The command writes structuredContent as formatted JSON.

Result Output Exit code
The call is successful. The result on stdout. 0
The call fails. The error on stderr. 1
The arguments are not valid. The usage on stderr. 2
--help or --version. The text on stdout. 0

Import raw firmware

Headerless firmware files such as .bin, .hex, .ihex and .srec have no architecture header. Pass optional import flags to ghidra_session open, ghidra_upload prepare or ghidra-mcp session open:

MCP params field CLI flag Purpose
processor --processor <ID> Ghidra language ID for -processor, for example ARM:LE:32:Cortex.
compilerSpec --compiler-spec <ID> Ghidra compiler specification ID for -cspec. Needs processor.
loader --loader <CLASS> Ghidra loader class for -loader, such as BinaryLoader or IntelHexLoader.
baseAddress --base-address <ADDR> Hexadecimal load address for -loader-baseAddr, such as 0x08000000 or ram:0x08000000.
reimport --reimport Delete the saved Ghidra project for this binary and run -import again.

Example with ghidra_session open:

{
  "operation": "open",
  "params": {
    "path": "/path/to/firmware.bin",
    "processor": "ARM:LE:32:Cortex",
    "baseAddress": "0x08000000",
    "wait": true
  }
}

Example with the command-line tool:

ghidra-mcp session open /path/to/firmware.bin \
  --processor ARM:LE:32:Cortex \
  --base-address 0x08000000 \
  --wait
  • When a file name ends in .bin, .hex, .ihex or .srec, the daemon keeps that lowercase extension on binary.<ext>.
  • For .srec files, the daemon selects MotorolaHexLoader when loader has no value.
  • ImportBinary.java aligns the program image base and the default memory blocks with baseAddress before Bridge.java starts.
  • The daemon saves the import flags in binary.json.
  • If a saved project already exists and a call gives different import flags, set reimport to true (--reimport).

Attach a local .gpr project

You can attach a Ghidra .gpr project on the daemon host without a file copy. This workflow keeps custom image bases, memory maps and saved symbols from Ghidra GUI.

Example with ghidra_session open:

{
  "operation": "open",
  "params": {
    "path": "/path/to/board.gpr",
    "programName": "firmware/app",
    "wait": true
  }
}

Example with the command-line tool:

ghidra-mcp session open /path/to/board.gpr --program-name firmware/app --wait
  • The .gpr file must have its <name>.rep directory beside it, and <name> must not start with ..
  • The daemon calculates a deterministic 32-character hexadecimal md5 from the canonical .gpr path and writes projects/<md5>/attached.json.
  • Use that md5 in subsequent tool calls and in ghidra_session open to reopen the project or change programName.
  • If the project has one Program, programName (--program-name) is optional.
  • If the project has multiple programs and programName is absent, open fails and lists the candidate program paths.
  • Before OpenSavedProject.java runs, the daemon checks <name>.lock and <name>.lock~ in read-only mode and modifies no project files.
  • If Ghidra GUI or another process holds the project lock, open fails at once. Close the project in Ghidra GUI first.
  • Binary import flags (processor, compilerSpec, loader, baseAddress and reimport) and ghidra_upload prepare do not apply to .gpr projects.

Attach an open Ghidra GUI program

To connect an open Ghidra CodeBrowser program to the daemon, use this procedure:

  1. Write the launcher scripts into your Ghidra script directory (~/ghidra_scripts by default):

    ghidra-mcp setup
  2. Open the Script Manager in CodeBrowser and run Bridge.java. The Console prints the loopback listener URL (ws://127.0.0.1:8765/ws/agent by default).

  3. Attach the daemon to that listener:

    ghidra-mcp session attach ws://127.0.0.1:8765/ws/agent

    You can also pass --port 8765, or pass a local file path with --port 8765 to use its MD5. The command does not copy the binary.

  4. When Bridge.java sends ghidra.ready, the session enters the ready state. A disconnect leaves CodeBrowser open and does not start analyzeHeadless.

If you omit --ws-url and --port, session attach prints outbound ws_url=... session_id=... token=... arguments instead.

Upload a binary from a remote client

Use this procedure when the client is not on the daemon host.

Remote Upload Sequence

  1. On the client, calculate the MD5 and the size in bytes of the file.

  2. Call the ghidra_upload tool:

    {"operation":"prepare","md5":"0123456789abcdef0123456789abcdef","params":{"fileName":"program.bin","size":1024}}

    fileName is a display name. It must not contain a directory. For raw firmware, params also accepts processor, compilerSpec, loader, baseAddress and reimport (see Import raw firmware). The daemon keeps .bin, .hex, .ihex and .srec extensions from fileName.

  3. Read the result. It contains these fields:

    • method: POST.
    • url: An absolute URL for HTTP calls, for example https://host/ghidra/upload. Other transports return upload, relative to the MCP URL.
    • headers: a single-use Authorization: Bearer credential and Content-Type: application/octet-stream.
    • expiresAt: the expiry time in Unix seconds.
  4. Send the file as the raw request body with the headers from the result:

    curl -X POST 'https://host/ghidra/upload' \
      -H 'Authorization: Bearer <credential>' \
      -H 'Content-Type: application/octet-stream' \
      --data-binary @program.bin
  5. Read the response:

    • HTTP 200: the session is ready.
    • HTTP 202: the session starts. Use ghidra_job wait with the returned jobId.

You do not need a separate ghidra_session open call.

Note

  • The upload goes directly to disk. It can be larger than the MCP request limit. The daemon accepts HTTP chunked transfer.
  • You must start the upload within ten minutes after ghidra_upload prepare. This limit does not apply to an active upload.
  • The request uses the credential when it starts. After an upload fails, get a new credential.
  • The daemon examines the size and the MD5 before it saves the binary. A failed upload leaves no file and no session.
  • If Ghidra does not start, the binary stays saved. Use ghidra_session open with the MD5 to retry.
  • A reverse proxy must send both /mcp and /upload to the daemon, with the same prefix.

The server uses Forwarded host and protocol values first, then X-Forwarded-Host and X-Forwarded-Proto. X-Forwarded-Prefix supplies a path prefix that the proxy removed.

The server can also use an absolute HTTP or HTTPS Referer whose path ends in /mcp. It does not use a Referer that points to a client page. Without these headers, the server uses the HTTP request address. An invalid protocol or path prefix leaves the URL relative. The proxy must replace client-supplied address headers with the correct public values.

Use with coding agents

Coding agents start ghidra-mcp as a stdio server, or connect to the HTTP URL. Agents that use the same runtime directory share one daemon.

Reverse Engineering Flow

For Claude Code, add the executable as a local stdio server:

claude mcp add --transport stdio --scope local ghidra-mcp -- /absolute/path/to/ghidra-mcp

To examine the connection, use claude mcp get ghidra-mcp or the /mcp panel. The status must be Status: ✓ Connected.

Use this procedure in an agent:

  1. Open the binary or project:
    • For a session that the daemon saved before, call ghidra_session with {"operation":"open","md5":"..."}.
    • For a binary on the daemon host, call ghidra_session with {"operation":"open","params":{"path":"..."}}. The daemon calculates the MD5 and saves the binary.
    • For raw firmware, add processor and baseAddress in params (see Import raw firmware).
    • For a local Ghidra project, pass its .gpr path in params.path (see Attach a local .gpr project).
    • For a file on a remote client, upload it (see Upload a binary from a remote client).
    • For a program that is already open in CodeBrowser, call ghidra_session with {"operation":"attach"} and paste bridgeArgs into Bridge.java.
  2. If the session starts, call ghidra_job with {"operation":"wait","params":{"jobId":"...","timeoutMs":...}}. You can use ghidra_job get to monitor the job.
  3. Confirm the ready status with ghidra_session get.
  4. Start the analysis: call ghidra_analysis with {"operation":"start","md5":"..."}.
  5. Monitor the analysis job with ghidra_job get or ghidra_job wait.
  6. Use the domain tools of the bridge, for example ghidra_program get, ghidra_function list and ghidra_data_type create.
  7. Save the analysis and the changes with ghidra_program save. The session stays open.
  8. Get approval from the user before you use an operation that changes the program.

A session summary contains only md5, fileName, status and connected. Operations that name one session use md5. There is no separate session ID. ghidra_session list is optional. For an MD5 that the daemon does not know, the daemon tells you to upload the binary.

Configuration

At the first start, the daemon writes a default config.toml in the persistent home. This example shows all the keys with their default values:

[ghidra]
home = ""
analyze_headless = ""

[analysis]
max_cpu = 4

[checkpoints]
max_per_binary = 10

[timeouts]
process_spawn_timeout_sec = 30
analysis_import_timeout_sec = 1800
bridge_connect_timeout_sec = 30
agent_ready_timeout_sec = 30
bridge_disconnect_grace_sec = 5
graceful_kill_timeout_sec = 10
force_kill_timeout_sec = 5
rpc_ms = 30000
daemon_start_timeout_sec = 8
ipc_handshake_timeout_sec = 5
Key Purpose
ghidra.home The Ghidra installation directory.
ghidra.analyze_headless The path of analyzeHeadless.
analysis.max_cpu The value of analyzeHeadless -max-cpu.
checkpoints.max_per_binary The maximum number of retained checkpoints for one binary.
timeouts.process_spawn_timeout_sec The time to start the Ghidra process.
timeouts.analysis_import_timeout_sec The time to import a binary. It is also the default wait for ghidra_analysis start.
timeouts.bridge_connect_timeout_sec A part of the total time to start a session.
timeouts.agent_ready_timeout_sec The time for the bridge to complete its handshake.
timeouts.bridge_disconnect_grace_sec The time for a process to stop by itself after its bridge disconnects or its session closes.
timeouts.graceful_kill_timeout_sec The time for a process to stop after the daemon tells it to stop.
timeouts.force_kill_timeout_sec The time for a process to stop after the daemon kills it.
timeouts.rpc_ms The time for one bridge request, in milliseconds.
timeouts.daemon_start_timeout_sec The time to wait for a daemon in proxy or CLI mode.
timeouts.ipc_handshake_timeout_sec The timeout for the IPC handshake between proxy and daemon.
  • An empty string for home or analyze_headless has the same effect as no value.
  • The daemon ignores other sections and keys. The file must be valid TOML.
  • Java temporary files always go into the tmp/ directory of the runtime directory.
  • The daemon does not accept the removed keys ghidra.java_tmp_dir, ghidra.script_path and ghidra.bridge_script. Remove them from your file.

The MCP tools

tools/list shows 19 MCP tools: ghidra_help and one tool for each domain. The bridge domain tools use the domain and operation names of the bridge MCP server. The daemon also has local operations and does not expose the bridge shutdown operation. This document writes an operation as the tool name and the operation name, for example ghidra_session open.

A domain tool has these arguments:

  • operation: necessary. The operation in the domain, for example list.
  • md5: the MD5 of the binary that identifies a session. It has exactly 32 hexadecimal characters and is never in params. Use the digest of the file or the MD5 of a session that is available, not a name. Each operation has an md5 rule: required, optional or absent.
  • params: the parameters of the operation. The default is {}.
Tool Operations Runs in
ghidra_session open, attach, list, get, close, checkpoint.create, checkpoint.list, checkpoint.restore, reset, delete The daemon.
ghidra_upload prepare The daemon.
ghidra_job list, get, wait The daemon.
ghidra_daemon status, shutdown The daemon.
ghidra_analysis start, get start: the daemon, then the bridge. get: the bridge.
ghidra_bridge, ghidra_program, ghidra_address, ghidra_memory, ghidra_listing, ghidra_global_variable, ghidra_function, ghidra_decompilation, ghidra_symbol, ghidra_reference, ghidra_comment, ghidra_data_type, ghidra_batch The bridge methods of the domain. The bridge of the session.

The bridge contract bridge/docs/asyncapi.yaml gives the bridge methods, their schemas and their read_only effects. The daemon sends only the methods in this contract. It does not show interface.get and session.shutdown. To stop a session, use ghidra_session close. The parameters use the objects of the bridge, for example selector, filter, page, patch and resource.

Examples for ghidra_function get and ghidra_comment upsert:

{"operation":"get","md5":"0123456789abcdef0123456789abcdef","params":{"selector":{"entry":"ram:00100000"}}}
{"operation":"upsert","md5":"0123456789abcdef0123456789abcdef","params":{"resource":{"address":"ram:00100000","type":"eol","text":"checked"}}}

To create a function, use ghidra_function with its entry address:

{
  "operation": "create",
  "md5": "0123456789abcdef0123456789abcdef",
  "params": {
    "resource": { "entry": "ram:00100000", "name": "my_function" },
    "disassemble": true
  }
}

The name is optional. By default, the entry must have an instruction. Set disassemble to true to decode instructions when the entry has none. The operation fails if the entry or the function body overlaps a function. It creates a regular function. It does not identify a thunk.

To delete a function, use its entry address in selector:

{
  "operation": "delete",
  "md5": "0123456789abcdef0123456789abcdef",
  "params": { "selector": { "entry": "ram:00100000" } }
}

The operation removes the function definition and its local variables. It keeps the instructions and data.

To get the decompiler view as editor lines, use ghidra_decompilation with format document:

{
  "operation": "get",
  "md5": "0123456789abcdef0123456789abcdef",
  "params": {
    "selector": { "entry": "ram:00100000" },
    "format": "document",
    "include_comments": true
  }
}

Each token has zero-based UTF-16 columns and the address that the Ghidra GUI selects. Set include_comments to show all comment types and to return the repeatable comments. If comments_complete is false, the comment list is not complete.

To apply C++ names to all mangled primary symbols, use ghidra_symbol:

{ "operation": "demangle", "md5": "0123456789abcdef0123456789abcdef", "params": {} }

The operation changes names and namespaces only. It keeps function signatures and data types. Function, symbol, and call results also give demangled_name without a change to the program.

Before the first call to an operation, call ghidra_help with the domain and operation. Its inputSchema describes the contents of params, not the top-level tool arguments. Check the required fields and their nested structure before the call.

The ghidra_help tool describes all tools:

  • {} lists the domain tools.
  • {"domain":"function"} lists the operations of one domain with each operation description, md5 rule, effects, and inputSchema.
  • {"domain":"function","operation":"list"} shows the full parameter schema, the md5 rule and the effects of one operation. The effects are the same as in the bridge contract, for example read_only, mutates_program and destructive.

If the Ghidra process does not start, the session goes to error and its launch job goes to failed. With wait=false, ghidra_session open returns immediately. Use ghidra_session get and ghidra_job get to see the result. With wait=true, ghidra_session open waits and returns the error.

The MD5 hash identifies each session. The daemon manages session states through a finite state machine:

Session Lifecycle

When a tool call fails, structuredContent contains a machine-readable JSON-RPC error code:

  • -32602 (invalid_argument): An unknown tool, or invalid or absent tool arguments or operation parameters.
  • -32001 (session_lock_timeout, agent_timeout, request_in_flight): Lock timeout or request collision.
  • -32002 (missing_target): Unknown binary MD5, session, job ID, domain, or operation.
  • -32000 (disconnected, shutting_down): Disconnected bridge session or daemon shutdown.
  • -32603 (transaction_failed, bridge_internal, internal_error): Ghidra transaction failure or internal error. Database transaction failures return code -32603 (transaction_failed). They do not return as invalid arguments.

Files and directories

On Unix, the persistent data and the runtime data are in different locations:

GHIDRA_MCP_HOME/                 # default: ~/.ghidra-mcp
|-- config.toml
`-- projects/<md5>/
    |-- binary                  # Saved binary (or binary.bin, .hex, .ihex, .srec)
    |-- binary.json             # File name and firmware import flags
    |-- attached.json           # Attached .gpr path and program name
    |-- checkpoints/            # Saved project snapshots
    |-- recovery-backups/       # Crash recovery backups
    `-- ghidra/
        |-- project.gpr
        `-- project.rep/

<runtime-base>/ghidra-mcp-<uid>/
|-- projects -> GHIDRA_MCP_HOME/projects
|-- attached/<md5> -> <gpr-parent>
|-- sessions/<md5>/session.json
|-- logs/<md5>/
|-- tmp/
|-- daemon.sock
|-- daemon.log
|-- daemon.lock
|-- server.json
|-- ghidra-bridge.jar
`-- Bridge.java
  • The runtime base is XDG_RUNTIME_DIR on Linux. Otherwise, it is the temporary directory of the system.
  • If the runtime base has a hidden segment, the daemon uses /tmp instead. Ghidra does not accept hidden segments.
  • The runtime directory has the mode 0700. The daemon log and the lock file have the mode 0600.
  • Ghidra cannot open a project in a hidden directory. For this reason, the daemon gives Ghidra the projects symbolic link. The project files stay in the persistent home.
  • If the projects path holds a different object, the daemon stops with an error. It does not replace the object.
  • For an attached .gpr session, the daemon creates the non-hidden symbolic link attached/<md5> to the parent directory of the .gpr file.

On Windows, the default layout is:

%LOCALAPPDATA%\ghidra-mcp\
|-- config.toml
|-- projects\<md5>\
|   |-- binary
|   |-- binary.json
|   |-- attached.json
|   |-- checkpoints\
|   |-- recovery-backups\
|   `-- ghidra\
|       |-- project.gpr
|       `-- project.rep\
`-- run\
    |-- sessions\<md5>\session.json
    |-- logs\<md5>\
    |-- tmp\
    |-- daemon.log
    |-- daemon.lock
    |-- server.json
    |-- ghidra-bridge.jar
    `-- Bridge.java
  • GHIDRA_MCP_HOME moves the configuration and the projects. The runtime directory stays in %LOCALAPPDATA%\ghidra-mcp\run.
  • Ghidra opens the project directly. There is no symbolic link.
  • Clients connect through a named pipe. server.json contains its random name. Only the owner can connect. Remote clients cannot connect.

On all platforms:

  • One daemon runs for each runtime directory. A file lock enforces this rule. There is no PID file.
  • Each runtime directory uses one persistent home. To change GHIDRA_MCP_HOME, stop the daemon and clear the runtime directory first. The projects in the old home stay available.
  • You can delete the runtime directory when the daemon does not run. Then ghidra_session open with the MD5 opens the saved project again.
  • The daemon opens a project again when project.gpr and project.rep exist. Ghidra replays its recovery journal.
  • The daemon does not change a project directory that it does not recognize. It shows an error.
  • The daemon bounds all log files (daemon.log, stdout.log, stderr.log) to 10 MiB.
  • The forwarder truncates oversized log lines. It replaces lines above 10 MiB with [TRUNCATED_LOG_LINE].
  • When a log file reaches 10 MiB, the daemon rotates it and keeps up to three backups (.1, .2, .3).
  • The daemon replaces sensitive authentication tokens in log lines with [REDACTED_TOKEN].
  • On Windows, the daemon closes active write handles before it renames log files.
  • The daemon rotates daemon.log before it opens a file larger than 10 MiB.

Validation and releases

To do the same checks as CI, use these commands:

cargo xtask ci
cargo xtask build --release --locked --bin ghidra-mcp

Or run the checks separately:

cargo xtask check
cargo fmt --all -- --check
cargo clippy --workspace --all-targets --locked -- -D warnings
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items --locked

CI builds release executables on macOS, Linux and Windows, for x86_64 and ARM64. Each push to main, each pull request and each manual run starts all six builds. A failed build does not stop the other builds. The Windows executables link the C runtime statically.

release-please sets the versions from the Conventional Commits on main:

  • fix: gives a patch release.
  • feat: gives a minor release.
  • ! or BREAKING CHANGE: gives a major release.

release-please opens a release pull request. This pull request updates the workspace version, Cargo.lock, CHANGELOG.md and the release manifest. After you merge it, release-please creates a version tag and a draft release at a fixed commit. All six builds and the dependency audit use that commit.

After those checks pass, CI attaches the executables, SHA-256 checksums and license texts. Then CI publishes the npm packages and makes the draft public. Failed checks leave the release as a draft. Rerun the failed jobs. CI does not publish an npm package again if npm has that version.

CI uses the default GITHUB_TOKEN for GitHub. For npm, CI uses trusted publishers through GitHub OIDC. You do not need other secrets. Each npm package must have a trusted publisher for this repository and the ci.yml workflow.

Note

  • The repository must let GitHub Actions make pull requests.
  • A CI run for a release pull request from GITHUB_TOKEN must have maintainer approval. Approve the run before you merge.

Troubleshooting

For runbooks about Ghidra discovery, Java 21, socket permissions, memory, and logs, read the Troubleshooting guide.

The daemon cannot find analyzeHeadless

  • Set GHIDRA_INSTALL_DIR or GHIDRA_HOME.
  • Alternatively, put analyzeHeadless or ghidraRun on PATH.

The bridge JAR is absent

  • Make sure that ghidra-bridge.jar is in the runtime directory.
  • If you changed the bridge source, run cargo xtask build again. The xtask command builds and embeds the bridge again.

The daemon does not start

  • Read daemon.log in the runtime directory.
  • Make sure that no other program uses the HTTP address. To let the system select a free port, use --listen 127.0.0.1:0.
  • daemon.lock stops a second daemon in the same runtime directory. Do not delete the runtime files while the daemon runs.

Documentation

Contribute

We welcome contributions. CONTRIBUTING.md gives the prerequisites, the standards for code and text, and the extension procedures. The code of conduct applies to all participants.

The Rust code is in src/. The xtask/ directory contains automation tools. The Java bridge is a Git submodule. Clone with --recurse-submodules, or use git submodule update --init --recursive.

License

The MIT License applies to this project. The Java bridge in bridge/ has a separate license. See bridge/LICENSE.

About

Headless Ghidra analysis for MCP clients. Clients can start sessions, decompile code, examine symbols, and change Ghidra programs.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages