ssh_send_input
Send commands or text to an active SSH shell session, with optional human-like typing simulation for interactive applications.
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)Implements the core logic for sending input to an active SSH interactive shell session. Retrieves the session from the pool, optionally simulates human typing with delays, and writes the input to the shell channel.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), and optional simulateTyping flag.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:334-346 (registration)Registers the ssh_send_input tool in the MCP server's listTools response, including name, description, and input schema.{ 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)Dispatches calls to the ssh_send_input tool by invoking the handleSendInput handler in the central CallToolRequestSchema switch statement.case 'ssh_send_input': return await this.handleSendInput(args);