Skip to main content
Glama
bvisible

MCP SSH Manager

ssh_key_manage

Manage SSH host keys to verify server identities, accept new connections, remove outdated entries, and list current keys for secure authentication.

Instructions

Manage SSH host keys for security verification

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform
serverNoServer name (required for most actions)
autoAcceptNoAutomatically accept new keys (use with caution)

Implementation Reference

  • Registration of the 'ssh_key_manage' tool as part of the advanced tool group in the TOOL_GROUPS export.
    advanced: [
      'ssh_deploy',
      'ssh_execute_sudo',
      'ssh_alias',
      'ssh_command_alias',
      'ssh_hooks',
      'ssh_profile',
      'ssh_connection_status',
      'ssh_tunnel_create',
      'ssh_tunnel_list',
      'ssh_tunnel_close',
      'ssh_key_manage',
      'ssh_execute_group',
      'ssh_group_manage',
      'ssh_history'
    ]
  • Helper function to remove a host's SSH key from known_hosts file using ssh-keygen.
    export function removeHostKey(host, port = 22) {
      try {
        const hostEntry = port === 22 ? host : `[${host}]:${port}`;
    
        // Use ssh-keygen to remove the host
        execSync(`ssh-keygen -R "${hostEntry}"`, { stdio: 'ignore' });
    
        logger.info('Host key removed', { host, port });
        return true;
      } catch (error) {
        logger.error('Failed to remove host key', { host, port, error: error.message });
        throw new Error(`Failed to remove host key: ${error.message}`);
      }
    }
  • Helper function to add a new host key to known_hosts, fetching via ssh-keyscan if needed, with backup.
    export async function addHostKey(host, port = 22, keyData = null) {
      try {
        // Backup current known_hosts
        if (fs.existsSync(KNOWN_HOSTS_PATH)) {
          fs.copyFileSync(KNOWN_HOSTS_PATH, KNOWN_HOSTS_BACKUP);
        }
    
        // If no key data provided, fetch it
        if (!keyData) {
          const fingerprints = await getHostKeyFingerprint(host, port);
          if (fingerprints.length === 0) {
            throw new Error('No host keys found');
          }
          keyData = fingerprints.map(fp => fp.fullKey).join('\n');
        }
    
        // Ensure .ssh directory exists
        const sshDir = path.dirname(KNOWN_HOSTS_PATH);
        if (!fs.existsSync(sshDir)) {
          fs.mkdirSync(sshDir, { mode: 0o700, recursive: true });
        }
    
        // Append to known_hosts
        fs.appendFileSync(KNOWN_HOSTS_PATH, keyData + '\n');
    
        logger.info('Host key added', { host, port });
        return true;
      } catch (error) {
        logger.error('Failed to add host key', { host, port, error: error.message });
        throw new Error(`Failed to add host key: ${error.message}`);
      }
    }
  • Helper function to update host key by first removing the old entry and adding the new one.
    export async function updateHostKey(host, port = 22) {
      try {
        // Remove old key
        removeHostKey(host, port);
    
        // Add new key
        await addHostKey(host, port);
    
        logger.info('Host key updated', { host, port });
        return true;
      } catch (error) {
        logger.error('Failed to update host key', { host, port, error: error.message });
        throw new Error(`Failed to update host key: ${error.message}`);
      }
    }
  • Helper function to list all known hosts from known_hosts file with their key fingerprints and types.
    export function listKnownHosts() {
      if (!fs.existsSync(KNOWN_HOSTS_PATH)) {
        return [];
      }
    
      const content = fs.readFileSync(KNOWN_HOSTS_PATH, 'utf8');
      const lines = content.split('\n');
      const hosts = new Map();
    
      for (const line of lines) {
        if (line && !line.startsWith('#')) {
          const entry = parseKnownHostEntry(line);
          if (entry) {
            // Extract host and port
            let host = entry.host;
            let port = 22;
    
            if (host.startsWith('[')) {
              const match = host.match(/\[([^\]]+)\]:(\d+)/);
              if (match) {
                host = match[1];
                port = parseInt(match[2]);
              }
            }
    
            const keyData = Buffer.from(entry.key, 'base64');
            const hash = crypto.createHash('sha256').update(keyData).digest('base64');
    
            const hostKey = `${host}:${port}`;
            if (!hosts.has(hostKey)) {
              hosts.set(hostKey, {
                host,
                port,
                keys: []
              });
            }
    
            hosts.get(hostKey).keys.push({
              type: entry.keyType,
              fingerprint: `SHA256:${hash}`
            });
          }
        }
      }
    
      return Array.from(hosts.values());
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'security verification' and 'manage,' hinting at read/write operations, but lacks details on permissions required, side effects (e.g., key changes affecting connections), rate limits, or error handling. For a tool with potential security implications, this is a significant gap, though it doesn't contradict any annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. It earns its place by summarizing the tool's function, though it could be more structured with brief usage hints. No waste or redundancy is present.

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 key management with security implications, no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like safety, return values, or error cases, leaving gaps for an agent to understand how to invoke it correctly. More context is needed for a tool with multiple actions and potential side effects.

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 parameters (action, server, autoAccept) with descriptions and an enum for action. The description adds no additional meaning beyond implying key management actions, but it doesn't explain parameter interactions or usage nuances. Baseline 3 is appropriate as the schema handles 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 tool's purpose as 'Manage SSH host keys for security verification,' which specifies the verb ('manage'), resource ('SSH host keys'), and context ('security verification'). It distinguishes from most siblings that focus on backups, execution, sessions, or other SSH operations, though it doesn't explicitly differentiate from tools like 'ssh_alert_setup' or 'ssh_health_check' that might also relate to security.

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. It doesn't mention prerequisites, such as needing SSH access or server connectivity, or compare it to sibling tools like 'ssh_alert_setup' for monitoring or 'ssh_health_check' for diagnostics. Usage is implied only through the action parameter, with no explicit context or exclusions provided.

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

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