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);

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