get_all_devices
Retrieve all devices and their current states from Domoticz. Use optional offset and limit to paginate results.
Instructions
Get all devices and their current states from Domoticz.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| offset | No | ||
| limit | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:541-547 (handler)The main handler function for the 'get_all_devices' tool. It is decorated with @mcp.tool(), fetches all devices from the Domoticz API with caching, supports pagination via offset/limit, and returns a JSON response with status, result, total_count, offset, and limit.
@mcp.tool() async def get_all_devices(offset: int = 0, limit: int = 50) -> str: """Get all devices and their current states from Domoticz.""" 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&order=Name") paginated = _paginate(devices, offset, limit) return json.dumps({"status": "OK", "result": paginated, "total_count": len(devices), "offset": offset, "limit": limit}) - src/domoticz_mcp/server.py:541-541 (registration)The @mcp.tool() decorator on line 541 registers get_all_devices as an MCP tool with the FastMCP server instance 'mcp'.
@mcp.tool() - src/domoticz_mcp/server.py:346-353 (helper)The _get_cached_data helper function is used by get_all_devices to fetch and cache device data from the Domoticz JSON 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:396-398 (helper)The _paginate helper function is used by get_all_devices to slice the results list based on offset and limit parameters.
def _paginate(data: list, offset: int, limit: int) -> list: """Paginate a list of results.""" return data[offset:offset + limit] - src/domoticz_mcp/server.py:542-542 (schema)The function signature defines the input schema: offset (int, default 0) and limit (int, default 50). The output schema is implicitly JSON with fields: status, result, total_count, offset, limit.
async def get_all_devices(offset: int = 0, limit: int = 50) -> str: