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
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Interactive session ID | |
| timeout | No | Timeout in milliseconds to wait for output | |
| clearBuffer | No | Clear the output buffer after reading |
Implementation Reference
- src/index.ts:1004-1053 (handler)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)}` ); } }
- src/index.ts:113-117 (schema)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);