Skip to content

Configuration

MCGhidra is configured through environment variables. No configuration file is required — defaults work out of the box for local development.

These variables control the Python MCP server process.

VariableDefaultDescription
GHIDRA_HOSTlocalhostHostname for connecting to Ghidra instances. Change this when Ghidra runs on a remote host.
MCGHIDRAMCP_DEBUGunsetSet to 1 to enable DEBUG-level logging. Shows HTTP requests, pagination details, and discovery results.
MCGHIDRA_FEEDBACKtrueEnable or disable feedback collection. Set to false to disable.
MCGHIDRA_FEEDBACK_DB~/.mcghidra/feedback.dbPath to the SQLite database for feedback data. The parent directory is created automatically.

These values are set in MCGhidraConfig and are not currently exposed as environment variables, but can be overridden programmatically when creating the server:

SettingDefaultDescription
quick_discovery_range18489-18498Port range for quick instance discovery scans
full_discovery_range18400-18599Port range for full discovery scans (instances_discover)
request_timeout30.0sHTTP request timeout for Ghidra API calls
discovery_timeout0.5sHTTP timeout per port during discovery scans
default_page_size50Default pagination page size
max_page_size500Maximum allowed page size
cursor_ttl_seconds300Cursor expiration time (5 minutes)
max_cursors_per_session100Maximum active cursors per MCP session
max_response_tokens8000Hard token budget — the return_all guard triggers above this
expected_api_version2Minimum API version required from the Ghidra plugin

These variables control the MCP server’s Docker integration — how it builds, tags, and starts containers.

VariableDefaultDescription
MCGHIDRAMCP_VERSIONlatestDocker image tag to use when starting containers.
MCGHIDRA_PORT8192Default port for container API mapping. Overridden by auto-allocation in multi-container mode.
MCGHIDRA_MAXMEM2GMax JVM heap size passed to containers. Increase for large binaries.
MCGHIDRA_DOCKER_AUTOfalseWhen true, the server will automatically start a Docker container when a binary is loaded and no Ghidra instance is available.

The port pool prevents conflicts when multiple MCP sessions run containers simultaneously. Ports are allocated using flock-based locking.

VariableDefaultDescription
MCGHIDRA_PORT_START8192First port in the allocation pool.
MCGHIDRA_PORT_END8319Last port in the allocation pool (128 ports total).
MCGHIDRA_PORT_LOCK_DIR/tmp/mcghidra-portsDirectory for port lock files. Created automatically on first use.

Port lock files are named port-{N}.lock and contain JSON with the session ID, PID, and timestamp. The docker_cleanup tool removes stale locks from crashed processes.


These variables are read by the Docker entrypoint script (entrypoint.sh) inside the container. They configure how Ghidra runs in headless mode.

VariableDefaultDescription
MCGHIDRA_MODEheadlessContainer operating mode. See modes below.
MCGHIDRA_PORT8192HTTP API port inside the container. The MCP server maps this to a host port from the pool.
MCGHIDRA_MAXMEM2GMax JVM heap size. Passed to Ghidra’s analyzeHeadless command.
VariableDefaultDescription
GHIDRA_HOME/opt/ghidraGhidra installation directory inside the container.
SCRIPT_DIR/home/ghidra/ghidra_scriptsDirectory for Ghidra Python scripts (MCGhidraServer.py lives here).
PROJECT_DIR/projectsDirectory where Ghidra stores its project files (.gpr, .rep).
PROJECT_NAMEMCGhidraName of the Ghidra project created for the imported binary.

These are optional. When omitted, Ghidra auto-detects the binary format.

VariableDefaultDescription
GHIDRA_LANGUAGEauto-detectProcessor language ID. Must match ARCH:ENDIAN:SIZE:VARIANT format (e.g., ARM:LE:32:v4t). Setting this causes the container to use BinaryLoader unless GHIDRA_LOADER overrides it.
GHIDRA_BASE_ADDRESSauto-detectBase address for raw binaries. Hex format: 0x00000000 or 00000000.
GHIDRA_LOADERauto-detectLoader type override. Common values: BinaryLoader (raw bytes), AutoImporter (header-based detection). Must be alphanumeric with underscores.

The MCGHIDRA_MODE variable selects the operating mode:

ModeDescription
headlessDefault. Imports the binary, runs auto-analysis, starts the HTTP API server. This is what docker_auto_start and docker_start use.
serverOpens an existing project (no import). Requires a program name as an argument. Useful for re-analyzing a previously imported binary.
analyzeImports and analyzes a binary, then exits. No HTTP server. Use for batch processing.
shellDrops into an interactive bash shell. Useful for debugging the container environment.

All firmware import parameters are validated before reaching Ghidra:

  • GHIDRA_LANGUAGE must match ARCH:ENDIAN:SIZE:VARIANT (regex-validated).
  • GHIDRA_BASE_ADDRESS must be valid hex, max 64-bit.
  • GHIDRA_LOADER must be alphanumeric with underscores.

Invalid values are rejected with a descriptive error before any Docker or Ghidra operations run. The MCP server validates these on the client side as well, so errors surface in tool responses rather than buried in container logs.