ssh_list_hosts
Retrieve a list of configured SSH hosts to manage server access and view available infrastructure for policy-driven operations.
Instructions
List configured hosts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_ssh/mcp_server.py:862-871 (handler)The ssh_list_hosts tool handler function decorated with @mcp.tool(). It calls config.list_hosts() and returns the list of host aliases as a dict with key 'hosts', or an error string on failure.
@mcp.tool() def ssh_list_hosts() -> ToolResult: """List configured hosts.""" try: hosts = config.list_hosts() return {"hosts": hosts} except Exception as e: error_str = str(e) log_json({"level": "error", "msg": "list_hosts_exception", "error": error_str}) return f"Error: {sanitize_error(error_str)}" - src/mcp_ssh/mcp_server.py:862-864 (registration)The tool is registered with MCP via the @mcp.tool() decorator on the ssh_list_hosts function at line 862.
@mcp.tool() def ssh_list_hosts() -> ToolResult: """List configured hosts.""" - src/mcp_ssh/config.py:539-547 (helper)The Config.list_hosts() helper method that reads host aliases from the servers.yml configuration and returns them as a list of strings.
def list_hosts(self) -> list: """List all host aliases.""" servers = self._data.get("servers", {}).get("hosts", []) result = [] for h in servers: alias = str(h.get("alias", "")).strip() if alias: result.append(alias) return result - src/mcp_ssh/mcp_server.py:862-864 (schema)The function signature uses the ToolResult type alias (dict[str, Any] | str) defined at line 22, serving as the schema for return types - dict for success, str for errors.
@mcp.tool() def ssh_list_hosts() -> ToolResult: """List configured hosts."""