Skip to main content
Glama
widjis
by widjis

ssh_connect

Establish SSH connections to remote servers using password or private key authentication for executing commands and transferring files.

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 that implements the ssh_connect tool logic. It validates parameters using ConnectSSHSchema, creates a NodeSSH connection, handles authentication with password or private key, adds to connection pool, and returns 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 defining the input parameters for the ssh_connect tool, used for validation in the handler.
    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-254 (registration)
    Registration of the ssh_connect tool in the listTools response, including name, description, and JSON input 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 to ssh_connect handler in the CallToolRequestSchema switch statement.
    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 the full burden of behavioral disclosure. 'Connect to an SSH server' implies establishing a network connection but reveals nothing about authentication requirements, timeout behavior, connection persistence, error handling, or what happens after connection. For a security-sensitive tool with 7 parameters, this is inadequate.

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 maximally concise with a single clear sentence that states the core purpose. There's no wasted language or unnecessary elaboration, making it easy to parse and understand at a glance.

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 complex SSH connection tool with 7 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what happens after connection, how to manage the connection, what errors might occur, or how this differs from sibling connection tools. The agent lacks critical context for proper tool selection and invocation.

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 all 7 parameters well-documented in the schema itself. The description adds no additional parameter information beyond what's already in the structured schema, so it meets the baseline for high schema coverage without adding value.

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') and target ('SSH server'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'ssh_connect_with_credential', which appears to serve a similar purpose with different authentication methods.

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' and 'ssh_disconnect', there's no indication of when this specific connection method is preferred or what prerequisites exist for successful connection.

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

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