Skip to content

fix(headless): name the fallback socket directory in --help - #665

Merged
bethington merged 2 commits into
bethington:devfrom
shu-chen-dot-ca:fix-653-headless-help-socket-dir
Nov 25, 2026
Merged

bethington merged 2 commits into
bethington:devfrom
shu-chen-dot-ca:fix-653-headless-help-socket-dir

Conversation

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor

What this changes

The headless server's --help said it always serves on $XDG_RUNTIME_DIR/ghidra-mcp/ghidra-<pid>.sock. With XDG_RUNTIME_DIR unset it actually serves from $TMPDIR/ghidra-mcp-<user>/, and the help never mentioned that directory or its -<user> suffix. The help now lists both directories, in the order McpHttpServer.resolveSocketDir picks them. Where the socket goes is unchanged.

Fixes #653

Why

On dev at 5f6c416, built with Gradle against Ghidra 12.2 on Linux:

  • --help printed the two "Always serves on $XDG_RUNTIME_DIR/ghidra-mcp/..." lines quoted in the issue.
  • Starting the server with XDG_RUNTIME_DIR unset and TMPDIR=$WORK/tmp logged Serving on $WORK/tmp/ghidra-mcp-<user>/ghidra-<pid>.sock.

The new tail of the help:

Always serves a Unix socket, ghidra-<pid>.sock, where the bridge discovers it:
  $XDG_RUNTIME_DIR/ghidra-mcp/   when XDG_RUNTIME_DIR is set, otherwise
  $TMPDIR/ghidra-mcp-<user>/     with java.io.tmpdir, then /tmp, in place of
                                 $TMPDIR when TMPDIR is unset too
TCP additionally at http://<address>:<port>/ when asked.

printUsage is now public static (it reads no instance state), so the new offline test HeadlessUsageSocketDirTest can capture its output and check that it names both directories and the socket file name.

Tests you ran

  • uv run pytest tests/unit/: run as uv run --frozen --python 3.13 pytest tests/unit/ --no-cov on CPython 3.13.17. Passed, 0 failures, 13 skips (the Windows-only and live-server ones).
  • ./gradlew test --tests 'com.xebyte.offline.*' "-PGHIDRA_INSTALL_DIR=<dir>": Ghidra 12.2, Temurin JDK 25. 119 suites, 968 tests, 0 failures, 0 skipped, including the 3 new tests.
  • powershell -File tests\pester\Run-Tests.ps1: not applicable, no PowerShell changes.
  • Live tier (pytest tests/ -m readonly, ./gradlew test): not run.
  • Could not run the live tier: no running Ghidra with a program loaded. I did start the headless server by hand, with and without XDG_RUNTIME_DIR, and its socket path matched the new help both times.
Gradle offline tier: 119 suites, 968 tests, 0 failures, 0 skipped
markdownlint-cli2 --config .markdownlint-cli2.jsonc CHANGELOG.md: 0 issues

I didn't run the Maven -Pcoverage-gate command: only Maven 3.8.7 is available here and the project needs 3.9+. The change adds a test that covers the edited method.

If you touched an @mcptool or @PARAM annotation

  • mvn test -Dtest=RegenerateEndpointsJson -Dregenerate=true
  • python -m tools.audit_server_scope --write
  • python -m tools.gen_readme_api_reference --write
  • Not applicable

Checklist

  • Branched from dev and targeting dev
  • CHANGELOG.md updated, if this is user-visible
  • No unrelated reformatting mixed into the diff

Screenshots

Before After
before after

The help said the server always serves on
$XDG_RUNTIME_DIR/ghidra-mcp/ghidra-<pid>.sock. With XDG_RUNTIME_DIR unset,
McpHttpServer.resolveSocketDir serves from $TMPDIR/ghidra-mcp-<user>/
instead, then java.io.tmpdir and /tmp. List both directories in the help
and pin them with an offline test.

Fixes #653
@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor Author

Rebased onto current dev (870db08). The only conflict was in CHANGELOG.md, where #644 added its entry at the top of Unreleased; I kept both entries. Offline Java tier (Gradle, Ghidra 12.2, JDK 25): 968 tests, 0 failures. tests/unit/ on Python 3.13: passed.

@shu-chen-dot-ca
shu-chen-dot-ca force-pushed the fix-653-headless-help-socket-dir branch from cd48c45 to 5750902 Compare November 18, 2026 15:42
@bethington bethington mentioned this pull request Nov 18, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the help text against McpHttpServer.resolveSocketDir (src/main/java/com/xebyte/core/McpHttpServer.java:469-484 on dev) and the wording matches the actual order: $XDG_RUNTIME_DIR/ghidra-mcp → $TMPDIR/ghidra-mcp-<user> → java.io.tmpdir/ghidra-mcp-<user> → /tmp/ghidra-mcp-<user>, with ghidra-<pid>.sock as the file name from startUds (line 336). The old text really did promise the XDG path unconditionally, so this is a genuine docs fix.

Two small notes on the test (HeadlessUsageSocketDirTest):

  • testUsageNamesUserSuffixedFallbackDir asserts usage().contains("/tmp"), which stays satisfied by unrelated lines even if the final /tmp fallback disappeared from the help. Anchoring it to the distinctive part (e.g. contains("then /tmp")) would keep the test honest against a regression that only drops the last fallback. Minor either way since the other assertions are exact.
  • Making printUsage public static is the only API surface change and is fine for the cross-package test; not worth churn if you don't care.

The System.setOut capture is fine given the JVM test is single-threaded and the original stream is restored in finally.

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor Author

Thanks @rahul05ranjan. I anchored the last fallback check to contains("then /tmp"). Right now no other help line has /tmp, so the old check did catch the fallback being dropped. But I tried a help with that fallback removed and an example changed to --file /tmp/binary.exe: the old check passed it, the new one fails as it should. Left printUsage public static as you suggested.

Offline Java tier (Gradle, Ghidra 12.2, JDK 25): 968 tests, 0 failures. tests/unit/ on Python 3.13: passed.

@bethington
bethington merged commit 9019130 into bethington:dev Nov 25, 2026
15 checks passed
@shu-chen-dot-ca
shu-chen-dot-ca deleted the fix-653-headless-help-socket-dir branch November 25, 2026 02:24
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.

fix(headless): --help omits fallback Unix socket locations

4 participants