Skip to main content
Glama
sbergeron42

gdb-multiarch-mcp

by sbergeron42

gdb_execute_command

Execute raw GDB commands for debugging Nintendo Switch executables on Yuzu or hardware via GDB stub.

Instructions

Execute a raw GDB command (CLI or MI). For Switch-specific operations, prefer the dedicated switch_* tools. IMPORTANT: Do NOT use 'target remote' or 'target extended-remote' — the session auto-connects to the Switch on first use. Do NOT use 'attach' or 'monitor wait application' — handled automatically. $main is already set to the base address of the game executable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesGDB command to execute

Implementation Reference

  • The `execute_command` method in `GDBSession` is the core handler that executes raw GDB/MI or CLI commands. It wraps CLI commands with `-interpreter-exec console` and executes them using the GDB/MI protocol.
    def execute_command(
        self, command: str, timeout_sec: int = DEFAULT_TIMEOUT_SEC
    ) -> dict[str, Any]:
        """
        Execute a GDB command and return the parsed response.
    
        Uses the GDB/MI protocol properly by sending commands with tokens and waiting
        for the (gdb) prompt. Automatically handles both MI commands (starting with '-')
        and CLI commands. CLI commands are wrapped with -interpreter-exec for proper
        output capture.
    
        Args:
            command: GDB command to execute (MI or CLI command)
            timeout_sec: Timeout for command execution (default: 30s)
    
        Returns:
            Dict containing the command result and output
        """
        if not self.controller:
            return {"status": "error", "message": "No active GDB session"}
    
        # Check if GDB process is still alive before trying to send command
        if not self._is_gdb_alive():
            logger.error(f"GDB process is not running when trying to execute: {command}")
            return {
                "status": "error",
                "message": "GDB process has exited - cannot execute command",
                "command": command,
            }
    
        # Detect if this is a CLI command (doesn't start with '-')
        # CLI commands need to be wrapped with -interpreter-exec
        is_cli_command = not command.strip().startswith("-")
        actual_command = command
    
        if is_cli_command:
            # Escape backslashes and quotes in the command
            escaped_command = command.replace("\\", "\\\\").replace('"', '\\"')
            actual_command = f'-interpreter-exec console "{escaped_command}"'
            logger.debug(f"Wrapping CLI command: {command} -> {actual_command}")
    
        # Send command and wait for (gdb) prompt using the proper MI protocol
        result = self._send_command_and_wait_for_prompt(actual_command, timeout_sec)
    
        # Check for errors
        if "error" in result:
            error_response = {
                "status": "error",
                "message": result["error"],
                "command": command,
            }
            # Propagate fatal flag if present (indicates GDB internal error)
            if result.get("fatal"):
                error_response["fatal"] = True
            return error_response
    
        if result.get("timed_out"):
            return {
                "status": "error",
                "message": f"Timeout waiting for command response after {timeout_sec}s",
                "command": command,
            }
    
        # Parse command responses
        command_responses = result.get("command_responses", [])
        parsed = self._parse_responses(command_responses)
    
        # For CLI commands, format the output more clearly
        if is_cli_command:
            # Combine all console output
            console_output = "".join(parsed.get("console", []))
    
            return {
                "status": "success",
                "command": command,
                "output": console_output.strip() if console_output else "(no output)",
            }
        else:
            # For MI commands, return structured result
            return {"status": "success", "command": command, "result": parsed}
  • The `call_tool` function in `server.py` dispatches the `gdb_execute_command` tool call to the `session.execute_command()` method.
    elif name == "gdb_execute_command":
        a = ExecuteCommandArgs(**arguments)
        result = session.execute_command(command=a.command)
  • The input schema for `gdb_execute_command` is defined by the `ExecuteCommandArgs` Pydantic model.
    class ExecuteCommandArgs(BaseModel):
        command: str = Field(..., description="GDB command to execute")
  • The `gdb_execute_command` tool is registered in the `list_tools` function within `server.py`.
    Tool(
        name="gdb_execute_command",
        description=(
            "Execute a raw GDB command (CLI or MI). "
            "For Switch-specific operations, prefer the dedicated switch_* tools. "
            "IMPORTANT: Do NOT use 'target remote' or 'target extended-remote' — "
            "the session auto-connects to the Switch on first use. "
            "Do NOT use 'attach' or 'monitor wait application' — handled automatically. "
            "$main is already set to the base address of the game executable."
        ),
        inputSchema=ExecuteCommandArgs.model_json_schema(),
    ),
Behavior4/5

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

With no annotations provided, description carries full burden and successfully discloses critical behavioral traits: auto-connection to Switch on first use, automatic handling of attach/monitor commands, and pre-set $main variable. However, lacks general warning about mutation risks inherent in arbitrary GDB command execution and does not describe output format.

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?

Perfectly front-loaded: purpose (sentence 1), sibling differentiation (sentence 2), critical constraints (sentences 3-4), environment context (sentence 5). Every sentence earns its place with zero redundancy despite covering multiple critical constraints and context signals.

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?

Strong compensation for missing annotations and output schema by documenting environmental state ($main variable), connection behavior, and prohibited commands. However, lacks description of return values or console output format, which would be valuable given no output schema exists and GDB commands produce variable output.

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?

Schema has 100% coverage establishing baseline 3. Description adds valuable context beyond schema by specifying commands can be 'CLI or MI' (Machine Interface) formats, hinting at syntax options not explicitly detailed in the schema's 'GDB command to execute' definition.

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?

Description explicitly states 'Execute a raw GDB command (CLI or MI)' with specific verb and resource. Critically distinguishes from 15+ sibling tools by stating 'For Switch-specific operations, prefer the dedicated switch_* tools', clearly delineating when to use this generic tool vs. specialized alternatives.

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

Usage Guidelines5/5

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

Provides explicit prohibitions ('Do NOT use target remote', 'Do NOT use attach') and explains why ('session auto-connects', 'handled automatically'). Explicitly directs users to switch_* alternatives for Switch-specific operations, creating clear decision boundaries between this tool and its siblings.

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/sbergeron42/gdb-multiarch-mcp'

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