Skip to main content
Glama

ssh_read_output

Retrieve command output from an interactive SSH shell session to monitor execution results and manage remote server operations.

Instructions

Read output from an interactive shell session

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesInteractive session ID
timeoutNoTimeout in milliseconds to wait for output
clearBufferNoClear the output buffer after reading

Implementation Reference

  • The main handler function for the 'ssh_read_output' tool. It parses input parameters using ReadOutputSchema, retrieves the shell session, waits for output from the session buffer with a configurable timeout, optionally clears the buffer, and returns the output as text content.
    private async handleReadOutput(args: unknown) {
      const params = ReadOutputSchema.parse(args);
      
      const session = shellSessions.get(params.sessionId);
      if (!session) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Session ID '${params.sessionId}' not found`
        );
      }
    
      try {
        // Wait for output with timeout
        const output = await new Promise<string>((resolve, reject) => {
          const timeout = setTimeout(() => {
            resolve(session.buffer);
          }, params.timeout);
    
          if (session.buffer) {
            clearTimeout(timeout);
            resolve(session.buffer);
          } else {
            session.emitter.once('data', () => {
              clearTimeout(timeout);
              resolve(session.buffer);
            });
          }
        });
    
        const result = output;
        
        if (params.clearBuffer) {
          session.buffer = '';
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `Output from session '${params.sessionId}':\n${result}`,
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to read output: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Zod schema definition used for input validation in the ssh_read_output handler. Defines parameters: sessionId (required), timeout (default 5000ms), clearBuffer (default true).
    const ReadOutputSchema = z.object({
      sessionId: z.string().describe('Interactive session ID'),
      timeout: z.number().default(5000).describe('Timeout in milliseconds to wait for output'),
      clearBuffer: z.boolean().default(true).describe('Clear the output buffer after reading')
    });
  • src/index.ts:348-359 (registration)
    Tool registration in the ListTools response. Defines the name, description, and JSON input schema for ssh_read_output.
      name: 'ssh_read_output',
      description: 'Read output from an interactive shell session',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: { type: 'string', description: 'Interactive session ID' },
          timeout: { type: 'number', default: 5000, description: 'Timeout in milliseconds to wait for output' },
          clearBuffer: { type: 'boolean', default: true, description: 'Clear the output buffer after reading' }
        },
        required: ['sessionId']
      },
    },
  • src/index.ts:501-502 (registration)
    Dispatch case in the CallToolRequest handler switch statement that routes calls to the ssh_read_output tool to its handler function.
    case 'ssh_read_output':
      return await this.handleReadOutput(args);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions reading output but doesn't disclose what happens on timeout, how output is formatted, whether it's blocking/non-blocking, or error conditions. This is inadequate for a tool that interacts with live shell sessions.

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 a single, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded with the core purpose.

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

Completeness2/5

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

For a tool that reads from interactive sessions with no annotations and no output schema, the description is insufficient. It doesn't explain return values, error handling, or important behavioral aspects like what 'output' includes (stdout, stderr, both). More context is needed given the complexity.

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 100%, so the schema fully documents all three parameters. The description adds no additional parameter context beyond implying a session exists, which is already covered by the sessionId parameter's description. Baseline 3 is appropriate when schema does the heavy lifting.

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 action ('Read output') and resource ('from an interactive shell session'), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like ssh_execute or ssh_send_input, but the focus on reading output from an existing session is reasonably distinct.

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 doesn't mention prerequisites (e.g., needing an active session via ssh_start_interactive_shell), exclusions, or comparisons to non-interactive execution tools like ssh_execute.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.