get_command_history
Retrieve a formatted record of recent terminal commands. Specify the number of commands to review past actions.
Instructions
Get recent command execution history
Args:
count: Number of recent commands to return
Returns:
Formatted command history recordInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No |
Implementation Reference
- terminal_controller.py:145-168 (handler)The handler function for the 'get_command_history' MCP tool. Registered with @mcp.tool() decorator, it reads from the global 'command_history' list (populated by run_command) and returns a formatted string of recent commands with success/failure status.
@mcp.tool() async def get_command_history(count: int = 10) -> str: """ Get recent command execution history Args: count: Number of recent commands to return Returns: Formatted command history record """ if not command_history: return "No command execution history." count = min(count, len(command_history)) recent_commands = command_history[-count:] output = f"Recent {count} command history:\n\n" for i, cmd in enumerate(recent_commands): status = "✓" if cmd["success"] else "✗" output += f"{i+1}. [{status}] {cmd['timestamp']}: {cmd['command']}\n" return output - terminal_controller.py:145-145 (registration)Registration of the tool via the @mcp.tool() decorator on the FastMCP instance 'mcp'.
@mcp.tool() - terminal_controller.py:147-155 (schema)The docstring serves as the schema/description for the tool, defining the 'count' parameter (int, default 10) and the return type (str).
""" Get recent command execution history Args: count: Number of recent commands to return Returns: Formatted command history record """ - terminal_controller.py:79-84 (helper)The run_command helper function populates the global 'command_history' list that get_command_history reads from.
# Add to history command_history.append({ "timestamp": datetime.now().isoformat(), "command": cmd, "success": return_code == 0 })