search_scripts
Search across Domoticz event scripts (Lua, dzVents, Python) for a given string to find relevant code sections.
Instructions
Search for a specific string inside event scripts (Lua, dzVents, Python, etc.).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:481-508 (handler)The `search_scripts` async function is the handler for the tool. It fetches the list of event scripts via Domoticz API, loads each script's source code, and searches case-insensitively for the query string within the script source. Returns matching scripts with name, interpreter, type, and status.
@mcp.tool() async def search_scripts(query: str) -> str: """Search for a specific string inside event scripts (Lua, dzVents, Python, etc.).""" async with create_client() as client: # 1. Get the list of scripts list_resp = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=events&evparam=list") scripts = list_resp.json().get("result", []) matches = [] query_lower = query.lower() # 2. For each script, load its source and search for script in scripts: script_id = script.get("idx") load_resp = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=events&evparam=load&event={script_id}") script_data = load_resp.json().get("result", [{}])[0] source_code = script_data.get("xml", "") or script_data.get("source", "") if query_lower in source_code.lower(): matches.append({ "idx": script_id, "Name": script.get("name"), "Interpreter": script.get("interpreter"), "Type": script.get("eventtype"), "Status": "Enabled" if script.get("eventstatus") == "1" else "Disabled" }) return json.dumps({"status": "OK", "result": matches, "count": len(scripts)}) - src/domoticz_mcp/server.py:481-481 (registration)The `@mcp.tool()` decorator on the `search_scripts` function registers it as a tool with the FastMCP server, making it available via the MCP protocol.
@mcp.tool() - src/domoticz_mcp/server.py:92-94 (helper)The `_format_response` helper is used by many tool handlers (though search_scripts uses json.dumps directly) to format dicts as JSON strings.
def _format_response(data: Dict[str, Any]) -> str: """Format a dictionary as a JSON string response.""" return json.dumps(data) - src/domoticz_mcp/server.py:329-336 (helper)The `create_client` helper function is used by search_scripts to create an HTTP client for Domoticz API calls.
def create_client(own_client: bool = False) -> DomoticzClient: """Create a DomoticzClient instance. Args: own_client: If True, creates a dedicated client that will be closed on exit. If False (default), uses a shared client for connection pooling. """ return DomoticzClient(own_client=own_client)