runRemoteCommand
Execute shell commands on remote SSH hosts to manage systems, run scripts, or perform administrative tasks securely through the MCP SSH Agent interface.
Instructions
Executes a shell command on an SSH host
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hostAlias | Yes | Alias or hostname of the SSH host | |
| command | Yes | The shell command to execute |
Implementation Reference
- src/ssh-client.ts:24-47 (handler)The main handler function for the 'runRemoteCommand' tool. It connects to the specified SSH host using the SSHClient class, executes the given command remotely, and returns the stdout, stderr, and exit code.async runRemoteCommand(hostAlias: string, command: string): Promise<CommandResult> { try { // First connect to the host await this.connectToHost(hostAlias); // Execute the command const result = await this.ssh.execCommand(command); return { stdout: result.stdout, stderr: result.stderr, code: result.code || 0 }; } catch (error) { console.error(`Error executing command on ${hostAlias}:`, error); return { stdout: '', stderr: error instanceof Error ? error.message : String(error), code: 1 }; } finally { this.ssh.dispose(); } }
- src/types.ts:12-16 (schema)Type definition for the output of runRemoteCommand, defining the structure of CommandResult returned by the tool.export interface CommandResult { stdout: string; stderr: string; code: number; }