Skip to main content
Glama

lldb_evaluate

Read-onlyIdempotent

Evaluate C/C++ expressions during debugging to inspect variables, call functions, and analyze program state within the LLDB debugger context.

Instructions

Evaluate a C/C++ expression in the debugger context.

Expressions can include:
- Variable access: 'my_var', 'ptr->member'
- Array indexing: 'array[5]'
- Function calls: 'strlen(str)'
- Casts: '(int*)ptr'
- Arithmetic: 'x + y * 2'
- sizeof: 'sizeof(MyStruct)'

Args:
    params: EvaluateExpressionInput with expression and context

Returns:
    str: Expression result with type information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(name="lldb_evaluate"), which evaluates C/C++ expressions using LLDB by creating a target, setting breakpoint, running, executing the expression command, and formatting the output.
    @mcp.tool(
        name="lldb_evaluate",
        annotations={
            "title": "Evaluate Expression",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        },
    )
    async def lldb_evaluate(params: EvaluateExpressionInput) -> str:
        """Evaluate a C/C++ expression in the debugger context.
    
        Expressions can include:
        - Variable access: 'my_var', 'ptr->member'
        - Array indexing: 'array[5]'
        - Function calls: 'strlen(str)'
        - Casts: '(int*)ptr'
        - Arithmetic: 'x + y * 2'
        - sizeof: 'sizeof(MyStruct)'
    
        Args:
            params: EvaluateExpressionInput with expression and context
    
        Returns:
            str: Expression result with type information
        """
        commands = [
            f"target create {params.executable}",
            f"breakpoint set --name {params.breakpoint}",
            "run" + (" " + " ".join(params.args) if params.args else ""),
            f"expression {params.expression}",
            "quit",
        ]
    
        result = _run_lldb_script(commands)
    
        return f"## Expression: `{params.expression}`\n\n```\n{result['output'].strip()}\n```"
  • Pydantic BaseModel defining the input schema for the lldb_evaluate tool, including executable path, expression to evaluate, breakpoint, and optional args.
    class EvaluateExpressionInput(BaseModel):
        """Input for evaluating expressions."""
    
        model_config = ConfigDict(str_strip_whitespace=True)
    
        executable: str = Field(..., description="Path to the executable", min_length=1)
        expression: str = Field(
            ...,
            description="C/C++ expression to evaluate (e.g., 'sizeof(int)', 'ptr->member', 'array[5]')",
            min_length=1,
        )
        breakpoint: str = Field(
            ..., description="Breakpoint location for evaluation context", min_length=1
        )
        args: list[str] | None = Field(
            default=None, description="Command-line arguments to pass to the program"
        )
  • Helper function _run_lldb_script that executes a list of LLDB commands via a temporary script file, capturing output and handling errors. Used by lldb_evaluate to run the LLDB session.
    def _run_lldb_script(
        commands: list[str],
        target: str | None = None,
        working_dir: str | None = None,
        timeout: int = 60,
    ) -> dict[str, Any]:
        """
        Execute multiple LLDB commands in sequence.
        """
        cmd = [LLDB_EXECUTABLE]
    
        if target:
            cmd.extend(["--file", target])
    
        cmd.append("--batch")
    
        for command in commands:
            cmd.extend(["-o", command])
    
        try:
            result = subprocess.run(
                cmd, capture_output=True, text=True, timeout=timeout, cwd=working_dir or os.getcwd()
            )
            return {
                "success": result.returncode == 0,
                "output": result.stdout,
                "error": result.stderr if result.returncode != 0 else None,
                "return_code": result.returncode,
            }
        except subprocess.TimeoutExpired:
            return {
                "success": False,
                "output": "",
                "error": f"Commands timed out after {timeout} seconds",
                "return_code": -1,
            }
        except Exception as e:
            return {"success": False, "output": "", "error": str(e), "return_code": -1}
    
    
    # =============================================================================
    # Initialize MCP Server
    # =============================================================================
    
    mcp = FastMCP(SERVER_NAME)
    
    
    # =============================================================================
    # Input Models
    # =============================================================================
    
    
    class ResponseFormat(str, Enum):
        """Output format for tool responses."""
Behavior4/5

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

Annotations provide readOnlyHint=true, destructiveHint=false, idempotentHint=true, and openWorldHint=false, covering safety and idempotency. The description adds valuable context by specifying the debugger context and listing expression capabilities (variable access, function calls, arithmetic, etc.), which helps the agent understand the tool's behavior beyond the annotations. No contradiction with annotations exists.

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 well-structured and front-loaded with the core purpose, followed by bullet-pointed expression examples and clear sections for Args and Returns. Every sentence earns its place without redundancy, making it efficient and easy to parse.

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

Completeness4/5

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

Given the tool's complexity (evaluating expressions in a debugger), the description provides good context with expression examples and return information. Annotations cover safety, and an output schema exists (Returns: str), so the description doesn't need to detail return values. However, it could better explain parameter interactions or prerequisites (e.g., needing a running debug session).

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%, but the description includes an 'Args' section that explains 'params' as 'EvaluateExpressionInput with expression and context' and lists expression examples. This adds some meaning, but it doesn't detail the nested parameters (executable, breakpoint, args) beyond what the schema provides. With 0% coverage, the description partially compensates but not fully.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'Evaluate a C/C++ expression in the debugger context.' It specifies the verb ('evaluate') and resource ('C/C++ expression'), and distinguishes from siblings like lldb_examine_variables (which likely inspects variables without expression evaluation) and lldb_run_command (which runs debugger commands rather than evaluating expressions).

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 when evaluating C/C++ expressions in a debugger context, but doesn't explicitly state when to use this tool versus alternatives like lldb_examine_variables or lldb_run_command. It provides examples of expression types but no explicit guidance on tool selection 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/benpm/claude_lldb_mcp'

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