search_devices
Search for smart home devices by name or status to find matching 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 | ||
| offset | No | ||
| limit | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:549-560 (handler)The search_devices tool handler: an async function decorated with @mcp.tool() that searches all devices by name or data (status) using a case-insensitive substring match, with pagination support.
@mcp.tool() async def search_devices(query: str, offset: int = 0, limit: int = 50) -> 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) paginated = _paginate(results, offset, limit) return json.dumps({"status": "OK", "result": paginated, "total_count": len(results), "offset": offset, "limit": limit}) - src/domoticz_mcp/server.py:549-549 (registration)The @mcp.tool() decorator on line 549 registers search_devices as an MCP tool with the FastMCP server instance.
@mcp.tool() - src/domoticz_mcp/server.py:550-550 (schema)The function signature defines the input schema: query (required string), offset (int, default 0), limit (int, default 50). The return type is str (JSON).
async def search_devices(query: str, offset: int = 0, limit: int = 50) -> str: - src/domoticz_mcp/server.py:396-398 (helper)The _paginate helper function used by search_devices to slice results by offset and limit.
def _paginate(data: list, offset: int, limit: int) -> list: """Paginate a list of results.""" return data[offset:offset + limit]