Skip to main content
Glama

ssh_read_output

Retrieve output from an active SSH shell session by specifying a session ID, with options to set timeout duration and clear the buffer after reading.

Instructions

Read output from an interactive shell session

Input Schema

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

Implementation Reference

  • Implementation of the ssh_read_output tool handler. 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 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 defining the input parameters for the ssh_read_output tool: 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-358 (registration)
    Registration of the ssh_read_output tool in the ListTools response, providing name, description, and JSON schema matching the Zod schema.
    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 registration in the CallToolRequestSchema switch statement, routing calls to ssh_read_output to the handleReadOutput method.
    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