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)}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'sequentially' (execution order) but omits critical behavioral traits: error handling (e.g., stops on first failure?), permissions required, output format, timeout/rate limits, or side effects. For a tool executing shell commands on a remote host, this lack of disclosure is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's front-loaded with the core action and target, and every word ('executes', 'multiple', 'shell commands', 'sequentially', 'SSH host') contributes essential information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (remote command execution with potential side effects), lack of annotations, and no output schema, the description is incomplete. It doesn't cover error handling, security implications, or return values, leaving the agent with insufficient context for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('hostAlias' and 'commands'). The description adds no additional meaning beyond implying 'commands' are executed in sequence, which is minimal value. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('executes multiple shell commands') and target ('on an SSH host'), with 'sequentially' adding operational detail. It distinguishes from siblings like 'runRemoteCommand' (singular vs. batch) and 'checkConnectivity' (diagnostic vs. execution), though not explicitly named. However, it doesn't fully differentiate from all siblings (e.g., 'uploadFile' is also SSH-related but different purpose).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., SSH connectivity established), compare to 'runRemoteCommand' for single commands, or specify use cases like batch automation. Without such context, an agent might misuse it when a sibling tool is more appropriate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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