Skip to main content
Glama

ssh_read_output

Retrieve command execution results from an active SSH shell session by specifying the session ID and optional timeout settings.

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

  • Handler function that reads output from an interactive SSH shell session buffer, with optional timeout and buffer clearing.
    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 for validating input parameters to the ssh_read_output tool.
    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:347-358 (registration)
    Tool registration in the listTools response, including name, description, and input 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)
    Switch case in CallToolRequest handler that routes to the ssh_read_output 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/widjis/mcp-ssh'

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