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);
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 states what the tool does but doesn't describe key behaviors: whether this is a read-only operation, if it blocks until output is available, what happens on timeout, or the format of returned output. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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, clear sentence that front-loads the essential action ('Read output'). There's no wasted verbiage or redundancy, making it highly efficient and easy to parse quickly.

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?

Given the complexity of interactive shell operations and the lack of annotations and output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., text, error handling), how it interacts with session state, or prerequisites like needing an active session. For a tool with no structured output information, more context is needed to be fully helpful.

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 already documents all three parameters thoroughly. The description doesn't add any additional meaning beyond what's in the schema (e.g., it doesn't explain how sessionId relates to interactive sessions or clarify timeout behavior). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't detract either.

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 verb ('Read') and resource ('output from an interactive shell session'), making the purpose immediately understandable. It distinguishes from siblings like ssh_send_input (which sends input) and ssh_execute (which executes commands non-interactively). However, it doesn't specify that this reads from an existing session rather than creating one, which could be more explicit.

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

Usage Guidelines3/5

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

The description implies usage by mentioning 'interactive shell session', suggesting it should be used after starting a session with ssh_start_interactive_shell. However, it doesn't explicitly state when to use this vs. alternatives like ssh_execute (for non-interactive output) or provide clear exclusions. The context is somewhat implied but lacks direct guidance.

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/mahathirmuh/mcp-ssh-server'

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