Skip to main content
Glama

ida_get_current_function_decompiled

Retrieve decompiled pseudocode for the function at your current cursor position in IDA Pro to analyze binary code structure.

Instructions

Get decompiled pseudocode for the function at the current cursor position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation performing Hex-Rays decompilation for a function at the given address using IDA APIs.
    def _get_function_decompiled_by_address_internal(self, address: int) -> Dict[str, Any]:
        """Internal implementation for get_function_decompiled_by_address without sync wrapper"""
        try:
            # Get function from address
            func = idaapi.get_func(address)
            if not func:
                return {"error": f"No function found at address 0x{address:X}"}
            
            # Get function name
            func_name = idaapi.get_func_name(func.start_ea)
            
            # Try to import decompiler module
            try:
                import ida_hexrays
            except ImportError:
                return {"error": "Hex-Rays decompiler is not available"}
            
            # Check if decompiler is available
            if not ida_hexrays.init_hexrays_plugin():
                return {"error": "Unable to initialize Hex-Rays decompiler"}
            
            # Get decompiled function
            cfunc = None
            try:
                cfunc = ida_hexrays.decompile(func.start_ea)
            except Exception as e:
                return {"error": f"Unable to decompile function: {str(e)}"}
            
            if not cfunc:
                return {"error": "Decompilation failed"}
            
            # Get pseudocode as string
            decompiled_code = str(cfunc)
            
            return {"decompiled_code": decompiled_code, "function_name": func_name}
        except Exception as e:
            traceback.print_exc()
            return {"error": str(e)}
  • Handler for current function decompilation: retrieves current screen EA and delegates to internal decompilation method.
    def get_current_function_decompiled(self) -> Dict[str, Any]:
        """Get decompiled code for the function at the current cursor position"""
        try:
            # Get current address
            curr_addr = idaapi.get_screen_ea()
            if curr_addr == idaapi.BADADDR:
                return {"error": "No valid cursor position"}
            
            # Use the internal implementation without decorator
            return self._get_function_decompiled_by_address_internal(curr_addr)
        except Exception as e:
            traceback.print_exc()
            return {"error": str(e)}
  • Socket server request handler dispatching 'get_current_function_decompiled' requests to the IDAMCPCore implementation.
    elif request_type == "get_current_function_decompiled":
        response.update(self.core.get_current_function_decompiled())
  • MCP tool registration defining the tool name 'ida_get_current_function_decompiled', description, and input schema.
    Tool(
        name=IDATools.GET_CURRENT_FUNCTION_DECOMPILED,
        description="Get decompiled pseudocode for the function at the current cursor position",
        inputSchema=GetCurrentFunctionDecompiled.schema(),
    ),
  • Pydantic input schema for the tool (empty as no parameters required).
    class GetCurrentFunctionDecompiled(BaseModel):
        pass
  • MCP @server.call_tool() handler executing the tool by calling the bridge function and formatting response.
    case IDATools.GET_CURRENT_FUNCTION_DECOMPILED:
        decompiled: str = ida_functions.get_current_function_decompiled()
        return [TextContent(
            type="text",
            text=decompiled
        )]
  • Bridge handler in MCP server that sends socket request to IDA plugin and processes/formats the response.
    def get_current_function_decompiled(self) -> str:
        """Get decompiled code for the function at current cursor position"""
        try:
            response: Dict[str, Any] = self.communicator.send_request(
                "get_current_function_decompiled", 
                {}
            )
            
            if "error" in response:
                return f"Error retrieving decompiled code for current function: {response['error']}"
            
            decompiled_code: Any = response.get("decompiled_code")
            function_name: str = response.get("function_name", "Current function")
            
            # Detailed type checking and conversion
            if decompiled_code is None:
                return f"Error: No decompiled code returned for current function"
                
            # Ensure result is string
            if not isinstance(decompiled_code, str):
                self.logger.warning(f"Decompiled code type is not string but {type(decompiled_code).__name__}, attempting conversion")
                try:
                    decompiled_code = str(decompiled_code)
                except Exception as e:
                    return f"Error: Failed to convert decompiled code: {str(e)}"
            
            return f"Decompiled code for function '{function_name}':\n{decompiled_code}"
        except Exception as e:
            self.logger.error(f"Error getting current function decompiled code: {str(e)}", exc_info=True)
            return f"Error retrieving decompiled code for current function: {str(e)}"
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but does not reveal any behavioral traits such as whether it requires specific permissions, how it handles errors (e.g., if no function is at the cursor), or what the output format looks like (e.g., text, structured data). This leaves significant gaps for an agent to understand the tool's behavior.

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, clear sentence that directly states the tool's purpose without any redundant words or fluff. It is front-loaded with the key action and target, making it highly efficient and easy to understand at a glance.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, no annotations, no output schema), the description is adequate for basic understanding but incomplete. It lacks details on behavioral aspects like error handling or output format, which are important for an agent to use the tool correctly in context, especially without annotations to fill in those gaps.

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

Parameters4/5

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

The tool has 0 parameters, and the input schema has 100% description coverage (though empty). The description does not need to add parameter semantics, as there are none to explain. It appropriately focuses on the tool's purpose without unnecessary details, meeting the baseline for zero parameters.

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 ('Get decompiled pseudocode') and the target ('for the function at the current cursor position'), which is specific and unambiguous. However, it does not explicitly differentiate from its sibling tools like 'ida_get_function_decompiled_by_address' or 'ida_get_function_decompiled_by_name', which offer similar functionality but with different input methods.

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

Usage Guidelines3/5

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

The description implies usage by referencing 'current cursor position,' suggesting it should be used when the cursor is placed on a function in IDA. However, it lacks explicit guidance on when to choose this tool over alternatives like the sibling tools that fetch decompiled code by address or name, and does not mention any prerequisites or exclusions.

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/MxIris-Reverse-Engineering/ida-mcp-server'

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