Skip to main content
Glama
samerfarida

MCP SSH Orchestrator

ssh_get_task_output

Retrieve recent output lines from running or completed SSH tasks to monitor execution progress and results in server fleet management.

Instructions

Get recent output lines from running or completed task.

Enhanced beyond SEP-1686: enables streaming output visibility.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
task_idNo
max_linesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'ssh_get_task_output' MCP tool. It performs input validation on task_id and max_lines, then delegates to ASYNC_TASKS.get_task_output to retrieve recent output lines from the task.
    @mcp.tool()
    def ssh_get_task_output(
        task_id: str = "", max_lines: int = 50, ctx: Context | None = None
    ) -> ToolResult:
        """Get recent output lines from running or completed task.
    
        Enhanced beyond SEP-1686: enables streaming output visibility.
        """
        try:
            # Input validation
            valid, error_msg = _validate_task_id(task_id)
            if not valid:
                return f"Error: {error_msg}"
    
            if max_lines < 1 or max_lines > 1000:
                return "Error: max_lines must be between 1 and 1000"
    
            task_id = task_id.strip()
            output = ASYNC_TASKS.get_task_output(task_id, max_lines)
            if not output:
                return f"Error: Task not found or no output available: {task_id}"
    
            _ctx_log(
                ctx,
                "debug",
                "ssh_get_task_output",
                {"task_id": task_id, "max_lines": max_lines},
            )
            return output
    
        except Exception as e:
            error_str = str(e)
            log_json({"level": "error", "msg": "output_exception", "error": error_str})
            _ctx_log(
                ctx,
                "debug",
                "ssh_get_task_output_error",
                {"task_id": task_id.strip(), "error": sanitize_error(error_str)},
            )
            return f"Output error: {sanitize_error(error_str)}"
  • The core helper method in AsyncTaskManager that implements the logic for retrieving recent output lines from a task's output buffer (for running tasks) or stored result (for completed tasks).
        self, task_id: str, max_lines: int = 50
    ) -> dict[str, Any] | None:
        """Get recent output lines."""
        with self._lock:
            # First check if task is still running and has output buffer
            output_buffer = self._output_buffers.get(task_id)
            if output_buffer and len(output_buffer) > 0:
                # Convert deque to list and get recent lines
                all_lines = list(output_buffer)
                recent_lines = (
                    all_lines[-max_lines:] if len(all_lines) > max_lines else all_lines
                )
    
                return {
                    "task_id": task_id,
                    "output_lines": recent_lines,
                    "total_lines": len(all_lines),
                    "has_more": len(all_lines) > max_lines,
                }
    
            # If no output buffer or empty buffer, check if task is completed and has result
            result = self._results.get(task_id)
            if result and result["expires"] > time.time():
                # Split the output into lines and return recent ones
                output_text = result.get("output", "")
                all_lines = output_text.split("\n") if output_text else []
                recent_lines = (
                    all_lines[-max_lines:] if len(all_lines) > max_lines else all_lines
                )
    
                return {
                    "task_id": task_id,
                    "output_lines": recent_lines,
                    "total_lines": len(all_lines),
                    "has_more": len(all_lines) > max_lines,
                }
    
            # Also check if task is still in _tasks but completed (no output buffer)
            task_info = self._tasks.get(task_id)
            if task_info and task_info.get("output"):
                # Split the output into lines and return recent ones
                output_text = task_info.get("output", "")
                all_lines = output_text.split("\n") if output_text else []
                recent_lines = (
                    all_lines[-max_lines:] if len(all_lines) > max_lines else all_lines
                )
    
                return {
                    "task_id": task_id,
                    "output_lines": recent_lines,
                    "total_lines": len(all_lines),
                    "has_more": len(all_lines) > max_lines,
                }
    
            return None
  • Global ASYNC_TASKS instance of AsyncTaskManager used by the tool handler.
    ASYNC_TASKS = AsyncTaskManager()
  • The @mcp.tool() decorator registers ssh_get_task_output as an MCP tool with FastMCP.
    @mcp.tool()
    def ssh_get_task_output(
        task_id: str = "", max_lines: int = 50, ctx: Context | None = None
    ) -> ToolResult:
        """Get recent output lines from running or completed task.
    
        Enhanced beyond SEP-1686: enables streaming output visibility.
        """
        try:
            # Input validation
            valid, error_msg = _validate_task_id(task_id)
            if not valid:
                return f"Error: {error_msg}"
    
            if max_lines < 1 or max_lines > 1000:
                return "Error: max_lines must be between 1 and 1000"
    
            task_id = task_id.strip()
            output = ASYNC_TASKS.get_task_output(task_id, max_lines)
            if not output:
                return f"Error: Task not found or no output available: {task_id}"
    
            _ctx_log(
                ctx,
                "debug",
                "ssh_get_task_output",
                {"task_id": task_id, "max_lines": max_lines},
            )
            return output
    
        except Exception as e:
            error_str = str(e)
            log_json({"level": "error", "msg": "output_exception", "error": error_str})
            _ctx_log(
                ctx,
                "debug",
                "ssh_get_task_output_error",
                {"task_id": task_id.strip(), "error": sanitize_error(error_str)},
            )
            return f"Output error: {sanitize_error(error_str)}"
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'streaming output visibility,' implying real-time or incremental data access, but doesn't detail rate limits, authentication needs, error handling, or whether it's read-only. For a tool with no annotation coverage, this is insufficient to inform safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two sentences: the first states the purpose clearly, and the second adds feature context. It's front-loaded with the core function, and both sentences earn their place by providing essential information without waste. However, the second sentence could be more integrated into usage guidelines.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters, no annotations, but has an output schema), the description is minimally adequate. The output schema likely covers return values, reducing the need for description details there. However, it lacks usage guidelines and behavioral context, making it incomplete for optimal agent decision-making in a server with multiple task-related tools.

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%, so the schema provides no parameter details. The description doesn't mention parameters at all, failing to compensate for the coverage gap. However, with only 2 parameters (task_id and max_lines), the baseline is moderate. The description's lack of parameter info results in a minimal viable score, as it doesn't add meaning beyond the schema's structural hints.

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

Purpose4/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: 'Get recent output lines from running or completed task.' It specifies the verb ('Get') and resource ('output lines from task'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like ssh_get_task_result or ssh_get_task_status, which likely retrieve different aspects of task data.

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?

The description provides no guidance on when to use this tool versus alternatives. It mentions 'Enhanced beyond SEP-1686: enables streaming output visibility,' which hints at a feature but doesn't clarify use cases, prerequisites, or exclusions compared to siblings like ssh_get_task_result. This leaves the agent without context for tool selection.

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/samerfarida/mcp-ssh-orchestrator'

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