GhidraMCP/ghidra_scripts/StartGhidraMcpServer.java
Kirill Zhumarin 6fee8a688a Serve MCP natively and add project, analysis and editing tools
The plugin now is the MCP server (Streamable HTTP at /mcp); the Python
bridge and the plain-text HTTP API it used are removed.

- One shared server per Ghidra process: started from the project window
  (GhidraMCPServerPlugin), any CodeBrowser, or headless via
  StartGhidraMcpServer.java. Programs resolve across all windows and
  programs opened in the background.
- Project and program lifecycle: list/import/open/close/save programs,
  manage project files, open/close/create projects.
- Auto-analysis control, function details and variables, symbols,
  comments, data, struct/enum editing, call graphs, decompiler data-flow
  slices, scalar and memory search, memory writes, scripts, MCP prompts
  and resources.
- Decompiler process reused per program with a cache keyed to the
  program modification number (previously one leaked process per call).
- Original tools split into domain classes; duplicate tools removed.
- Fix false "Failed" results for nested transactions, a GUI deadlock and
  a modal-dialog hang when closing projects with several CodeBrowsers.
- JUnit 4 (tests run in build.sh again), install.sh, and an end-to-end
  suite (tests/e2e) that exercises every tool against a live Ghidra.
2026-11-24 01:18:33 +03:00

20 lines
814 B
Java

// Starts the GhidraMCP server in headless mode and blocks until the MCP tool
// shutdown_ghidra is called. Usage:
// analyzeHeadless <projDir> <projName> [-process <file>] -noanalysis \
// -postScript StartGhidraMcpServer.java [port] [host]
//@category GhidraMCP
import com.lauriewired.GhidraMcpHeadless;
import ghidra.app.script.GhidraScript;
public class StartGhidraMcpServer extends GhidraScript {
@Override
protected void run() throws Exception {
String[] args = getScriptArgs();
int port = args.length > 0 ? Integer.parseInt(args[0]) : 8080;
String host = args.length > 1 ? args[1] : "127.0.0.1";
println("GhidraMCP headless server on " + host + ":" + port);
GhidraMcpHeadless.serve(state.getProject(), currentProgram, host, port, monitor);
}
}