delete_user_variable
Delete a user variable from Domoticz using its IDX or name. Removes the specified variable from the system.
Instructions
Delete a user variable by IDX or Name.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| idx | No | ||
| name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:749-760 (handler)The 'delete_user_variable' tool handler function decorated with @mcp.tool(). It accepts an optional idx or name, resolves the user variable index, calls the Domoticz API to delete it, invalidates the cache, and returns the response.
@mcp.tool() async def delete_user_variable(idx: int | None = None, name: str | None = None) -> str: """Delete a user variable by IDX or Name.""" if idx is None and name is None: return '{"status": "error", "message": "Must provide either idx or name"}' async with create_client() as client: resolved_idx = await _resolve_user_variable_idx(client, idx, name) if resolved_idx is None: return '{"status": "error", "message": "User variable not found"}' response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=deleteuservariable&idx={resolved_idx}") _user_variable_cache["timestamp"] = 0 # Invalidate cache return response.text - src/domoticz_mcp/server.py:749-749 (registration)The @mcp.tool() decorator registers 'delete_user_variable' as an MCP tool with the FastMCP instance.
@mcp.tool() - src/domoticz_mcp/server.py:383-385 (helper)Helper function '_resolve_user_variable_idx' resolves a user variable name to its idx by fetching cached user variables data and matching by name (case-insensitive).
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") - tests/test_server.py:210-218 (registration)Test that verifies the delete_user_variable tool works, including resolution by name and the API call with the correct idx.
# delete_user_variable # Mock resolution first respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=getuservariables").mock( return_value=Response(200, json={"result": [{"idx": "5", "Name": "DeleteMe"}]}) ) respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=deleteuservariable&idx=5").mock( return_value=Response(200, json={"status": "OK"}) ) await delete_user_variable(name="DeleteMe")