Skip to main content
Glama

listKnownHosts

Retrieve a consolidated list of SSH hosts from configuration and known hosts files to manage remote connections.

Instructions

Returns a consolidated list of all known SSH hosts, prioritizing ~/.ssh/config entries first, then additional hosts from ~/.ssh/known_hosts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'listKnownHosts' tool. It calls the config parser's getAllKnownHosts method to retrieve the list of known SSH hosts.
    async listKnownHosts(): Promise<SSHHostInfo[]> {
      return await this.configParser.getAllKnownHosts();
    }
  • Interface defining the structure of SSHHostInfo, which is the return type of the listKnownHosts tool.
    export interface SSHHostInfo {
      hostname: string;
      alias?: string;
      user?: string;
      port?: number;
      identityFile?: string;
      [key: string]: any; // For other configuration options
    }
  • Helper method in SSHConfigParser that implements the core logic: parses ~/.ssh/config for hosts and ~/.ssh/known_hosts for additional hostnames, combining them into SSHHostInfo array.
    async getAllKnownHosts(): Promise<SSHHostInfo[]> {
      const configHosts = await this.parseConfig();
      const knownHostnames = await this.parseKnownHosts();
    
      // Add hosts from known_hosts that aren't in the config
      for (const hostname of knownHostnames) {
        if (!configHosts.some(host => 
            host.hostname === hostname || 
            host.alias === hostname)) {
          configHosts.push({
            hostname: hostname
          });
        }
      }
    
      return configHosts;
    }

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

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