Skip to main content
Glama

ssh_open_session

Establish a secure SSH connection to remote servers using password, key, or agent authentication for executing commands and managing files.

Instructions

Opens a new SSH session with authentication

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesSSH server hostname or IP
usernameYesSSH username
portNoSSH port (default: 22)
authNoAuthentication method (default: auto)
passwordNoPassword for authentication
privateKeyNoInline private key content
privateKeyPathNoPath to private key file
passphraseNoPassphrase for encrypted private key
useAgentNoUse SSH agent for authentication
readyTimeoutMsNoConnection timeout in milliseconds (default: 20000)
ttlMsNoSession TTL in milliseconds (default: 900000)

Implementation Reference

  • The `openSession` method in `SessionManager` handles the actual SSH connection logic, including authentication, SFTP setup, and storing the active session in a map.
    async openSession(params: ConnectionParams): Promise<SessionResult> {
      logger.debug('Opening SSH session', { host: params.host, username: params.username });
    
      const sessionId = this.generateSessionId();
      const now = Date.now();
      const ttl = params.ttlMs || 900000; // 15 minutes default
    
      try {
        // Clean up old sessions if we're at the limit
        if (this.sessions.size >= this.maxSessions) {
          this.evictOldestSession();
        }
    
        const ssh = new NodeSSH();
        const authConfig = await this.buildAuthConfig(params);
    
        const connectConfig = {
          host: params.host,
          username: params.username,
          port: params.port || 22,
          readyTimeout: params.readyTimeoutMs || 20000,
          hostVerifyMethod: params.strictHostKeyChecking
            ? undefined  // Use default strict checking
            : () => true, // Relaxed host key checking
          knownHosts: params.knownHostsPath,
          ...authConfig
        };
    
        logger.debug('Connecting to SSH server');
        await ssh.connect(connectConfig);
    
        // Initialize SFTP client
        const sftp = new SftpClient();
        await sftp.connect({
          host: params.host,
          username: params.username,
          port: params.port || 22,
          readyTimeout: params.readyTimeoutMs || 20000,
          ...authConfig
        });
    
        const sessionInfo: SessionInfo = {
          sessionId,
          host: params.host,
          username: params.username,
          port: params.port || 22,
          createdAt: now,
          expiresAt: now + ttl,
          lastUsed: now
        };
    
        const session: SSHSession = {
          ssh,
          sftp,
          info: sessionInfo,
          connectionParams: params // Store for reconnect
        };
    
        this.sessions.set(sessionId, session);
    
        logger.info('SSH session opened successfully', {
          sessionId,
          host: params.host,
          username: params.username,
          expiresInMs: ttl
        });
    
        return {
          sessionId,
          host: params.host,
          username: params.username,
          expiresInMs: ttl
        };
    
      } catch (error) {
        logger.error('Failed to open SSH session', { error, host: params.host });
    
        if (error instanceof Error) {
          if (error.message.includes('authentication')) {
            throw createAuthError(
              'SSH authentication failed',
              'Check your username, password, or SSH key configuration'
            );
          } else if (error.message.includes('timeout') || error.message.includes('ETIMEDOUT')) {
            throw createTimeoutError(
              'SSH connection timeout',
              'Check if the host is reachable and the SSH service is running'
            );
          } else if (error.message.includes('ECONNREFUSED')) {
            throw createConnectionError(
              'SSH connection refused',
              'Check if the SSH service is running on the target port'
            );
          }
        }
    
        throw createConnectionError(
          `Failed to establish SSH connection: ${error instanceof Error ? error.message : String(error)}`,
          'Verify the host, port, and network connectivity'
        );
      }
    }
  • src/mcp.ts:388-393 (registration)
    Registration of the 'ssh_open_session' tool handler in the MCP server request handler switch block.
    case 'ssh_open_session': {
      const params = ConnectionParamsSchema.parse(args);
      const result = await sessionManager.openSession(params);
      logger.info('SSH session opened', { sessionId: result.sessionId, host: redactSensitiveData(params.host) });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
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. While it mentions authentication, it doesn't describe what happens after session opening (e.g., does it return a session ID, what operations can follow, whether sessions persist, what happens on timeout). For a session management tool with no annotation coverage, this leaves significant behavioral gaps.

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 communicates the core purpose without any wasted words. It's appropriately sized and front-loaded with the essential information.

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 session management tool with 11 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns (session ID? success status?), how sessions are managed, what operations are possible after opening, or how this integrates with other SSH tools. The context signals indicate significant complexity that the description doesn't address.

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 11 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema. This meets the baseline expectation when schema coverage is complete.

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 ('Opens a new SSH session') and the resource ('with authentication'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from sibling SSH tools like ssh_close_session or ssh_list_sessions, which would be needed for a perfect score.

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 multiple SSH-related sibling tools (ssh_close_session, ssh_list_sessions, ssh_ping, ssh_resolve_host), there's no indication of when this specific session-opening tool is appropriate versus other SSH 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/oaslananka/mcp-ssh-tool'

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