call_domoticz_api
Execute a generic Domoticz API call by specifying the action parameter and any additional query parameters to control or retrieve smart home data.
Instructions
Call a generic Domoticz API endpoint.
Args: param: The 'param' parameter of the JSON API (e.g. 'checkforupdate'). kwargs: Dictionary of additional query parameters.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| param | Yes | ||
| kwargs | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:887-901 (handler)The handler for the 'call_domoticz_api' MCP tool. It takes a 'param' string (the Domoticz JSON API param, e.g. 'checkforupdate') and a 'kwargs' dict of additional query parameters, constructs the URL, and calls the Domoticz API via GET request using the custom DomoticzClient.
@mcp.tool() async def call_domoticz_api(param: str, kwargs: dict) -> str: """Call a generic Domoticz API endpoint. Args: param: The 'param' parameter of the JSON API (e.g. 'checkforupdate'). kwargs: Dictionary of additional query parameters. """ async with create_client() as client: url_params = urllib.parse.urlencode(kwargs) url = f"{DOMOTICZ_API_URL}?type=command¶m={param}" if url_params: url += f"&{url_params}" response = await _do_request(client, "GET", url) return response.text - src/domoticz_mcp/server.py:887-887 (registration)The tool is registered as an MCP tool via the @mcp.tool() decorator on line 887, making it available in the tool registry.
@mcp.tool() - src/domoticz_mcp/server.py:888-894 (schema)The input schema for the tool: 'param' (str, required) and 'kwargs' (dict, required). The docstring explains the purpose: to call a generic Domoticz API endpoint.
async def call_domoticz_api(param: str, kwargs: dict) -> str: """Call a generic Domoticz API endpoint. Args: param: The 'param' parameter of the JSON API (e.g. 'checkforupdate'). kwargs: Dictionary of additional query parameters. """ - src/domoticz_mcp/server.py:298-325 (helper)The DomoticzClient helper (context manager) used by the handler to make authenticated HTTP requests to the Domoticz API.
class DomoticzClient: def __init__(self, own_client: bool = False): self._own_client = own_client if own_client or _global_http_client is None: self.client: httpx.AsyncClient = httpx.AsyncClient(timeout=30.0) self._owns_client = True else: self.client = _global_http_client self._owns_client = False async def __aenter__(self) -> "httpx.AsyncClient": oauth_token = None if DOMOTICZ_CLIENT_ID: oauth_token = await _fetch_oauth_token() if oauth_token: self.client.headers["Authorization"] = f"Bearer {oauth_token}" elif DOMOTICZ_USERNAME and DOMOTICZ_PASSWORD: self.client.auth = (DOMOTICZ_USERNAME, DOMOTICZ_PASSWORD) else: self.client.headers.pop("Authorization", None) self.client.auth = None return self.client async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: if self._owns_client: - tests/test_server.py:683-684 (registration)Test file imports and tests the 'call_domoticz_api' function, providing a test case with 'testparam' and kwargs {'myarg': '1'}.
async def test_new_tools(): from domoticz_mcp.server import call_domoticz_api, check_for_updates, restart_system, get_camera_snapshot