Skip to main content
Glama
vilasone455

SSH MCP Server

by vilasone455

execute_command

Execute shell commands on remote Linux or Windows systems via SSH to manage servers, run scripts, and perform administrative tasks.

Instructions

Run a shell command in an existing SSH session and return stdout/stderr/exitCode.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connection_idYes
commandYesShell command to execute

Implementation Reference

  • Main handler logic for the execute_command tool. Validates inputs, executes the command on the SSH connection using wrapExec helper, updates currentPath for cd commands, and returns structured output with stdout, stderr, and exitCode.
    // execute_command
    if (name === "execute_command") {
      const { connection_id, command } = args as { connection_id: string; command: string };
      if (!command?.trim()) throw new Error("Command cannot be empty.");
    
      const conn = connections.get(connection_id);
      if (!conn) throw new Error(`connection_id '${connection_id}' not found.`);
    
      const { stdout, stderr, exitCode } = await wrapExec(conn.client, command);
    
      // update PWD if the agent just cd’d somewhere
      if (/^cd\\s+/.test(command.trim())) {
        const { stdout: cwd } = await wrapExec(conn.client, "pwd");
        conn.currentPath = cwd.trim();
      }
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({ stdout, stderr, exitCode }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:167-180 (registration)
    Registration of the execute_command tool within the ListTools handler, including name, description, and input schema definition.
    {
      name: "execute_command",
      description:
        "Run a shell command in an existing SSH session and return stdout/stderr/exitCode.",
      inputSchema: {
        type: "object",
        required: ["connection_id", "command"],
        properties: {
          connection_id: { type: "string" },
          command: { type: "string", description: "Shell command to execute" },
        },
        additionalProperties: false,
      },
    },
  • Input schema definition for the execute_command tool, specifying required connection_id and command parameters.
    inputSchema: {
      type: "object",
      required: ["connection_id", "command"],
      properties: {
        connection_id: { type: "string" },
        command: { type: "string", description: "Shell command to execute" },
      },
      additionalProperties: false,
    },
  • Supporting helper function used by the execute_command handler to wrap SSH client.exec, capturing stdout, stderr, and exit code in a Promise.
    function wrapExec(client, command): any {
      return new Promise((resolve, reject) => {
        let stdout = "";
        let stderr = "";
        client.exec(command, (err, stream) => {
          if (err) return reject(err);
          stream
            .on("close", (code) => {
              resolve({ stdout, stderr, exitCode: code });
            })
            .on("data", (data) => {
              stdout += data.toString();
            })
            .stderr.on("data", (data) => {
              stderr += data.toString();
            });
        });
      });
    }
Behavior2/5

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

With no annotations, the description carries full burden. It discloses the tool executes commands and returns output/exit codes, but lacks critical behavioral details: whether commands run with specific permissions, timeouts, side effects (e.g., file modifications), error handling, or security implications. For a shell execution tool, this 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 that front-loads the core action and outcome. Every word earns its place, with no redundancy or unnecessary elaboration, making it highly concise and well-structured.

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

Completeness3/5

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

Given no annotations, no output schema, and a tool that executes shell commands (a potentially complex operation), the description is minimally adequate. It covers the basic purpose and output format but lacks details on behavioral traits, error cases, or security considerations, leaving gaps for an AI agent to use it safely and effectively.

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

Parameters4/5

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

Schema description coverage is 50% (only 'command' has a description). The description adds no explicit parameter semantics beyond what the schema provides. However, with only 2 parameters and one documented in schema, the baseline is high. The description's context ('in an existing SSH session') implicitly clarifies 'connection_id' as an active session identifier, adding some value.

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

Purpose5/5

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

The description clearly states the specific action ('Run a shell command'), resource ('in an existing SSH session'), and outcome ('return stdout/stderr/exitCode'). It distinguishes from siblings like create_connection (establishes session) and close_connection (terminates session) by focusing on command execution within an existing session.

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

Usage Guidelines3/5

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

The description implies usage context ('in an existing SSH session'), suggesting this tool should be used after establishing a connection. However, it doesn't explicitly state when to use alternatives like secure_execute_command or provide prerequisites (e.g., connection must be active). The guidance is present but incomplete.

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

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