ssh_send_input
Send commands or input to an active SSH shell session, optionally simulating human typing for interactive tasks using the SSH MCP Server.
Instructions
Send input to an interactive shell session with optional typing simulation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | Input to send to the shell | |
| sessionId | Yes | Interactive session ID | |
| simulateTyping | No | Simulate human typing with delays |
Input Schema (JSON Schema)
{
"properties": {
"input": {
"description": "Input to send to the shell",
"type": "string"
},
"sessionId": {
"description": "Interactive session ID",
"type": "string"
},
"simulateTyping": {
"default": false,
"description": "Simulate human typing with delays",
"type": "boolean"
}
},
"required": [
"sessionId",
"input"
],
"type": "object"
}
Implementation Reference
- src/index.ts:958-1002 (handler)The handler function that executes the ssh_send_input tool. It validates parameters using SendInputSchema, retrieves the shell session from shellSessions, checks if active, sends input to the shell (simulating typing if requested), 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).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)Registration of the ssh_send_input tool in the 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)Dispatch case in the CallToolRequest handler switch statement that routes ssh_send_input calls to the handleSendInput method.case 'ssh_send_input': return await this.handleSendInput(args);
- src/index.ts:57-57 (helper)Global shellSessions Map used by ssh_send_input to store and retrieve active interactive shell sessions.const shellSessions = new Map<string, ShellSession>();