terminal_get_output
Retrieve recent terminal output including command inputs and results for monitoring or debugging purposes. Specify session ID and number of lines to capture from terminal history.
Instructions
Get the output from a terminal.
Retrieves the recent output from the terminal's history. This includes
both command inputs and their outputs.
Args:
session_id: The terminal session ID returned by terminal_create_or_get.
lines: Number of lines to retrieve from the end (default: 100, max: 1000).
Returns:
dict: Contains success status, session_id, and the output text.
Examples:
- Get last 100 lines: terminal_get_output(session_id="abc123")
- Get last 50 lines: terminal_get_output(session_id="abc123", lines=50)
Note:
Output may have a slight delay as it's captured asynchronously from
the terminal process.Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| lines | No |
Implementation Reference
- src/terminal_mcp/server.py:131-172 (handler)The implementation of the terminal_get_output tool handler, which retrieves terminal output from the SessionManager.
async def terminal_get_output(session_id: str, lines: int = 100) -> dict: """Get the output from a terminal. Retrieves the recent output from the terminal's history. This includes both command inputs and their outputs. Args: session_id: The terminal session ID returned by terminal_create_or_get. lines: Number of lines to retrieve from the end (default: 100, max: 1000). Returns: dict: Contains success status, session_id, and the output text. Examples: - Get last 100 lines: terminal_get_output(session_id="abc123") - Get last 50 lines: terminal_get_output(session_id="abc123", lines=50) Note: Output may have a slight delay as it's captured asynchronously from the terminal process. """ manager = SessionManager.get_instance() session = await manager.get_session(session_id) if not session: return { "success": False, "error": f"Session '{session_id}' not found. It may have been closed or never existed.", "suggestion": "Use terminal_create_or_get to create a new terminal.", } # Clamp lines to reasonable range lines = max(1, min(lines, 1000)) output = await manager.get_output(session_id, lines) return { "success": True, "session_id": session_id, "terminal_name": session.name, "output": output, "lines_requested": lines, } - src/terminal_mcp/server.py:121-130 (registration)MCP tool registration for terminal_get_output.
@mcp.tool( name="terminal_get_output", annotations={ "title": "Get Terminal Output", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False, }, )