Skip to main content
Glama
adrighem

Domoticz MCP Server

by adrighem

get_connectivity_report

Retrieve a list of smart home devices that have not reported in a given number of hours, helping identify unresponsive or disconnected equipment.

Instructions

Get a list of devices that haven't checked in/updated within the specified timeframe.

Args: hours: Number of hours threshold for considering a device 'unresponsive' (default: 24).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hoursNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler for the 'get_connectivity_report' tool. It is registered as an MCP tool via @mcp.tool() decorator. Fetches all devices, filters those whose LastUpdate is older than the specified hours threshold, and returns a sorted JSON list of unresponsive devices.
    @mcp.tool()
    async def get_connectivity_report(hours: int = 24) -> str:
        """Get a list of devices that haven't checked in/updated within the specified timeframe.
        
        Args:
            hours: Number of hours threshold for considering a device 'unresponsive' (default: 24).
        """
        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")
            now = datetime.now()
            threshold_time = now - timedelta(hours=hours)
            results = []
            
            for dev in devices:
                last_update_str = dev.get("LastUpdate")
                if not last_update_str:
                    continue
                    
                try:
                    # Domoticz format: YYYY-MM-DD HH:MM:SS
                    last_update = datetime.strptime(last_update_str, "%Y-%m-%d %H:%M:%S")
                    if last_update < threshold_time:
                        results.append({
                            "idx": dev.get("idx"),
                            "Name": dev.get("Name"),
                            "LastUpdate": last_update_str,
                            "HardwareName": dev.get("HardwareName"),
                            "Type": dev.get("Type"),
                            "Data": dev.get("Data")
                        })
                except ValueError:
                    continue
                    
            # Sort by oldest update first
            results.sort(key=lambda x: x["LastUpdate"])
            return json.dumps({"status": "OK", "result": results})
  • Registration of the tool via the @mcp.tool() decorator on line 1129, which registers it with the FastMCP instance named 'Domoticz'.
    @mcp.tool()
    async def get_connectivity_report(hours: int = 24) -> str:
  • The function signature and docstring define the schema: takes an optional 'hours' parameter (int, default 24) and returns a JSON string.
    async def get_connectivity_report(hours: int = 24) -> str:
        """Get a list of devices that haven't checked in/updated within the specified timeframe.
        
        Args:
            hours: Number of hours threshold for considering a device 'unresponsive' (default: 24).
  • The _get_cached_data helper function used internally to fetch and cache device data from the Domoticz 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"]
  • Test for get_connectivity_report, verifying it correctly identifies devices not updated within 24 hours.
    @pytest.mark.asyncio
    @respx.mock
    async def test_get_connectivity_report():
        from domoticz_mcp.server import get_connectivity_report
        from datetime import datetime, timedelta
        
        old_time = (datetime.now() - timedelta(hours=48)).strftime("%Y-%m-%d %H:%M:%S")
        new_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        
        mock_data = {
            "result": [
                {"idx": "1", "Name": "Dead Sensor", "LastUpdate": old_time},
                {"idx": "2", "Name": "Live Sensor", "LastUpdate": new_time}
            ]
        }
        respx.get(f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&filter=all&used=true").mock(
            return_value=Response(200, json=mock_data)
        )
        
        response = await get_connectivity_report(hours=24)
        data = json.loads(response)
        assert len(data["result"]) == 1
        assert data["result"][0]["Name"] == "Dead Sensor"
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the burden of behavioral disclosure. It indicates a read operation (get) but does not explicitly confirm read-only nature, error conditions, or rate limits. The existence of an output schema partly compensates, but the description lacks depth.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with one sentence for purpose and a separate args section. It is front-loaded but could be more structured (e.g., using a list for args). However, it is efficient and contains no fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple one-parameter tool with an output schema, the description adequately covers the core functionality and parameter meaning. It lacks examples or prerequisites, but the context is relatively complete given the tool's simplicity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description includes an args section that explains the parameter 'hours' as 'Number of hours threshold for considering a device unresponsive', adding meaning beyond the schema's minimal title. The schema itself has 0% description coverage, so the description effectively compensates.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool returns devices that haven't checked in within a timeframe, using a specific verb-resource pairing. This distinguishes it from sibling tools like get_all_devices (all devices) and get_device (single device).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives, such as get_all_devices or get_device_history. It simply describes the tool's function without contextualizing its appropriate use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adrighem/domoticz-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server