search_devices
Search for smart home devices by name or status to find specific devices in your Domoticz system.
Instructions
Search for devices by name or data (status). Returns a list of matching devices.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:544-554 (handler)The main handler/implementation of the search_devices tool. It fetches all devices from Domoticz API, then filters locally by matching the query string against device name or data (case-insensitive). The function is decorated with @mcp.tool() which registers it as an MCP tool.
@mcp.tool() async def search_devices(query: str) -> str: """Search for devices by name or data (status). Returns a list of matching devices.""" async with create_client() as client: devices = await _get_cached_data(client, _device_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&filter=all&used=true") query_lower = query.lower() results = [] for dev in devices: if query_lower in dev.get("Name", "").lower() or query_lower in dev.get("Data", "").lower(): results.append(dev) return json.dumps({"status": "OK", "result": results}) - src/domoticz_mcp/server.py:544-544 (registration)The tool is registered with the MCP server via the @mcp.tool() decorator on line 544, immediately above the search_devices function definition.
@mcp.tool() - src/domoticz_mcp/server.py:346-352 (helper)The _get_cached_data helper function is used by search_devices to fetch and cache device data from the Domoticz API.
async def _get_cached_data(client: "httpx.AsyncClient", cache_obj: Dict[str, Any], api_url: str, key_path: str = "result") -> List[Dict[str, Any]]: now = time.time() if cache_obj["data"] is None or (now - cache_obj["timestamp"]) > CACHE_TTL: response = await _do_request(client, "GET", api_url) cache_obj["data"] = response.json().get(key_path, []) cache_obj["timestamp"] = now return cache_obj["data"] - src/domoticz_mcp/server.py:545-545 (schema)The input schema for search_devices: it accepts a single required 'query' parameter of type str. The output schema is a JSON string with status 'OK' and a 'result' array of matching device dictionaries.
async def search_devices(query: str) -> str: