@ghidra-mcp/cli 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ByteLand Technology Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,689 @@
1
- # Temporary Holding Version
1
+ # ghidra-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [English](README.md) | [中文](README.zh-CN.md) | [日本語](README.ja-JP.md)
4
+
5
+ ![Rust](https://img.shields.io/badge/Rust-2021-000000?logo=rust)
6
+ ![MCP](https://img.shields.io/badge/MCP-stdio%20%7C%20HTTP-1f6feb)
7
+ ![CI](https://github.com/ByteLandTechnology/ghidra-mcp/actions/workflows/ci.yml/badge.svg)
8
+ ![License](https://img.shields.io/badge/license-MIT-blue.svg)
9
+
10
+ `ghidra-mcp` is an MCP server and a command-line tool for headless Ghidra analysis.
11
+
12
+ One local daemon runs the Ghidra sessions on Linux, macOS and Windows.
13
+ MCP clients connect to the daemon through stdio or HTTP.
14
+ The command-line tool uses the same daemon.
15
+ The MD5 of a binary identifies its session for all clients.
16
+
17
+ > [!IMPORTANT]
18
+ > The daemon keeps configuration, binaries and analysis in the **persistent home**.
19
+ > The default persistent home is `~/.ghidra-mcp` on Linux and macOS, and `%LOCALAPPDATA%\ghidra-mcp` on Windows.
20
+ > To use a different directory, set `GHIDRA_MCP_HOME`.
21
+ > The daemon keeps temporary files in a private **runtime directory**.
22
+ > If the daemon does not run, stdio clients and the command-line tool start it.
23
+
24
+ ![System Architecture](docs/img/architecture.svg)
25
+
26
+ ## Contents
27
+
28
+ - [Features](#features)
29
+ - [Get started](#get-started)
30
+ - [Usage](#usage)
31
+ - [Use with coding agents](#use-with-coding-agents)
32
+ - [Configuration](#configuration)
33
+ - [The MCP tools](#the-mcp-tools)
34
+ - [Files and directories](#files-and-directories)
35
+ - [Validation and releases](#validation-and-releases)
36
+ - [Troubleshooting](#troubleshooting)
37
+ - [Documentation](#documentation)
38
+ - [Contribute](#contribute)
39
+ - [License](#license)
40
+
41
+ ## Features
42
+
43
+ - **MCP through stdio, Streamable HTTP, or legacy SSE.** One daemon keeps the shared state.
44
+ - **Command-line client.** It lists the tools locally. It calls the tools through the daemon.
45
+ - **Sessions identified by MD5.** The daemon uses a session again or opens the saved analysis again.
46
+ - **Persistent sessions and jobs.** Sessions and analysis jobs continue after a client disconnects.
47
+ - **Remote upload.** A client that is not on the daemon host sends a binary through a separate HTTP endpoint.
48
+ - **Full Ghidra access.** The Java bridge gives program data, functions, decompilation, symbols, references, memory and comments.
49
+ - **One executable.** The executable contains the bridge JAR and its launcher script.
50
+ - **Background jobs.** `ghidra_job get` and `ghidra_job wait` monitor a long analysis.
51
+
52
+ Sessions can change the program by default.
53
+ Coding agents must get approval from the user before they use an operation that changes the program.
54
+
55
+ ## Get started
56
+
57
+ For client setup snippets and walkthroughs, read the
58
+ [First Steps guide](docs/getting-started.md).
59
+
60
+ ### Prerequisites
61
+
62
+ - Linux, macOS or Windows.
63
+ - Java 21.
64
+ - A local Ghidra installation that has `analyzeHeadless` (`analyzeHeadless.bat` on Windows).
65
+
66
+ ### Install with npm
67
+
68
+ If you have Node.js 18 or later, npm can install the executable for your platform:
69
+
70
+ ```sh
71
+ npx @ghidra-mcp/cli tools
72
+ ```
73
+
74
+ Or install the command for all projects:
75
+
76
+ ```sh
77
+ npm install --global @ghidra-mcp/cli
78
+ ghidra-mcp tools
79
+ ```
80
+
81
+ To use `npx` from an MCP client:
82
+
83
+ ```json
84
+ {
85
+ "command": "npx",
86
+ "args": ["-y", "@ghidra-mcp/cli"]
87
+ }
88
+ ```
89
+
90
+ npm installs one platform package, such as `@ghidra-mcp/linux-x64`.
91
+ Do not use `--omit=optional`, because the platform packages are optional dependencies.
92
+ The Linux packages need glibc. On musl systems, such as Alpine, use [Build from source](#build-from-source).
93
+ The executable must also find Ghidra (see [Find Ghidra](#find-ghidra)).
94
+
95
+ ### Use a prebuilt executable
96
+
97
+ 1. Download the file for your platform from [GitHub Releases](https://github.com/ByteLandTechnology/ghidra-mcp/releases).
98
+
99
+ | Platform | x86_64 | ARM64 |
100
+ | --- | --- | --- |
101
+ | macOS | `ghidra-mcp-macos-x86_64` | `ghidra-mcp-macos-arm64` |
102
+ | Linux | `ghidra-mcp-linux-x86_64` | `ghidra-mcp-linux-arm64` |
103
+ | Windows | `ghidra-mcp-windows-x86_64.exe` | `ghidra-mcp-windows-arm64.exe` |
104
+
105
+ 2. Rename the file to `ghidra-mcp` (`ghidra-mcp.exe` on Windows).
106
+ 3. On Linux and macOS, make the file executable with `chmod +x ghidra-mcp`.
107
+ 4. Make sure that the executable can find Ghidra (see [Find Ghidra](#find-ghidra)). For example, on Windows:
108
+
109
+ ```powershell
110
+ $env:GHIDRA_INSTALL_DIR = 'C:\Tools\ghidra_12.1.4_PUBLIC'
111
+ .\ghidra-mcp.exe tools
112
+ ```
113
+
114
+ 5. Add the executable to your MCP client:
115
+
116
+ ```json
117
+ {
118
+ "command": "C:\\Tools\\ghidra-mcp.exe",
119
+ "args": []
120
+ }
121
+ ```
122
+
123
+ The executable needs only Ghidra and Java.
124
+ It writes the bridge files into the runtime directory when it opens a session.
125
+
126
+ ### Build from source
127
+
128
+ To build from source, you also need:
129
+
130
+ - A Rust toolchain.
131
+ - The `bridge/` submodule. The build uses the Gradle wrapper of the submodule.
132
+ - A Ghidra installation in `GHIDRA_INSTALL_DIR` or `GHIDRA_HOME`. The bridge compiles against this installation.
133
+
134
+ 1. If you cloned the repository without submodules, get the bridge:
135
+
136
+ ```sh
137
+ git submodule update --init --recursive
138
+ ```
139
+
140
+ 2. Build the release executable:
141
+
142
+ ```sh
143
+ cargo xtask build --release --locked --bin ghidra-mcp
144
+ ```
145
+
146
+ The result is `target/release/ghidra-mcp` (`ghidra-mcp.exe` on Windows).
147
+ This one file is the complete distribution.
148
+
149
+ The command `cargo xtask build` builds the bridge with Gradle.
150
+ Then it embeds the bridge JAR and `Bridge.java` in the executable.
151
+ The operation catalog comes from the bridge contract `bridge/docs/asyncapi.yaml` at compile time.
152
+
153
+ To embed a bridge JAR that you built before, set `GHIDRA_MCP_BRIDGE_JAR`.
154
+ A relative path starts at the workspace root.
155
+ The build then makes only `Bridge.java` and does not compile the bridge.
156
+
157
+ ### Find Ghidra
158
+
159
+ Before it serves MCP, the daemon checks that it can find an executable `analyzeHeadless`.
160
+ If this check fails, it writes the error to stderr and `daemon.log`, then exits with status `1`.
161
+
162
+ The daemon finds `analyzeHeadless` in this order:
163
+
164
+ 1. `[ghidra].analyze_headless` in `config.toml`.
165
+ 2. The installation in `[ghidra].home`, `GHIDRA_INSTALL_DIR` or `GHIDRA_HOME`.
166
+ 3. `analyzeHeadless` on `PATH`.
167
+ 4. The installation of `ghidraRun` on `PATH`.
168
+ 5. On Unix, the Homebrew Cellar and directories named `ghidra*` in `/Applications`, `~`, `~/Applications` and `~/opt`.
169
+
170
+ > [!TIP]
171
+ > If a computer has more than one Ghidra installation, set `GHIDRA_INSTALL_DIR`.
172
+
173
+ ## Usage
174
+
175
+ The default configuration does not need environment variables.
176
+ These optional variables change the defaults:
177
+
178
+ | Variable | Purpose |
179
+ | --- | --- |
180
+ | `GHIDRA_INSTALL_DIR` | The Ghidra installation directory. |
181
+ | `GHIDRA_HOME` | Another name for the installation directory. `GHIDRA_INSTALL_DIR` has priority. |
182
+ | `GHIDRA_MCP_HOME` | The persistent home. |
183
+
184
+ Ghidra also uses the standard Java variables `JAVA_HOME` and `JAVA_TOOL_OPTIONS`.
185
+ On Unix, `XDG_RUNTIME_DIR` and `TMPDIR` set the location of the runtime directory.
186
+
187
+ ### Stdio server
188
+
189
+ An MCP client starts `ghidra-mcp` without arguments and talks to it through stdio:
190
+
191
+ ```json
192
+ {
193
+ "command": "/path/to/ghidra-mcp",
194
+ "args": []
195
+ }
196
+ ```
197
+
198
+ This process sends each tool call to the daemon.
199
+ If the daemon does not run, the process starts it.
200
+ The process connects to the daemon through a local socket.
201
+ On Unix, the socket is a private Unix domain socket.
202
+ On Windows, the socket is a named pipe.
203
+
204
+ The process reuses this connection across tool calls to avoid repeated handshake delays.
205
+ If the daemon stops, the process reconnects on the next call.
206
+
207
+ To run from a source checkout, use `cargo run --` as the command.
208
+
209
+ ### HTTP server
210
+
211
+ To run the daemon in the foreground, use this command:
212
+
213
+ ```sh
214
+ ghidra-mcp --daemon
215
+ ```
216
+
217
+ The daemon serves these endpoints on one listener:
218
+
219
+ | Endpoint | Purpose |
220
+ | --- | --- |
221
+ | `http://127.0.0.1:18489/mcp` | MCP through Streamable HTTP or legacy SSE. |
222
+ | `/upload` | Binary uploads. |
223
+ | `/ws/agent` | The WebSocket of the Ghidra bridge. |
224
+
225
+ The daemon accepts only loopback addresses.
226
+ To use a different address, use `--listen`:
227
+
228
+ ```sh
229
+ ghidra-mcp --daemon --listen 127.0.0.1:18490
230
+ ```
231
+
232
+ With `--listen 127.0.0.1:0`, the system selects a free port.
233
+ The daemon writes the address in `server.json` and `daemon.log` in the runtime directory.
234
+
235
+ The daemon continues to run after all clients disconnect.
236
+ To stop a foreground daemon, press Ctrl-C.
237
+ On Unix, `SIGINT`, `SIGTERM` and `SIGHUP` also stop it.
238
+ When the daemon stops, it closes its Ghidra sessions.
239
+ You can open the saved projects again later.
240
+
241
+ ### Command-line tool
242
+
243
+ The command-line tool uses the same tool catalog as MCP.
244
+
245
+ To list the tools without a daemon, use this command:
246
+
247
+ ```sh
248
+ ghidra-mcp tools
249
+ ```
250
+
251
+ To call a tool through the daemon, use this command:
252
+
253
+ ```sh
254
+ ghidra-mcp call ghidra_session '{"operation":"list"}'
255
+ ```
256
+
257
+ `call TOOL [JSON]` accepts one JSON object. The default is `{}`.
258
+ If necessary, the command starts the daemon.
259
+ The command writes `structuredContent` as formatted JSON.
260
+
261
+ | Result | Output | Exit code |
262
+ | --- | --- | --- |
263
+ | The call is successful. | The result on stdout. | 0 |
264
+ | The call fails. | The error on stderr. | 1 |
265
+ | The arguments are not valid. | The usage on stderr. | 2 |
266
+ | `--help` or `--version`. | The text on stdout. | 0 |
267
+
268
+ ### Upload a binary from a remote client
269
+
270
+ Use this procedure when the client is not on the daemon host.
271
+
272
+ ![Remote Upload Sequence](docs/img/remote_upload.svg)
273
+
274
+ 1. On the client, calculate the MD5 and the size in bytes of the file.
275
+ 2. Call the `ghidra_upload` tool:
276
+
277
+ ```json
278
+ {"operation":"prepare","md5":"0123456789abcdef0123456789abcdef","params":{"fileName":"program.bin","size":1024}}
279
+ ```
280
+
281
+ `fileName` is a display name. It must not contain a directory.
282
+ 3. Read the result. It contains these fields:
283
+ - `method`: `POST`.
284
+ - `url`: An absolute URL for HTTP calls, for example `https://host/ghidra/upload`.
285
+ Other transports return `upload`, relative to the MCP URL.
286
+ - `headers`: a single-use `Authorization: Bearer` credential and `Content-Type: application/octet-stream`.
287
+ - `expiresAt`: the expiry time in Unix seconds.
288
+ 4. Send the file as the raw request body with the headers from the result:
289
+
290
+ ```sh
291
+ curl -X POST 'https://host/ghidra/upload' \
292
+ -H 'Authorization: Bearer <credential>' \
293
+ -H 'Content-Type: application/octet-stream' \
294
+ --data-binary @program.bin
295
+ ```
296
+
297
+ 5. Read the response:
298
+ - HTTP `200`: the session is ready.
299
+ - HTTP `202`: the session starts. Use `ghidra_job wait` with the returned `jobId`.
300
+
301
+ You do not need a separate `ghidra_session open` call.
302
+
303
+ > [!NOTE]
304
+ > - The upload goes directly to disk. It can be larger than the MCP request limit. The daemon accepts HTTP chunked transfer.
305
+ > - You must start the upload within ten minutes after `ghidra_upload prepare`.
306
+ > This limit does not apply to an active upload.
307
+ > - The request uses the credential when it starts. After an upload fails, get a new credential.
308
+ > - The daemon examines the size and the MD5 before it saves the binary. A failed upload leaves no file and no session.
309
+ > - If Ghidra does not start, the binary stays saved. Use `ghidra_session open` with the MD5 to retry.
310
+ > - A reverse proxy must send both `/mcp` and `/upload` to the daemon, with the same prefix.
311
+
312
+ The server uses `Forwarded` host and protocol values first, then `X-Forwarded-Host` and
313
+ `X-Forwarded-Proto`.
314
+ `X-Forwarded-Prefix` supplies a path prefix that the proxy removed.
315
+
316
+ The server can also use an absolute HTTP or HTTPS `Referer` whose path ends in `/mcp`.
317
+ It does not use a Referer that points to a client page.
318
+ Without these headers, the server uses the HTTP request address.
319
+ An invalid protocol or path prefix leaves the URL relative.
320
+ The proxy must replace client-supplied address headers with the correct public values.
321
+
322
+ ## Use with coding agents
323
+
324
+ Coding agents start `ghidra-mcp` as a stdio server, or connect to the HTTP URL.
325
+ Agents that use the same runtime directory share one daemon.
326
+
327
+ ![Reverse Engineering Flow](docs/img/reverse_engineering_flow.svg)
328
+
329
+ For Claude Code, add the executable as a local stdio server:
330
+
331
+ ```sh
332
+ claude mcp add --transport stdio --scope local ghidra-mcp -- /absolute/path/to/ghidra-mcp
333
+ ```
334
+
335
+ To examine the connection, use `claude mcp get ghidra-mcp` or the `/mcp` panel.
336
+ The status must be `Status: ✓ Connected`.
337
+
338
+ Use this procedure in an agent:
339
+
340
+ 1. Open the binary:
341
+ - For a binary that the daemon saved before, call `ghidra_session` with `{"operation":"open","md5":"..."}`.
342
+ - For a file on the daemon host, call `ghidra_session` with `{"operation":"open","params":{"path":"..."}}`. The daemon calculates the MD5 and saves the binary.
343
+ - For a file on a remote client, upload it (see [Upload a binary from a remote client](#upload-a-binary-from-a-remote-client)).
344
+ 2. If the session starts, call `ghidra_job` with `{"operation":"wait","params":{"jobId":"...","timeoutMs":...}}`.
345
+ You can use `ghidra_job get` to monitor the job.
346
+ 3. Confirm the ready status with `ghidra_session get`.
347
+ 4. Start the analysis: call `ghidra_analysis` with `{"operation":"start","md5":"..."}`.
348
+ 5. Monitor the analysis job with `ghidra_job get` or `ghidra_job wait`.
349
+ 6. Use the domain tools of the bridge, for example `ghidra_program get`, `ghidra_function list` and `ghidra_data_type create`.
350
+ 7. Save the analysis and the changes with `ghidra_program save`. The session stays open.
351
+ 8. Get approval from the user before you use an operation that changes the program.
352
+
353
+ A session summary contains only `md5`, `fileName`, `status` and `connected`.
354
+ Operations that name one session use `md5`. There is no separate session ID.
355
+ `ghidra_session list` is optional.
356
+ For an MD5 that the daemon does not know, the daemon tells you to upload the binary.
357
+
358
+ ## Configuration
359
+
360
+ At the first start, the daemon writes a default `config.toml` in the persistent home.
361
+ This example shows all the keys with their default values:
362
+
363
+ ```toml
364
+ [ghidra]
365
+ home = ""
366
+ analyze_headless = ""
367
+
368
+ [analysis]
369
+ max_cpu = 4
370
+
371
+ [timeouts]
372
+ process_spawn_timeout_sec = 30
373
+ analysis_import_timeout_sec = 1800
374
+ bridge_connect_timeout_sec = 30
375
+ agent_ready_timeout_sec = 30
376
+ bridge_disconnect_grace_sec = 5
377
+ graceful_kill_timeout_sec = 10
378
+ force_kill_timeout_sec = 5
379
+ rpc_ms = 30000
380
+ daemon_start_timeout_sec = 8
381
+ ipc_handshake_timeout_sec = 5
382
+ ```
383
+
384
+ | Key | Purpose |
385
+ | --- | --- |
386
+ | `ghidra.home` | The Ghidra installation directory. |
387
+ | `ghidra.analyze_headless` | The path of `analyzeHeadless`. |
388
+ | `analysis.max_cpu` | The value of `analyzeHeadless -max-cpu`. |
389
+ | `timeouts.process_spawn_timeout_sec` | The time to start the Ghidra process. |
390
+ | `timeouts.analysis_import_timeout_sec` | The time to import a binary. It is also the default wait for `ghidra_analysis start`. |
391
+ | `timeouts.bridge_connect_timeout_sec` | A part of the total time to start a session. |
392
+ | `timeouts.agent_ready_timeout_sec` | The time for the bridge to complete its handshake. |
393
+ | `timeouts.bridge_disconnect_grace_sec` | The time for a process to stop by itself after its bridge disconnects or its session closes. |
394
+ | `timeouts.graceful_kill_timeout_sec` | The time for a process to stop after the daemon tells it to stop. |
395
+ | `timeouts.force_kill_timeout_sec` | The time for a process to stop after the daemon kills it. |
396
+ | `timeouts.rpc_ms` | The time for one bridge request, in milliseconds. |
397
+ | `timeouts.daemon_start_timeout_sec` | The time to wait for a daemon in proxy or CLI mode. |
398
+ | `timeouts.ipc_handshake_timeout_sec` | The timeout for the IPC handshake between proxy and daemon. |
399
+
400
+ - An empty string for `home` or `analyze_headless` has the same effect as no value.
401
+ - The daemon ignores other sections and keys. The file must be valid TOML.
402
+ - Java temporary files always go into the `tmp/` directory of the runtime directory.
403
+ - The daemon does not accept the removed keys `ghidra.java_tmp_dir`, `ghidra.script_path` and `ghidra.bridge_script`. Remove them from your file.
404
+
405
+ ## The MCP tools
406
+
407
+ `tools/list` shows 18 MCP tools: `ghidra_help` and one tool for each domain.
408
+ The bridge domain tools use the domain and operation names of the bridge MCP server.
409
+ The daemon also has local operations and does not expose the bridge shutdown operation.
410
+ This document writes an operation as the tool name and the operation name, for example `ghidra_session open`.
411
+
412
+ A domain tool has these arguments:
413
+
414
+ - `operation`: necessary. The operation in the domain, for example `list`.
415
+ - `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`.
416
+ - `params`: the parameters of the operation. The default is `{}`.
417
+
418
+ | Tool | Operations | Runs in |
419
+ | --- | --- | --- |
420
+ | `ghidra_session` | `open`, `list`, `get`, `close` | The daemon. |
421
+ | `ghidra_upload` | `prepare` | The daemon. |
422
+ | `ghidra_job` | `get`, `wait` | The daemon. |
423
+ | `ghidra_analysis` | `start`, `get` | `start`: the daemon, then the bridge. `get`: the bridge. |
424
+ | `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. |
425
+
426
+ The bridge contract `bridge/docs/asyncapi.yaml` gives the bridge methods, their schemas and their `read_only` effects.
427
+ The daemon sends only the methods in this contract.
428
+ It does not show `interface.get` and `session.shutdown`. To stop a session, use `ghidra_session close`.
429
+ The parameters use the objects of the bridge, for example `selector`, `filter`, `page`, `patch` and `resource`.
430
+
431
+ Examples for `ghidra_function get` and `ghidra_comment upsert`:
432
+
433
+ ```json
434
+ {"operation":"get","md5":"0123456789abcdef0123456789abcdef","params":{"selector":{"entry":"ram:00100000"}}}
435
+ {"operation":"upsert","md5":"0123456789abcdef0123456789abcdef","params":{"resource":{"address":"ram:00100000","type":"eol","text":"checked"}}}
436
+ ```
437
+
438
+ To create a function, use `ghidra_function` with its entry address:
439
+
440
+ ```json
441
+ {
442
+ "operation": "create",
443
+ "md5": "0123456789abcdef0123456789abcdef",
444
+ "params": {
445
+ "resource": { "entry": "ram:00100000", "name": "my_function" },
446
+ "disassemble": true
447
+ }
448
+ }
449
+ ```
450
+
451
+ The `name` is optional. By default, the entry must have an instruction.
452
+ Set `disassemble` to `true` to decode instructions when the entry has none.
453
+ The operation fails if the entry or the function body overlaps a function.
454
+ It creates a regular function. It does not identify a thunk.
455
+
456
+ To delete a function, use its entry address in `selector`:
457
+
458
+ ```json
459
+ {
460
+ "operation": "delete",
461
+ "md5": "0123456789abcdef0123456789abcdef",
462
+ "params": { "selector": { "entry": "ram:00100000" } }
463
+ }
464
+ ```
465
+
466
+ The operation removes the function definition and its local variables.
467
+ It keeps the instructions and data.
468
+
469
+ To get the decompiler view as editor lines, use `ghidra_decompilation` with format `document`:
470
+
471
+ ```json
472
+ {
473
+ "operation": "get",
474
+ "md5": "0123456789abcdef0123456789abcdef",
475
+ "params": {
476
+ "selector": { "entry": "ram:00100000" },
477
+ "format": "document",
478
+ "include_comments": true
479
+ }
480
+ }
481
+ ```
482
+
483
+ Each token has zero-based UTF-16 columns and the address that the Ghidra GUI selects.
484
+ Set `include_comments` to show all comment types and to return the repeatable comments.
485
+ If `comments_complete` is `false`, the comment list is not complete.
486
+
487
+ To apply C++ names to all mangled primary symbols, use `ghidra_symbol`:
488
+
489
+ ```json
490
+ { "operation": "demangle", "md5": "0123456789abcdef0123456789abcdef", "params": {} }
491
+ ```
492
+
493
+ The operation changes names and namespaces only. It keeps function signatures and data types.
494
+ Function, symbol, and call results also give `demangled_name` without a change to the program.
495
+
496
+ Before the first call to an operation, call `ghidra_help` with the domain and operation.
497
+ Its `inputSchema` describes the contents of `params`, not the top-level tool arguments.
498
+ Check the required fields and their nested structure before the call.
499
+
500
+ The `ghidra_help` tool describes all tools:
501
+
502
+ - `{}` lists the domain tools.
503
+ - `{"domain":"function"}` lists the operations of one domain.
504
+ - `{"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`.
505
+
506
+ If the Ghidra process does not start, the session goes to `error` and its launch job goes to `failed`.
507
+ With `wait=false`, `ghidra_session open` returns immediately. Use `ghidra_session get` and `ghidra_job get` to see the result.
508
+ With `wait=true`, `ghidra_session open` waits and returns the error.
509
+
510
+ The MD5 hash identifies each session.
511
+ The daemon manages session states through a finite state machine:
512
+
513
+ ![Session Lifecycle](docs/img/session_lifecycle.svg)
514
+
515
+ When a tool call fails, `structuredContent` contains a machine-readable JSON-RPC error code:
516
+ - `-32602` (`invalid_argument`): An unknown tool, or invalid or absent tool arguments or operation parameters.
517
+ - `-32001` (`session_lock_timeout`, `agent_timeout`, `request_in_flight`): Lock timeout or request collision.
518
+ - `-32002` (`missing_target`): Unknown binary MD5, session, job ID, domain, or operation.
519
+ - `-32000` (`disconnected`, `shutting_down`): Disconnected bridge session or daemon shutdown.
520
+ - `-32603` (`transaction_failed`, `bridge_internal`, `internal_error`): Ghidra transaction failure or internal error.
521
+ Database transaction failures return code `-32603` (`transaction_failed`).
522
+ They do not return as invalid arguments.
523
+
524
+ ## Files and directories
525
+
526
+ On Unix, the persistent data and the runtime data are in different locations:
527
+
528
+ ```text
529
+ GHIDRA_MCP_HOME/ # default: ~/.ghidra-mcp
530
+ |-- config.toml
531
+ `-- projects/<md5>/
532
+ |-- binary # The saved binary, with a fixed name
533
+ |-- binary.json # The original file name
534
+ `-- ghidra/
535
+ |-- project.gpr
536
+ `-- project.rep/
537
+
538
+ <runtime-base>/ghidra-mcp-<uid>/
539
+ |-- projects -> GHIDRA_MCP_HOME/projects
540
+ |-- sessions/<md5>/session.json
541
+ |-- logs/<md5>/
542
+ |-- tmp/
543
+ |-- daemon.sock
544
+ |-- daemon.log
545
+ |-- daemon.lock
546
+ |-- server.json
547
+ |-- ghidra-bridge.jar
548
+ `-- Bridge.java
549
+ ```
550
+
551
+ - The runtime base is `XDG_RUNTIME_DIR` on Linux. Otherwise, it is the temporary directory of the system.
552
+ - If the runtime base has a hidden segment, the daemon uses `/tmp` instead. Ghidra does not accept hidden segments.
553
+ - The runtime directory has the mode `0700`. The daemon log and the lock file have the mode `0600`.
554
+ - 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.
555
+ - If the `projects` path holds a different object, the daemon stops with an error. It does not replace the object.
556
+
557
+ On Windows, the default layout is:
558
+
559
+ ```text
560
+ %LOCALAPPDATA%\ghidra-mcp\
561
+ |-- config.toml
562
+ |-- projects\<md5>\
563
+ | |-- binary
564
+ | |-- binary.json
565
+ | `-- ghidra\
566
+ | |-- project.gpr
567
+ | `-- project.rep\
568
+ `-- run\
569
+ |-- sessions\<md5>\session.json
570
+ |-- logs\<md5>\
571
+ |-- tmp\
572
+ |-- daemon.log
573
+ |-- daemon.lock
574
+ |-- server.json
575
+ |-- ghidra-bridge.jar
576
+ `-- Bridge.java
577
+ ```
578
+
579
+ - `GHIDRA_MCP_HOME` moves the configuration and the projects. The runtime directory stays in `%LOCALAPPDATA%\ghidra-mcp\run`.
580
+ - Ghidra opens the project directly. There is no symbolic link.
581
+ - Clients connect through a named pipe. `server.json` contains its random name. Only the owner can connect. Remote clients cannot connect.
582
+
583
+ On all platforms:
584
+
585
+ - One daemon runs for each runtime directory. A file lock enforces this rule. There is no PID file.
586
+ - 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.
587
+ - You can delete the runtime directory when the daemon does not run. Then `ghidra_session open` with the MD5 opens the saved project again.
588
+ - The daemon opens a project again when `project.gpr` and `project.rep` exist. Ghidra replays its recovery journal.
589
+ - The daemon does not change a project directory that it does not recognize. It shows an error.
590
+ - The daemon bounds all log files (`daemon.log`, `stdout.log`, `stderr.log`) to 10 MiB.
591
+ - The forwarder truncates oversized log lines. It replaces lines above 10 MiB with `[TRUNCATED_LOG_LINE]`.
592
+ - When a log file reaches 10 MiB, the daemon rotates it and keeps up to three backups (`.1`, `.2`, `.3`).
593
+ - The daemon replaces sensitive authentication tokens in log lines with `[REDACTED_TOKEN]`.
594
+ - On Windows, the daemon closes active write handles before it renames log files.
595
+ - The daemon rotates `daemon.log` before it opens a file larger than 10 MiB.
596
+
597
+ ## Validation and releases
598
+
599
+ To do the same checks as CI, use these commands:
600
+
601
+ ```sh
602
+ cargo xtask ci
603
+ cargo xtask build --release --locked --bin ghidra-mcp
604
+ ```
605
+
606
+ Or run the checks separately:
607
+
608
+ ```sh
609
+ cargo xtask check
610
+ cargo fmt --all -- --check
611
+ cargo clippy --workspace --all-targets --locked -- -D warnings
612
+ RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items --locked
613
+ ```
614
+
615
+ CI builds release executables on macOS, Linux and Windows, for x86_64 and ARM64.
616
+ Each push to `main`, each pull request and each manual run starts all six builds.
617
+ A failed build does not stop the other builds.
618
+ The Windows executables link the C runtime statically.
619
+
620
+ release-please sets the versions from the Conventional Commits on `main`:
621
+
622
+ - `fix:` gives a patch release.
623
+ - `feat:` gives a minor release.
624
+ - `!` or `BREAKING CHANGE:` gives a major release.
625
+
626
+ release-please opens a release pull request.
627
+ This pull request updates the workspace version, `Cargo.lock`, `CHANGELOG.md` and the release manifest.
628
+ After you merge it, release-please creates a version tag and a draft release at a fixed commit.
629
+ All six builds and the dependency audit use that commit.
630
+
631
+ After those checks pass, CI attaches the executables, SHA-256 checksums and license texts.
632
+ Then CI publishes the npm packages and makes the draft public.
633
+ Failed checks leave the release as a draft. Rerun the failed jobs.
634
+ CI does not publish an npm package again if npm has that version.
635
+
636
+ CI uses the default `GITHUB_TOKEN` for GitHub.
637
+ For npm, CI uses trusted publishers through GitHub OIDC. You do not need other secrets.
638
+ Each npm package must have a trusted publisher for this repository and the `ci.yml` workflow.
639
+
640
+ > [!NOTE]
641
+ > - The repository must let GitHub Actions make pull requests.
642
+ > - A CI run for a release pull request from `GITHUB_TOKEN` must have maintainer approval. Approve the run before you merge.
643
+
644
+ ## Troubleshooting
645
+
646
+ For runbooks about Ghidra discovery, Java 21, socket permissions, memory, and logs,
647
+ read the [Troubleshooting guide](docs/troubleshooting.md).
648
+
649
+ ### The daemon cannot find `analyzeHeadless`
650
+
651
+ - Set `GHIDRA_INSTALL_DIR` or `GHIDRA_HOME`.
652
+ - Alternatively, put `analyzeHeadless` or `ghidraRun` on `PATH`.
653
+
654
+ ### The bridge JAR is absent
655
+
656
+ - Make sure that `ghidra-bridge.jar` is in the runtime directory.
657
+ - If you changed the bridge source, run `cargo xtask build` again. The xtask command builds and embeds the bridge again.
658
+
659
+ ### The daemon does not start
660
+
661
+ - Read `daemon.log` in the runtime directory.
662
+ - 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`.
663
+ - `daemon.lock` stops a second daemon in the same runtime directory. Do not delete the runtime files while the daemon runs.
664
+
665
+ ## Documentation
666
+
667
+ - [First Steps](docs/getting-started.md): configuration steps and the first analysis procedure.
668
+ - [Troubleshooting](docs/troubleshooting.md): runbooks for discovery, Java 21, permissions, memory, and logs.
669
+ - [Architecture](docs/architecture.md): processes, request flows, session lifecycle, concurrency, process ownership and security.
670
+ - API documentation of each module and item: `cargo doc --no-deps --document-private-items --open`.
671
+ - [Security policy](SECURITY.md): deployment and vulnerability reports.
672
+ - [Changelog](CHANGELOG.md).
673
+ - The Java bridge has its own documents: [`bridge/README.md`](bridge/README.md), [`bridge/docs/protocol.md`](bridge/docs/protocol.md), [`bridge/docs/api.md`](bridge/docs/api.md) and [`bridge/docs/development.md`](bridge/docs/development.md).
674
+
675
+ ## Contribute
676
+
677
+ We welcome contributions.
678
+ [CONTRIBUTING.md](CONTRIBUTING.md) gives the prerequisites, the standards for code and text, and the extension procedures.
679
+ The [code of conduct](CODE_OF_CONDUCT.md) applies to all participants.
680
+
681
+ The Rust code is in `src/`.
682
+ The `xtask/` directory contains automation tools.
683
+ The Java bridge is a Git submodule.
684
+ Clone with `--recurse-submodules`, or use `git submodule update --init --recursive`.
685
+
686
+ ## License
687
+
688
+ The [MIT License](LICENSE) applies to this project.
689
+ The Java bridge in `bridge/` has a separate license. See [`bridge/LICENSE`](bridge/LICENSE).
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026 ByteLand Technology Limited
3
+ // SPDX-License-Identifier: MIT
4
+
5
+ // Starts the native ghidra-mcp executable from the platform package.
6
+ // MCP clients use stdio, thus the child process uses the same streams.
7
+
8
+ 'use strict';
9
+
10
+ const { spawn } = require('node:child_process');
11
+
12
+ const RELEASES = 'https://github.com/ByteLandTechnology/ghidra-mcp/releases';
13
+
14
+ // Each key is "<process.platform>-<process.arch>".
15
+ // Each value is the npm package that holds the executable for that platform.
16
+ const PACKAGES = {
17
+ 'darwin-arm64': '@ghidra-mcp/darwin-arm64',
18
+ 'darwin-x64': '@ghidra-mcp/darwin-x64',
19
+ 'linux-arm64': '@ghidra-mcp/linux-arm64',
20
+ 'linux-x64': '@ghidra-mcp/linux-x64',
21
+ 'win32-arm64': '@ghidra-mcp/win32-arm64',
22
+ 'win32-x64': '@ghidra-mcp/win32-x64',
23
+ };
24
+
25
+ /** Returns the path of the native executable, or stops the process with an error. */
26
+ function findExecutable() {
27
+ const key = `${process.platform}-${process.arch}`;
28
+ const name = PACKAGES[key];
29
+ if (!name) {
30
+ fail(`ghidra-mcp has no npm package for ${key}.`);
31
+ }
32
+ const file = process.platform === 'win32' ? 'ghidra-mcp.exe' : 'ghidra-mcp';
33
+ try {
34
+ return require.resolve(`${name}/bin/${file}`);
35
+ } catch {
36
+ fail(
37
+ `The package ${name} is not installed. ` +
38
+ 'Do not use --omit=optional or --no-optional when you install @ghidra-mcp/cli.',
39
+ );
40
+ }
41
+ }
42
+
43
+ /** Writes an error message and stops the process. */
44
+ function fail(message) {
45
+ process.stderr.write(`${message}\nYou can download an executable from ${RELEASES}\n`);
46
+ process.exit(1);
47
+ }
48
+
49
+ const child = spawn(findExecutable(), process.argv.slice(2), { stdio: 'inherit' });
50
+
51
+ child.on('error', (error) => {
52
+ fail(`Cannot start ghidra-mcp: ${error.message}`);
53
+ });
54
+
55
+ // Send termination signals to the child. The child decides when to stop.
56
+ // A terminal sends SIGINT to the full process group, thus the child can get it two times.
57
+ const SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP'];
58
+ for (const signal of SIGNALS) {
59
+ process.on(signal, () => {
60
+ if (child.exitCode === null && child.signalCode === null) {
61
+ child.kill(signal);
62
+ }
63
+ });
64
+ }
65
+
66
+ // Exit as the child exits, so that the caller gets the same status.
67
+ child.on('exit', (code, signal) => {
68
+ if (signal) {
69
+ // Remove the handlers, so that Node.js does the default action for the signal.
70
+ for (const name of SIGNALS) {
71
+ process.removeAllListeners(name);
72
+ }
73
+ process.kill(process.pid, signal);
74
+ return;
75
+ }
76
+ process.exit(code ?? 1);
77
+ });
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
+ "bin": {
3
+ "ghidra-mcp": "bin/ghidra-mcp.js"
4
+ },
5
+ "description": "Headless Ghidra analysis for MCP clients. Clients can start sessions, decompile code, examine symbols, and change Ghidra programs.",
6
+ "engines": {
7
+ "node": ">=18"
8
+ },
9
+ "files": [
10
+ "bin"
11
+ ],
12
+ "homepage": "https://github.com/ByteLandTechnology/ghidra-mcp#readme",
13
+ "keywords": [
14
+ "ghidra",
15
+ "mcp",
16
+ "reverse-engineering",
17
+ "static-analysis",
18
+ "decompiler"
19
+ ],
20
+ "license": "MIT",
2
21
  "name": "@ghidra-mcp/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
22
+ "optionalDependencies": {
23
+ "@ghidra-mcp/darwin-arm64": "1.1.0",
24
+ "@ghidra-mcp/darwin-x64": "1.1.0",
25
+ "@ghidra-mcp/linux-arm64": "1.1.0",
26
+ "@ghidra-mcp/linux-x64": "1.1.0",
27
+ "@ghidra-mcp/win32-arm64": "1.1.0",
28
+ "@ghidra-mcp/win32-x64": "1.1.0"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/ByteLandTechnology/ghidra-mcp.git"
33
+ },
34
+ "version": "1.1.0"
35
+ }