ssh_execute
Execute commands on a remote server via SSH using a specified connection ID. Define the command and working directory to streamline remote server management tasks.
Instructions
Execute a command on a remote SSH server
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Command to execute on remote server | |
| connectionId | Yes | SSH connection ID | |
| cwd | No | Working directory for command execution |
Input Schema (JSON Schema)
{
"properties": {
"command": {
"description": "Command to execute on remote server",
"type": "string"
},
"connectionId": {
"description": "SSH connection ID",
"type": "string"
},
"cwd": {
"description": "Working directory for command execution",
"type": "string"
}
},
"required": [
"connectionId",
"command"
],
"type": "object"
}
Implementation Reference
- src/index.ts:626-656 (handler)The handler function for the 'ssh_execute' tool. It validates input using ExecuteCommandSchema, retrieves the SSH connection from the pool, executes the specified command using ssh.execCommand with optional cwd, and returns the command output including stdout, stderr, and exit code.private async handleSSHExecute(args: unknown) { const params = ExecuteCommandSchema.parse(args); const ssh = connectionPool.get(params.connectionId); if (!ssh) { throw new McpError( ErrorCode.InvalidParams, `Connection ID '${params.connectionId}' not found` ); } try { const result = await ssh.execCommand(params.command, { cwd: params.cwd, }); return { content: [ { type: 'text', text: `Command: ${params.command}\nExit Code: ${result.code}\n\nSTDOUT:\n${result.stdout}\n\nSTDERR:\n${result.stderr}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Command execution failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:74-78 (schema)Zod schema for validating input parameters to the ssh_execute tool: connectionId (required), command (required), cwd (optional).const ExecuteCommandSchema = z.object({ connectionId: z.string().describe('SSH connection ID'), command: z.string().describe('Command to execute on remote server'), cwd: z.string().optional().describe('Working directory for command execution') });
- src/index.ts:267-279 (registration)Tool registration in the ListTools response, defining name 'ssh_execute', description, and inputSchema matching the ExecuteCommandSchema.name: 'ssh_execute', description: 'Execute a command on a remote SSH server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'SSH connection ID' }, command: { type: 'string', description: 'Command to execute on remote server' }, cwd: { type: 'string', description: 'Working directory for command execution' } }, required: ['connectionId', 'command'] }, }, {
- src/index.ts:489-490 (registration)Dispatch case in the CallToolRequest handler switch statement that routes 'ssh_execute' calls to the handleSSHExecute method.case 'ssh_execute': return await this.handleSSHExecute(args);