ssh_execute
Execute commands on remote SSH servers through the MCP SSH Manager by specifying server configurations and command parameters.
Instructions
Execute command on remote SSH server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| server | Yes | Server name from configuration | |
| command | Yes | Command to execute | |
| cwd | No | Working directory (optional, uses default if configured) | |
| timeout | No | Command timeout in milliseconds (default: 30000) |
Implementation Reference
- src/tool-registry.js:12-20 (registration)TOOL_GROUPS.core includes 'ssh_execute' as part of essential SSH operations. This central registry defines all tools and their groups, used for dynamic registration, validation, and conditional enabling in the MCP server.export const TOOL_GROUPS = { // Core group (5 tools) - Essential SSH operations core: [ 'ssh_list_servers', 'ssh_execute', 'ssh_upload', 'ssh_download', 'ssh_sync' ],
- src/ssh-manager.js:113-198 (handler)The execCommand method of SSHManager executes arbitrary commands over SSH. It handles connection check, working directory changes, timeouts with forceful termination, captures stdout/stderr/exit code/signal. This is the primary execution logic for the 'ssh_execute' MCP tool.async execCommand(command, options = {}) { if (!this.connected) { throw new Error('Not connected to SSH server'); } const { timeout = 30000, cwd, rawCommand = false } = options; const fullCommand = (cwd && !rawCommand) ? `cd ${cwd} && ${command}` : command; return new Promise((resolve, reject) => { let stdout = ''; let stderr = ''; let completed = false; let stream = null; let timeoutId = null; // Setup timeout first if (timeout > 0) { timeoutId = setTimeout(() => { if (!completed) { completed = true; // Try multiple ways to kill the stream if (stream) { try { stream.write('\x03'); // Send Ctrl+C stream.end(); stream.destroy(); } catch (e) { // Ignore errors } } // Kill the entire client connection as last resort try { this.client.end(); this.connected = false; } catch (e) { // Ignore errors } reject(new Error(`Command timeout after ${timeout}ms: ${command.substring(0, 100)}...`)); } }, timeout); } this.client.exec(fullCommand, (err, streamObj) => { if (err) { completed = true; if (timeoutId) clearTimeout(timeoutId); reject(err); return; } stream = streamObj; stream.on('close', (code, signal) => { if (!completed) { completed = true; if (timeoutId) clearTimeout(timeoutId); resolve({ stdout, stderr, code: code || 0, signal }); } }); stream.on('data', (data) => { stdout += data.toString(); }); stream.stderr.on('data', (data) => { stderr += data.toString(); }); stream.on('error', (err) => { if (!completed) { completed = true; if (timeoutId) clearTimeout(timeoutId); reject(err); } }); }); }); }