Skip to content

feat(settings)!: one settings registry for server, bridge, tree and naming configuration - #636

Open
heeen wants to merge 12 commits into
devfrom
pr/settings
Open

heeen wants to merge 12 commits into
devfrom
pr/settings

Conversation

@heeen

@heeen heeen commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #635. Merge that one first; this PR's diff is only the settings series.

Configuration moves to one key registry with scoped settings. The changes are breaking: the old environment variable names and three endpoints are removed.

What changes

  • One key registry, one resolver (512c8dc).
    • Each key is a dotted name declared once, with a type, a default, its allowed scopes, a kind (preference, guardrail, secret) and a merge rule.
    • Scopes resolve in this order: default < server < project < local < program < session < call.
    • A list value can be a +x/-x change to the scope below it.
    • A guardrail set above server scope applies only if it tightens the server's value.
  • Stores and tools (554a808).
    • Project settings live in a /.ghidra-mcp data-type archive, version-controlled on a shared project.
    • Local settings are a properties file in .rep; program settings are the program's GhidraMCP options.
    • New tools: get_settings and set_setting. set_setting refuses secrets and any write that would loosen a guardrail.
  • Bridge tool groups come from tools.* settings (0b12b5a). The groups loaded in the last session are loaded again.
  • Guardrails read through the resolver on every check (edbb9a0): scripts.allow, files.root, project.folder_scope. The tool guide's settings table is generated from the registry.
  • Server and bridge environment variables become settings keys (c8c9e71, f3ca099).
    • Each variable's name is derived from its key.
    • The server or bridge refuses to start while an old name is set, and names the new one.
    • ghidra-mcp-xkc: when the Ghidra Server runs without -u, the configured user is ignored. The authentication error now says so.
  • Tree create defaults come from tree.* keys (118e3f6).
  • Naming rules are naming.* keys, and conventions.json is gone (c88f097). This means a shared project enforces the same rules on every machine.
  • Folded tools (80fe4fd, 4bea018):
    • validate_function_prototype becomes set_function_prototype(dry_run=true);
    • validate_data_type becomes apply_data_type(dry_run=true) or find_data_types(name=);
    • search_strings becomes list_strings(pattern=);
    • force_decompile becomes get_functions(fields=decompiled_code).

Breaking

  • Renamed environment variables:
    • GHIDRA_MCP_ALLOW_SCRIPTS → GHIDRA_MCP_SCRIPTS_ALLOW
    • GHIDRA_MCP_FILE_ROOT → GHIDRA_MCP_FILES_ROOT
    • GHIDRA_MCP_PROJECT_FOLDER → GHIDRA_MCP_PROJECT_FOLDER_SCOPE
    • GHIDRA_SERVER_* → GHIDRA_MCP_GHIDRA_SERVER_*
    • the bridge variables → GHIDRA_MCP_BRIDGE_*
    • GHIDRA_MCP_REQUIRE_PROGRAM_SELECTORS → GHIDRA_MCP_TOOLS_REQUIRE_PROGRAM
  • Removed endpoints: /validate_function_prototype, /validate_data_type, /search_strings, /force_decompile. The migration guide has a row for each.

Tests

On the tip of the stack (#637), on Ghidra 12.1.4:

  • Java offline and real-Ghidra tiers: 1154 tests, 0 failures, 0 skipped.
  • Python unit and offline tiers pass, except test_default_branch_constant_matches_git, which also fails on dev.

https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6

heeen added 12 commits October 30, 2026 14:20
Checking out a newer version closes and reopens the program
(rebindOpenCopies, or the GUI). The registry rebound the observer to the
new instance without looking at it, so the tree kept the old revision and
status said in_sync.

- Reattaching to a program whose saved state (file version, saved time)
  differs from the one the tree last described queues a full reconcile.
  An unchanged reopen (an LRU eviction) queues nothing.
- The input fingerprint, which a full reconcile compares, now covers
  locals, the types of the data a function reads and the members of every
  struct, union and enum it reaches. A retype that renames nothing used to
  leave the block as it was; a real-Ghidra test fails on the old
  fingerprint and passes on this one.
- The memory map is part of the recorded session and of STATUS.md
  (memory_map). A reopen, an in-place restore (undo, a server update) or
  an adoption after a restart on a different map marks the tree stale,
  since no fingerprint covers it, and the reattach reconcile no longer
  clears that.

TreeConvergenceGhidraTest's sweep-queued case registers its own
threading strategy: run alone it failed, because one was registered only
when another test happened to run first.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
… whole tree

Any memory-block event marked the whole tree stale until a resweep: a
data-only block moved, a block nothing references added, a rename. A new
image base, which re-keys every function, was not noticed at all.

- A full reconcile compares the memory map with the one the tree was
  decompiled against, address by address (MemoryMapChange), and
  re-decompiles the functions that reference what changed although their
  fingerprints match: every reference into a block that moved, appeared or
  went away, and the data references into one whose permissions or
  initialisation changed. Renaming, splitting or joining a block changes
  nothing at any address and costs nothing.
- Block events and IMAGE_BASE_CHANGED ask for that full reconcile; Ghidra
  sends RESTORED for most block changes, which already did. A new image
  base re-keys every function and the address diff replaces each block
  under its new key. A restore or reopen on a different map queues the
  same pass instead of marking the tree stale.
- Only a full pass that followed the change moves the session onto the
  live map; a targeted one keeps the old map for the full pass to compare.
- The map is kept beside STATUS.md's hash in index/memory-map.txt, so an
  adoption after a restart compares it the same way. A tree with only the
  hash, or a change reaching more than 2000 functions, still marks it stale.
- TreeRegistry.markStale had no caller left and is gone.

TreeMemoryMapGhidraTest covers a read-only data block (its two readers
re-decompile, the load folds), an unreferenced block changed every way (no
decompile), a moved block, a new image base, an adoption and a targeted
pass.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
Keys are dotted names declared once with type, default, allowed scopes,
kind (preference, guardrail, secret) and merge rule. The resolver walks
default < server < project < local < program < session < call and reports
the value, the scope it came from and every scope that held one. List keys
take +x/-x deltas over the scope below; a bare list replaces it. A guardrail
value from a scope above the server's only applies if it tightens, and a
write that would loosen one is refused without naming the override.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
…et_setting

- project: options on a /.ghidra-mcp data-type archive, created on first
  write, added to version control on a shared project and written through a
  checkout and check-in of that one file
- local: a properties file in the project's .rep directory. Not Ghidra's
  project saveable data: DefaultProject.save() returns without a ToolManager,
  which a headless project never has, so it was never written there
- program: the program's GhidraMCP options

get_settings lists every key with its value, source scope and the scopes that
also hold one; secrets show only whether they are set. set_setting writes or
unsets one scope and refuses secrets, other scopes and any change that would
loosen a guardrail, unset included. set_program_option and
remove_program_option refuse the GhidraMCP group, delete_file and move_file
refuse the archive, and list_project_files does not show it.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
…on's groups

On connect the bridge reads the project's tools.* settings and layers this
session's on top (GHIDRA_MCP_<KEY> in its environment, --default-groups for
tools.autoload):

- tools.autoload: the groups every session loads (+group/-group deltas)
- tools.restore_loaded (default on): also load tools.last_loaded
- tools.last_loaded: groups loaded beyond autoload; the bridge writes it at
  local scope after every load_tool_group / unload_tool_group
- tools.require_program: strict program routing

Unknown group names are warned about with the valid list. A server without
/get_settings falls back to the defaults.

BREAKING: GHIDRA_MCP_REQUIRE_PROGRAM_SELECTORS is now
GHIDRA_MCP_TOOLS_REQUIRE_PROGRAM (or the tools.require_program setting), and
--default-groups sets this session's tools.autoload.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
…able

scripts.allow, files.root and project.folder_scope are read through the
resolver on every check, so a project or local value tightens them without a
restart; both servers hand SecurityConfig their SettingsService. Their server
variables take the derived names, and a server whose environment still sets
an old one refuses to start: an ignored files.root or project.folder_scope
would run unconfined.

Refusals and tool descriptions state the guardrail and never how to lift it.
The tool guide's settings table is generated from the registry and held
equal by SettingsKeyTableTest.

BREAKING: GHIDRA_MCP_ALLOW_SCRIPTS -> GHIDRA_MCP_SCRIPTS_ALLOW,
GHIDRA_MCP_FILE_ROOT -> GHIDRA_MCP_FILES_ROOT,
GHIDRA_MCP_PROJECT_FOLDER -> GHIDRA_MCP_PROJECT_FOLDER_SCOPE.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
- validate_function_prototype -> set_function_prototype(dry_run=true). The
  validator checked for '(' and a hard-coded x86 convention list; the dry run
  parses and applies the prototype, then rolls back.
- validate_data_type -> apply_data_type(dry_run=true) with an address, and
  find_data_types(name=...) without one. The existence check searched only
  the program's own types by exact name, so it denied int or dword[4] that
  apply_data_type accepts; name= resolves exactly as apply_data_type does.
- search_strings -> list_strings(pattern=..., min_length=...). filter stays a
  substring; search_strings' encoding only echoed a label back.

Catalog 219 (215 GUI, 200 headless, 218 advertised). Migration guide rows
added; corpus, fixture and integration callers moved to the survivors.

BREAKING: /validate_function_prototype, /validate_data_type and
/search_strings are removed.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
force_decompile flushed the cache of a decompiler it had created a moment
before, so it never refreshed anything; get_functions(fields=decompiled_code)
already decompiles with a fresh decompiler on every call. Catalog 218, 217
agent-visible.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
Every environment variable the server read directly is a registry key of
a new kind, operator: set in the server's environment, read-only to
agents, shown by get_settings and the generated key table. Names derive
from the key; the server refuses to start while an old name is set, in
its environment or a .env file, and says the new one.

  GHIDRA_MCP_BIND_ADDRESS        server.bind_address
  GHIDRA_MCP_MAX_CACHED_PROGRAMS programs.max_cached
  GHIDRA_MCP_SHARED_PROJECT_DIR  project.shared_dir
  GHIDRA_SERVER_HOST/PORT/USER   ghidra_server.host/port/user
  GHIDRA_SERVER_PASSWORD         ghidra_server.password (secret)
  GHIDRA_MCP_ARCHIVE_URL         archive.url (name unchanged)

.env in the Ghidra directory and in home now back the whole server scope
(the process environment wins), not just the two credentials; the Java
side no longer reads .ghidra-cred (ghidra-mcp-setup.ps1 still exports
it). Credentials are registered by one method on both servers.

ghidra-mcp-xkc: the configured user was ignored because the Ghidra Server
ran without -u, which is the only way a client may choose its name; both
connection paths sent the OS user. The authenticator now detects that and
the connection or project-open error says so, instead of a bare
"Authentication failed".

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
Eleven bridge variables become bridge.* registry keys at session scope,
named the derived way (GHIDRA_MCP_BRIDGE_*); the bridge refuses to start
while an old name is set and names the new one. GHIDRA_MCP_PROJECT and
GHIDRA_MCP_EXPOSE, added upstream since, become bridge.project and
bridge.expose the same way. GHIDRA_MCP_DISABLE_REBIND_
PROTECTION=1 becomes bridge.rebind_protection=false. auth.token keeps its
name and gains session scope, since the bridge sends the same variable.

python/bridge_mcp_ghidra/keys.py is a stdlib-only leaf (config.py cannot
import settings.py without a cycle) holding the defaults, the parser, the
retired map and the startup check; test_bridge_keys pins its defaults to
the generated key table, so the Java registry and the Python mirror
cannot drift. get_settings leaves session-only keys out: the server
cannot see the bridge's environment.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
decompile_tree_create's omitted parameters take tree.* keys resolved
for the program (server < project < local < program); an explicit one wins.
decompile_timeout_seconds and analysis_wait_seconds are create parameters
now. Resolved values are written to tree.json, so a later default change
leaves existing trees alone. The default constants moved into the
registry.

tree.disassemble_missing stays off by default (it is the one tree
setting that writes the program); a project whose imports need it sets
it once.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
… is gone

conventions.json lived in a per-machine cache directory, so on a shared
project each machine enforced its own rules. Every field becomes a naming.*
key resolved per program through the shared project store.

naming.mode (off < warn < enforce) is a guardrail: agents may only tighten
it. The other naming.* keys are operator-only: an agent reads them but cannot
add its own verb to get a name through. naming.override=deny refuses a
per-call strict_mode below the resolved mode; allow (default) keeps today's
behaviour. The GUI's strict-naming checkbox shows the resolved mode and
writes it at local scope when changed (never on startup sync, which would
pin it). NamingPolicy memoizes the built config per program until a setting
is written.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
@bethington

Copy link
Copy Markdown
Owner

Thanks. The code and tests look solid: with both PRs applied, the unit tier and the Java offline and real-Ghidra tests all pass locally with nothing skipped. I'm holding the settings series for the release after this one, for two reasons.

#635 was squash-merged, so this PR's base branch is no longer part of dev. It needs retargeting to dev, and git cherry shows its first two commits are already there.

The rename has no aliases, so it breaks every existing .env, and every HTTP client calling the removed endpoints, in one step. I need to line those up on my side first.

One correction to the description: it says three endpoints are removed, but /force_decompile, /search_strings, /validate_data_type and /validate_function_prototype are all gone, so four.

For #637: ProgramSaves.awaitAnalysis changes in #639 (the 12.2 retarget), so the hasAutoAnalysisManager guard will need to move into awaitAnalysis(Program, long) when you rebase.

@bethington
bethington changed the base branch from pr/tree-revision-memory-map to dev November 18, 2026 06:46
@bethington

Copy link
Copy Markdown
Owner

I've pointed this at dev now that #635 is in. I'm planning it as the headline of the next major release rather than 7.1: force_decompile going away and the bridge's environment variables becoming settings keys are breaking changes, and I want them to ship with a migration note rather than inside a fix release.

To get it reviewable, could you rebase onto dev?

#637 can then sit on top of this, or go to dev on its own if you'd rather it land sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants