get_user_variables
Retrieve all user variables defined in your Domoticz home automation system, enabling centralized access to custom data.
Instructions
Get all user variables.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:716-721 (handler)The `get_user_variables` async function is the MCP tool handler. It uses @mcp.tool() decorator to register as 'get_user_variables', takes no arguments, fetches cached user variables from the Domoticz API endpoint 'getuservariables', and returns a JSON response with status 'OK' and the result list.
@mcp.tool() async def get_user_variables() -> str: """Get all user variables.""" async with create_client() as client: vars = await _get_cached_data(client, _user_variable_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getuservariables") return json.dumps({"status": "OK", "result": vars}) - src/domoticz_mcp/server.py:716-716 (registration)The tool is registered via the @mcp.tool() decorator at line 716, which registers the function `get_user_variables` with the FastMCP server instance.
@mcp.tool() - src/domoticz_mcp/server.py:346-352 (helper)The `_get_cached_data` helper is used by the handler to fetch data from the Domoticz API with caching support. It checks the cache TTL (5 minutes) before making the actual HTTP request.
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:88-88 (helper)The `_user_variable_cache` dictionary is used for caching user variables data with a TTL of 300 seconds (5 minutes).
_user_variable_cache = {"data": None, "timestamp": 0} - src/domoticz_mcp/server.py:383-385 (helper)The `_resolve_user_variable_idx` helper resolves a user variable by name to its idx, used by other user variable tools (update/delete).
async def _resolve_user_variable_idx(client: "httpx.AsyncClient", idx: Optional[int] = None, name: Optional[str] = None) -> Optional[int]: """Resolve a user variable to its idx.""" return await _resolve_idx(client, idx, name, _user_variable_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getuservariables")