Skip to main content
Glama

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
NameRequiredDescriptionDefault
serverYesServer name from configuration
commandYesCommand to execute
cwdNoWorking directory (optional, uses default if configured)
timeoutNoCommand timeout in milliseconds (default: 30000)

Implementation Reference

  • 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' ],
  • 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); } }); }); }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bvisible/mcp-ssh-manager'

If you have feedback or need assistance with the MCP directory API, please join our Discord server