Skip to main content
Glama

ida_get_global_variable_by_name

Retrieve global variable details from IDA database by specifying its name to analyze binary code structure.

Instructions

Get information about a global variable by name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
variable_nameYes

Implementation Reference

  • Main handler method that resolves the global variable name to its address using ida_name.get_name_ea and calls the internal helper to retrieve detailed information. Decorated with @idaread for IDA synchronization.
    def get_global_variable_by_name(self, variable_name: str) -> Dict[str, Any]:
        """Get global variable information by its name"""
        try:
            # Get variable address
            var_addr: int = ida_name.get_name_ea(0, variable_name)
            if var_addr == idaapi.BADADDR:
                return {"error": f"Global variable '{variable_name}' not found"}
            
            # Call internal implementation
            result = self._get_global_variable_by_address_internal(var_addr)
            
            # If successful, add variable name to result
            if "error" not in result and "variable_info" in result:
                # Parse the JSON string back to dict to modify it
                var_info = json.loads(result["variable_info"])
                var_info["name"] = variable_name
                # Convert back to JSON string
                result["variable_info"] = json.dumps(var_info, indent=2)
                
            return result
        except Exception as e:
            print(f"Error getting global variable by name: {str(e)}")
            traceback.print_exc()
            return {"error": str(e)}
  • Dispatch/registration in the MCP server request handler that maps incoming request_type 'get_global_variable_by_name' to the core handler, extracting 'variable_name' from request data.
    elif request_type == "get_global_variable_by_name":
        response.update(self.core.get_global_variable_by_name(request_data.get("variable_name", "")))
  • Internal helper implementing the core logic to extract global variable details: name, address, segment info, type via guess_tinfo, size, value (byte/word/etc.), and string value if applicable, using various IDA APIs.
    def _get_global_variable_by_address_internal(self, address: int) -> Dict[str, Any]:
        """Internal implementation for get_global_variable_by_address without sync wrapper"""
        try:
            # Verify address is valid
            if address == idaapi.BADADDR:
                return {"error": f"Invalid address: {hex(address)}"}
            
            # Get variable name if available
            variable_name = ida_name.get_name(address)
            if not variable_name:
                variable_name = f"unnamed_{hex(address)}"
            
            # Get variable segment
            segment: Optional[ida_segment.segment_t] = ida_segment.getseg(address)
            if not segment:
                return {"error": f"No segment found for address {hex(address)}"}
            
            segment_name: str = ida_segment.get_segm_name(segment)
            segment_class: str = ida_segment.get_segm_class(segment)
            
            # Get variable type
            tinfo = idaapi.tinfo_t()
            guess_type: bool = idaapi.guess_tinfo(tinfo, address)
            type_str: str = tinfo.get_type_name() if guess_type else "unknown"
            
            # Try to get variable value
            size: int = ida_bytes.get_item_size(address)
            if size <= 0:
                size = 8  # Default to 8 bytes
            
            # Read data based on size
            value: Optional[int] = None
            if size == 1:
                value = ida_bytes.get_byte(address)
            elif size == 2:
                value = ida_bytes.get_word(address)
            elif size == 4:
                value = ida_bytes.get_dword(address)
            elif size == 8:
                value = ida_bytes.get_qword(address)
            
            # Build variable info
            var_info: Dict[str, Any] = {
                "name": variable_name,
                "address": hex(address),
                "segment": segment_name,
                "segment_class": segment_class,
                "type": type_str,
                "size": size,
                "value": hex(value) if value is not None else "N/A"
            }
            
            # If it's a string, try to read string content
            if ida_bytes.is_strlit(ida_bytes.get_flags(address)):
                str_value = idc.get_strlit_contents(address, -1, 0)
                if str_value:
                    try:
                        var_info["string_value"] = str_value.decode('utf-8', errors='replace')
                    except:
                        var_info["string_value"] = str(str_value)
            
            return {"variable_info": json.dumps(var_info, indent=2)}
        except Exception as e:
            print(f"Error getting global variable by address: {str(e)}")
            traceback.print_exc()
            return {"error": str(e)}
  • Backward compatibility registration for 'get_global_variable' request_type that also calls the same core handler.
    elif request_type == "get_global_variable":
        response.update(self.core.get_global_variable_by_name(request_data.get("variable_name", "")))
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the tool 'Get information about' a global variable, implying a read-only operation, but doesn't disclose behavioral traits such as error handling, permissions needed, rate limits, or what happens if the variable doesn't exist. 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, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, 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 (a read operation with no annotations, 1 parameter, 0% schema coverage, and no output schema), the description is incomplete. It doesn't explain what information is returned, error conditions, or usage context, leaving the agent with insufficient information to use the tool effectively.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It mentions 'by name' which hints at the 'variable_name' parameter, but doesn't add meaning beyond what the schema's title ('Variable Name') provides. No details on format, constraints, or examples are given, failing to adequately document the single parameter.

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

Purpose3/5

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

The description states the action ('Get information about') and resource ('global variable by name'), which is clear but vague. It distinguishes from sibling tools like 'ida_get_global_variable_by_address' by specifying 'by name', but lacks specificity about what information is retrieved (e.g., type, value, address).

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description implies usage for retrieving global variable information by name, but it doesn't mention prerequisites, when not to use it, or compare it to siblings like 'ida_get_global_variable_by_address' or other variable-related tools.

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