Skip to main content
Glama

ssh_connect

Establish SSH connections to VPS servers using password authentication or private keys for remote management and initialization tasks.

Instructions

Connect to a VPS via SSH using password or private key

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesVPS IP address or hostname
portNoSSH port (default: 22)
usernameYesSSH username
passwordNoSSH password (optional)
privateKeyPathNoPrivate key file path (optional)
passphraseNoPrivate key passphrase (optional)

Implementation Reference

  • Main handler function for the 'ssh_connect' tool. Parses input arguments with SSHConfigSchema, instantiates SSHService with the config, calls connect(), initializes other services if successful, and returns a success message or throws on failure.
    private async handleSSHConnect(
      args: unknown
    ): Promise<{ content: Array<{ type: 'text'; text: string }> }> {
      const parsedConfig = SSHConfigSchema.parse(args);
      const config: SSHConfig = {
        host: parsedConfig.host,
        port: parsedConfig.port,
        username: parsedConfig.username,
        password: parsedConfig.password || undefined,
        privateKeyPath: parsedConfig.privateKeyPath || undefined,
        passphrase: parsedConfig.passphrase || undefined,
      };
    
      this.sshService = new SSHService(config);
      const connected = await this.sshService.connect();
    
      if (connected) {
        // Initialize other services
        this.vpsInitializer = new VPSInitializer(this.sshService);
        this.nginxManager = new NginxManager(this.sshService);
        this.githubCICD = new GitHubCICD(this.sshService);
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully connected to ${config.host} as ${config.username}`,
            },
          ],
        };
      } else {
        throw new Error('Failed to establish SSH connection');
      }
    }
  • Zod schema used for input validation in the ssh_connect handler.
    const SSHConfigSchema = z.object({
      host: z.string().describe('The IP address or hostname of the VPS'),
      port: z.number().optional().default(22).describe('SSH port (default: 22)'),
      username: z.string().describe('SSH username'),
      password: z.string().optional().describe('SSH password (if not using key)'),
      privateKeyPath: z.string().optional().describe('Path to private key file'),
      passphrase: z.string().optional().describe('Passphrase for private key'),
    });
  • Tool registration in the MCP server's listTools handler, defining name, description, and input schema for ssh_connect.
    {
      name: 'ssh_connect',
      description: 'Connect to a VPS via SSH using password or private key',
      inputSchema: {
        type: 'object',
        properties: {
          host: { type: 'string', description: 'VPS IP address or hostname' },
          port: { type: 'number', description: 'SSH port (default: 22)' },
          username: { type: 'string', description: 'SSH username' },
          password: { type: 'string', description: 'SSH password (optional)' },
          privateKeyPath: { type: 'string', description: 'Private key file path (optional)' },
          passphrase: { type: 'string', description: 'Private key passphrase (optional)' },
        },
        required: ['host', 'username'],
      },
    },
  • Supporting method in SSHService class that performs the actual SSH connection using the node-ssh library, supporting both password and private key (with optional passphrase) authentication.
    async connect(): Promise<boolean> {
      try {
        const connectionConfig: Parameters<NodeSSH['connect']>[0] = {
          host: this.config.host,
          port: this.config.port || 22,
          username: this.config.username,
        };
    
        // Handle authentication methods
        if (this.config.privateKeyPath) {
          logger.info('Authenticating with private key', {
            keyPath: this.config.privateKeyPath,
          });
          connectionConfig.privateKey = readFileSync(this.config.privateKeyPath, 'utf8');
          if (this.config.passphrase) {
            connectionConfig.passphrase = this.config.passphrase;
          }
        } else if (this.config.password) {
          logger.info('Authenticating with password');
          connectionConfig.password = this.config.password;
        } else {
          throw new Error('Either password or privateKeyPath must be provided');
        }
    
        await this.ssh.connect(connectionConfig);
        this.isConnected = true;
        logger.info('Successfully connected to SSH server', {
          host: this.config.host,
          username: this.config.username,
        });
        return true;
      } catch (error) {
        logger.error('Failed to connect to SSH server', {
          error: error instanceof Error ? error.message : 'Unknown error',
          host: this.config.host,
        });
        this.isConnected = false;
        return false;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool establishes an SSH connection but lacks details on what happens after connection (e.g., does it open a session, return a handle, or just verify connectivity?), error handling, timeout behavior, or security implications. This is inadequate for a tool that involves network operations and authentication.

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 and authentication options without any fluff. It's front-loaded and appropriately sized for its function, with every word earning its place.

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 connections (involving network, authentication, and potential session management), no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (e.g., connection status, session ID), error cases, or behavioral traits like timeouts, leaving significant gaps for an agent to use it correctly.

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%, with clear documentation for all 6 parameters (e.g., host as 'VPS IP address or hostname', port with default 22). The description adds no additional parameter semantics beyond what the schema provides, such as explaining interactions between password and privateKeyPath. Baseline 3 is appropriate since 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 ('Connect to a VPS via SSH') and the authentication methods ('using password or private key'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'execute_command' (which might be for commands after connection) or 'vps_initialize' (which might be for initial setup).

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 like 'execute_command' (for running commands on an SSH connection) or 'vps_initialize' (for initial VPS setup). It mentions authentication methods but doesn't specify prerequisites or exclusions, leaving usage context implied at best.

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/oxy-Op/DevPilot'

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