bulk_discover_and_map
Discover multiple devices via SSH and store them in the network site map database for homelab infrastructure management.
Instructions
Discover multiple devices via SSH and store them in the network site map database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| targets | Yes | Array of target device configurations |
Implementation Reference
- The handler function `handle_bulk_discover_and_map` that executes the tool logic. It creates a NetworkSiteMap instance and calls bulk_discover_and_store with the targets array from arguments, returning the result in MCP format.
async def handle_bulk_discover_and_map(arguments: dict[str, Any]) -> dict[str, Any]: """Handle bulk_discover_and_map tool.""" sitemap = NetworkSiteMap() result = await bulk_discover_and_store(sitemap, arguments["targets"]) return {"content": [{"type": "text", "text": result}]} - src/homelab_mcp/tool_handlers/__init__.py:84-84 (registration)Tool registration mapping 'bulk_discover_and_map' tool name to its handler function in the TOOL_HANDLERS dictionary.
"bulk_discover_and_map": handle_bulk_discover_and_map, - Schema definition for bulk_discover_and_map tool, specifying the input requires a 'targets' array containing device configuration objects with hostname, username, and optional password, key_path, and port fields.
"bulk_discover_and_map": { "description": "Discover multiple devices via SSH and store them in the network site map database", "inputSchema": { "type": "object", "properties": { "targets": { "type": "array", "description": "Array of target device configurations", "items": { "type": "object", "properties": { "hostname": {"type": "string"}, "username": {"type": "string"}, "password": {"type": "string"}, "key_path": {"type": "string"}, "port": {"type": "integer", "default": 22}, }, "required": ["hostname", "username"], }, } }, "required": ["targets"], }, }, - src/homelab_mcp/sitemap.py:335-367 (helper)The `bulk_discover_and_store` helper function that implements the core logic - iterates through multiple target devices, calls discover_and_store for each, collects results, and returns a consolidated JSON response with all discovery results.
async def bulk_discover_and_store(sitemap: NetworkSiteMap, targets: list[dict[str, Any]]) -> str: """Discover multiple devices and store them in the site map.""" results = [] for target in targets: try: result = await discover_and_store( sitemap, target["hostname"], target["username"], target.get("password"), target.get("key_path"), target.get("port", 22), ) results.append(json.loads(result)) except Exception as e: results.append( { "status": "error", "hostname": target.get("hostname", "unknown"), "error": str(e), } ) return json.dumps( { "status": "success", "total_targets": len(targets), "results": results, "completed_at": datetime.now().isoformat(), }, indent=2, )