Skip to main content
Glama

runCommandBatch

Execute multiple shell commands sequentially on an SSH host to automate remote administration tasks through the MCP SSH Agent.

Instructions

Executes multiple shell commands sequentially on an SSH host

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostAliasYesAlias or hostname of the SSH host
commandsYesList of shell commands to execute

Implementation Reference

  • The primary handler function implementing the 'runCommandBatch' tool. Connects to an SSH host via alias, executes each command in the provided array sequentially, collects stdout, stderr, and exit code for each, computes overall success, and returns structured results. Handles connection and execution errors gracefully.
    async runCommandBatch(hostAlias: string, commands: string[]): Promise<BatchCommandResult> { try { await this.connectToHost(hostAlias); const results: CommandResult[] = []; let success = true; for (const command of commands) { const result = await this.ssh.execCommand(command); const cmdResult: CommandResult = { stdout: result.stdout, stderr: result.stderr, code: result.code || 0 }; results.push(cmdResult); if (cmdResult.code !== 0) { success = false; // We don't abort, execute all commands } } this.ssh.dispose(); return { results, success }; } catch (error) { console.error(`Error during batch execution on ${hostAlias}:`, error); return { results: [{ stdout: '', stderr: error instanceof Error ? error.message : String(error), code: 1 }], success: false }; } }
  • Output schema/type for the runCommandBatch tool: array of individual command results and boolean indicating if all commands succeeded.
    // Batch result of remote commands export interface BatchCommandResult { results: CommandResult[]; success: boolean; }
  • Schema for individual command results used within BatchCommandResult output of runCommandBatch.
    // Result of a remote command export interface CommandResult { stdout: string; stderr: string; code: number; }
  • Helper function called by runCommandBatch to resolve host alias to connection details from SSH config and establish the NodeSSH connection.
    private async connectToHost(hostAlias: string): Promise<void> { // Get host information const hostInfo = await this.getHostInfo(hostAlias); if (!hostInfo) { throw new Error(`Host ${hostAlias} not found`); } // Create connection configuration const connectionConfig = { host: hostInfo.hostname, username: hostInfo.user, port: hostInfo.port || 22, privateKeyPath: hostInfo.identityFile }; try { await this.ssh.connect(connectionConfig); } catch (error) { throw new Error(`Connection to ${hostAlias} failed: ${error instanceof Error ? error.message : String(error)}`); } }

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/AiondaDotCom/mcp-ssh'

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