ssh_send_input
Send commands or text to an interactive SSH shell session, optionally simulating human typing for automation scripts or remote management tasks.
Instructions
Send input to an interactive shell session with optional typing simulation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Interactive session ID | |
| input | Yes | Input to send to the shell | |
| simulateTyping | No | Simulate human typing with delays |
Implementation Reference
- src/index.ts:958-1002 (handler)The handler function for 'ssh_send_input' tool. It validates input parameters using SendInputSchema, retrieves the active shell session by sessionId, sends the input to the SSH shell (optionally simulating human typing with delays), and returns a confirmation message.private async handleSendInput(args: unknown) { const params = SendInputSchema.parse(args); const session = shellSessions.get(params.sessionId); if (!session) { throw new McpError( ErrorCode.InvalidParams, `Session ID '${params.sessionId}' not found` ); } if (!session.isActive) { throw new McpError( ErrorCode.InvalidParams, `Session '${params.sessionId}' is not active` ); } try { if (params.simulateTyping) { // Simulate human typing with random delays for (const char of params.input) { session.shell.write(char); // Random delay between 50-150ms per character await new Promise(resolve => setTimeout(resolve, 50 + Math.random() * 100)); } } else { session.shell.write(params.input); } return { content: [ { type: 'text', text: `Input sent to session '${params.sessionId}'${params.simulateTyping ? ' (with typing simulation)' : ''}\nInput: ${params.input}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to send input: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:107-111 (schema)Zod schema defining the input parameters for the 'ssh_send_input' tool: sessionId (required), input (required), simulateTyping (optional boolean). Used for validation in the handler.const SendInputSchema = z.object({ sessionId: z.string().describe('Interactive session ID'), input: z.string().describe('Input to send to the shell'), simulateTyping: z.boolean().default(false).describe('Simulate human typing with delays') });
- src/index.ts:335-346 (registration)Tool registration in the ListTools response. Defines the name, description, and inputSchema for 'ssh_send_input', making it discoverable by MCP clients.name: 'ssh_send_input', description: 'Send input to an interactive shell session with optional typing simulation', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Interactive session ID' }, input: { type: 'string', description: 'Input to send to the shell' }, simulateTyping: { type: 'boolean', default: false, description: 'Simulate human typing with delays' } }, required: ['sessionId', 'input'] }, },
- src/index.ts:499-500 (registration)Dispatch/registration in the CallToolRequestSchema handler switch statement, routing calls to the handleSendInput method.case 'ssh_send_input': return await this.handleSendInput(args);