Skip to main content
Glama

ssh_execute

Execute commands on remote SSH servers to manage systems, run scripts, or perform administrative tasks through secure connections.

Instructions

Execute a command on a remote SSH server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID
commandYesCommand to execute on remote server
cwdNoWorking directory for command execution

Implementation Reference

  • The handler function for 'ssh_execute' tool. Parses input using ExecuteCommandSchema, retrieves SSH connection from pool, executes the command using ssh.execCommand(), and returns stdout, stderr, and exit code.
    private async handleSSHExecute(args: unknown) {
      const params = ExecuteCommandSchema.parse(args);
      
      const ssh = connectionPool.get(params.connectionId);
      if (!ssh) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Connection ID '${params.connectionId}' not found`
        );
      }
    
      try {
        const result = await ssh.execCommand(params.command, {
          cwd: params.cwd,
        });
    
        return {
          content: [
            {
              type: 'text',
              text: `Command: ${params.command}\nExit Code: ${result.code}\n\nSTDOUT:\n${result.stdout}\n\nSTDERR:\n${result.stderr}`,
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Command execution failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Zod schema defining the input parameters for the ssh_execute tool: required connectionId and command, optional cwd.
    const ExecuteCommandSchema = z.object({
      connectionId: z.string().describe('SSH connection ID'),
      command: z.string().describe('Command to execute on remote server'),
      cwd: z.string().optional().describe('Working directory for command execution')
    });
  • src/index.ts:267-278 (registration)
    Tool registration/definition in the ListTools response, including name, description, and inputSchema matching the handler.
      name: 'ssh_execute',
      description: 'Execute a command on a remote SSH server',
      inputSchema: {
        type: 'object',
        properties: {
          connectionId: { type: 'string', description: 'SSH connection ID' },
          command: { type: 'string', description: 'Command to execute on remote server' },
          cwd: { type: 'string', description: 'Working directory for command execution' }
        },
        required: ['connectionId', 'command']
      },
    },
  • src/index.ts:489-490 (registration)
    Dispatch/registration in the CallToolRequestSchema handler switch statement, routing to handleSSHExecute.
    case 'ssh_execute':
      return await this.handleSSHExecute(args);
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but lacks critical behavioral details: no mention of execution context (e.g., synchronous vs. asynchronous), error handling, output format, timeout behavior, or security implications. This is a significant gap for a command execution tool.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded with the core functionality.

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 of SSH command execution and the absence of both annotations and output schema, the description is insufficient. It doesn't address execution behavior, output handling, error conditions, or dependencies on other tools (like ssh_connect). For a potentially destructive operation with no structured safety hints, this leaves critical gaps.

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 all three parameters (connectionId, command, cwd) with clear descriptions. The description adds no additional parameter semantics beyond what's in the schema, maintaining the baseline score for high schema coverage.

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 ('Execute a command') and target ('on a remote SSH server'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like ssh_start_interactive_shell or ssh_send_input, which also involve command execution in different contexts.

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. There's no mention of prerequisites (like requiring an established SSH connection via ssh_connect), nor does it clarify when this is preferred over interactive shell tools or file operations.

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

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