Skip to main content
Glama

ssh_connect

Establish secure SSH connections to remote servers using password or key authentication for remote operations and management.

Instructions

Connect to an SSH server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesSSH server hostname or IP address
portNoSSH port number
usernameYesSSH username
passwordNoSSH password (if not using key)
privateKeyPathNoPath to private key file
passphraseNoPassphrase for private key
connectionIdYesUnique identifier for this connection

Implementation Reference

  • The handler function for the 'ssh_connect' tool. It validates input parameters using ConnectSSHSchema, creates a new NodeSSH instance, configures connection with host, port, username, and either password or private key, connects to the SSH server, stores the connection in connectionPool and connectionContexts maps, and returns a success message.
    private async handleSSHConnect(args: unknown) {
      const params = ConnectSSHSchema.parse(args);
      
      if (connectionPool.has(params.connectionId)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Connection ID '${params.connectionId}' already exists`
        );
      }
    
      const ssh = new NodeSSH();
      
      try {
        const connectConfig: any = {
          host: params.host,
          port: params.port,
          username: params.username,
        };
    
        if (params.privateKeyPath) {
          const privateKey = await fs.readFile(params.privateKeyPath, 'utf8');
          connectConfig.privateKey = privateKey;
          if (params.passphrase) {
            connectConfig.passphrase = params.passphrase;
          }
        } else if (params.password) {
          connectConfig.password = params.password;
        } else {
          throw new McpError(
            ErrorCode.InvalidParams,
            'Either password or privateKeyPath must be provided'
          );
        }
    
        await ssh.connect(connectConfig);
        connectionPool.set(params.connectionId, ssh);
        
        // Initialize connection context
        connectionContexts.set(params.connectionId, {
          ssh,
          currentWorkingDirectory: undefined,
          defaultWorkingDirectory: undefined
        });
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully connected to ${params.host}:${params.port} as ${params.username} (Connection ID: ${params.connectionId})`,
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `SSH connection failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Zod schema used for input validation in the ssh_connect handler, defining parameters like host, port, username, optional password or private key details, and required connectionId.
    const ConnectSSHSchema = z.object({
      host: z.string().describe('SSH server hostname or IP address'),
      port: z.number().default(22).describe('SSH port number'),
      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'),
      connectionId: z.string().describe('Unique identifier for this connection')
    });
  • src/index.ts:239-253 (registration)
    Registration of the 'ssh_connect' tool in the ListTools response, including name, description, and JSON input schema matching the Zod schema.
    name: 'ssh_connect',
    description: 'Connect to an SSH server',
    inputSchema: {
      type: 'object',
      properties: {
        host: { type: 'string', description: 'SSH server hostname or IP address' },
        port: { type: 'number', default: 22, description: 'SSH port number' },
        username: { type: 'string', description: 'SSH username' },
        password: { type: 'string', description: 'SSH password (if not using key)' },
        privateKeyPath: { type: 'string', description: 'Path to private key file' },
        passphrase: { type: 'string', description: 'Passphrase for private key' },
        connectionId: { type: 'string', description: 'Unique identifier for this connection' }
      },
      required: ['host', 'username', 'connectionId']
    },
  • src/index.ts:485-486 (registration)
    Dispatch case in the CallToolRequest handler switch statement that routes 'ssh_connect' calls to the handleSSHConnect method.
    case 'ssh_connect':
      return await this.handleSSHConnect(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. 'Connect to an SSH server' implies establishing a persistent connection, but doesn't specify what happens after connection (e.g., whether it returns a connection handle, establishes a session, or just verifies connectivity). It doesn't mention authentication requirements, timeout behavior, error conditions, or what the connectionId parameter represents in practice.

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, clear sentence with zero wasted words. It's appropriately sized for a tool with comprehensive schema documentation. Every word earns its place by stating the core purpose without unnecessary elaboration.

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?

For a connection tool with 7 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what happens after connection establishment, what the connectionId is used for, or how this tool relates to other SSH operations. The agent would need to guess about the tool's behavior and output format based solely on the schema.

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 all parameters are documented in the schema. The description adds no additional parameter information beyond the basic purpose. It doesn't explain relationships between parameters (e.g., that password and privateKeyPath are alternative authentication methods) or provide usage examples. The baseline of 3 is appropriate when 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 'Connect to an SSH server' clearly states the action (connect) and target resource (SSH server). It distinguishes from siblings like ssh_execute or ssh_copy_file by focusing on establishing a connection rather than performing operations. However, it doesn't specify how it differs from ssh_connect_with_credential, which appears to be a similar connection tool.

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. With siblings like ssh_connect_with_credential (presumably for credential-based connections) and ssh_start_interactive_shell (for interactive sessions), there's no indication of when this basic connection tool is appropriate versus those alternatives. No prerequisites or exclusions are mentioned.

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