Skip to main content
Glama

setup_context

Export binary analysis context from Ghidra headless decompilation for reverse-engineering functions, pseudocode, structs, and enums.

Instructions

Run Ghidra headless decompilation to export binary context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ghidra_pathNo/Users/tomi/Downloads/ghidra_11.3.1_PUBLIC
binary_pathNo/Users/tomi/Documents/ghidra_mcp/crackme

Implementation Reference

  • main.py:44-66 (handler)
    The core handler function for the 'setup_context' MCP tool. Decorated with @mcp.tool() for automatic registration and schema inference from type hints and docstring. Validates inputs, executes Ghidra headless analysis using helper functions, loads the resulting context, and updates global state.
    @mcp.tool()
    async def setup_context(ghidra_path: str = "/Users/tomi/Downloads/ghidra_11.3.1_PUBLIC", binary_path: str = "/Users/tomi/Documents/ghidra_mcp/crackme") -> str:
        """Run Ghidra headless decompilation to export binary context."""
        global ctx_ready, last_binary
    
        if not os.path.isdir(ghidra_path):
            return f"❌ Ghidra path '{ghidra_path}' is not valid."
        if not os.path.isfile(binary_path):
            return f"❌ Binary file '{binary_path}' does not exist."
    
        result = run_headless(ghidra_path, binary_path)
    
        if result.returncode != 0:
            return f"❌ Ghidra failed:\n{result.stderr}"
    
        if not is_context_ready():
            return f"❌ Export script ran but no context was saved."
    
        load_context()
        ctx_ready = True
        last_binary = os.path.basename(binary_path)
        return f"✅ Context loaded for '{last_binary}'."
  • main.py:18-35 (helper)
    Key helper function called by setup_context to execute the Ghidra analyzeHeadless command with the export script, environment variable for JSON output path, and proper arguments for importing and analyzing the binary.
    def run_headless(ghidra_path: str, binary_path: str):
        analyze_headless = os.path.join(ghidra_path, "support", "analyzeHeadless")
        project_dir = os.getcwd()
        project_name = "ghidra_ctx"
        cmd = [
            analyze_headless,
            project_dir,
            project_name,
            "-import", binary_path,
            "-overwrite",
            "-scriptPath", os.path.dirname(EXPORT_SCRIPT_PATH),
            "-postScript", os.path.basename(EXPORT_SCRIPT_PATH),
            "-deleteProject"
        ]
        env = os.environ.copy()
        env["GHIDRA_CONTEXT_JSON"] = GHIDRA_CONTEXT_JSON
        return subprocess.run(cmd, capture_output=True, text=True, env=env)
  • main.py:36-40 (helper)
    Helper function to load the exported Ghidra context JSON into the global ctx dictionary, used after successful headless run.
    def load_context():
        global ctx
        with open(GHIDRA_CONTEXT_JSON) as f:
            ctx = json.load(f)
  • main.py:41-43 (helper)
    Helper function to check if the context JSON file exists, used to verify successful export.
    def is_context_ready():
        return os.path.exists(GHIDRA_CONTEXT_JSON)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'headless decompilation' and 'export binary context', implying a potentially resource-intensive or setup-oriented operation, but doesn't clarify critical aspects like whether this is a one-time setup, what permissions are needed, if it modifies files, or what the output format is. The description is too vague for a tool that likely performs significant processing.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It's front-loaded with the core action and outcome, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity implied by 'headless decompilation' and 'export binary context', along with no annotations, 0% schema description coverage, and no output schema, the description is inadequate. It doesn't explain what 'binary context' includes, how the output is structured, or any behavioral traits, leaving significant gaps for an AI agent to use this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the schema provides no parameter descriptions. The tool description doesn't mention any parameters at all, failing to compensate for the schema gap. However, with only 2 parameters (both with default values and clear titles like 'Ghidra Path'), the baseline is moderate since the titles are somewhat self-explanatory, but the description adds no value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Run Ghidra headless decompilation') and the outcome ('export binary context'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate this tool from its siblings (like get_pseudocode or list_functions), which all appear to work with Ghidra decompilation outputs.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing Ghidra installed), when this tool is appropriate (e.g., initial setup vs. querying), or how it relates to sibling tools like get_pseudocode that might depend on its output.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Bamimore-Tomi/ghidra_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server