Skip to main content
Glama
adrighem

Domoticz MCP Server

by adrighem

toggle_switch

Toggle a switch or light in Domoticz by specifying its IDX or name. Use IDX for precise control.

Instructions

Toggle a switch or light by IDX or Name. Prefer using IDX for precision.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idxNo
nameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the toggle_switch MCP tool. It toggles a switch/light by idx or name by making a GET request to the Domoticz API with the 'Toggle' switch command.
    @mcp.tool()
    async def toggle_switch(idx: int | None = None, name: str | None = None) -> str:
        """Toggle a switch or light by IDX or Name. Prefer using IDX for precision."""
        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_device_idx(client, idx, name)
            if resolved_idx is None:
                return '{"status": "error", "message": "Device not found"}'
            response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=switchlight&idx={resolved_idx}&switchcmd=Toggle")
            return response.text
  • The @mcp.tool() decorator registers toggle_switch as an MCP tool on the FastMCP instance.
    @mcp.tool()
    async def toggle_switch(idx: int | None = None, name: str | None = None) -> str:
        """Toggle a switch or light by IDX or Name. Prefer using IDX for precision."""
        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_device_idx(client, idx, name)
            if resolved_idx is None:
                return '{"status": "error", "message": "Device not found"}'
            response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=switchlight&idx={resolved_idx}&switchcmd=Toggle")
            return response.text
  • Input schema: accepts optional idx (int) or name (str). Returns a JSON string response.
    @mcp.tool()
    async def toggle_switch(idx: int | None = None, name: str | None = None) -> str:
        """Toggle a switch or light by IDX or Name. Prefer using IDX for precision."""
        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_device_idx(client, idx, name)
            if resolved_idx is None:
                return '{"status": "error", "message": "Device not found"}'
            response = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=switchlight&idx={resolved_idx}&switchcmd=Toggle")
            return response.text
Behavior2/5

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

With no annotations, the description carries full burden. Only says 'Toggle', which implies state flipping, but lacks details on side effects, authentication needs, or behavior when both parameters are provided or both are null.

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

Conciseness5/5

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

Single sentence, no wasted words. Efficiently conveys action, resource, and a usage preference.

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

Completeness3/5

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

Adequate for a simple toggle tool with output schema present, but lacks details on what happens if the device is not togglable, error cases, or return value format. With no annotations, more context would be beneficial.

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

Parameters3/5

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

Schema has 0% coverage, so description adds value by naming parameters and preferring IDX. However, it does not explain mutual exclusivity or behavior when both are defined/null. Baseline is low due to coverage.

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?

Clearly states the action ('Toggle') and the resource ('switch or light'), and specifies two identification methods (IDX or Name). Distinguishes from siblings like 'set_switch_state' by indicating a toggle action.

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

Usage Guidelines3/5

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

Provides a preference for using IDX for precision, which guides parameter choice. However, it does not explain when to use this tool versus alternatives (e.g., when to toggle vs set a specific state), nor does it mention when not to use it.

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