search_scripts
Search event scripts for a specific string to find code across Lua, dzVents, Python, and other languages.
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:485-512 (handler)The actual implementation of the search_scripts tool handler. It fetches the list of event scripts from Domoticz, then for each script loads its source code and searches for the query string (case-insensitive). Returns matching scripts with their idx, 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:485-486 (registration)The tool is registered via the @mcp.tool() decorator on the search_scripts async function, using the FastMCP instance 'mcp' created on line 70.
@mcp.tool() async def search_scripts(query: str) -> str: - src/domoticz_mcp/server.py:92-95 (helper)The _format_response helper used indirectly via json.dumps calls within search_scripts to format the JSON response.
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:97-100 (helper)The _error_response helper is a supporting utility for error formatting (not directly called by search_scripts but available in the same module).
def _error_response(message: str, status: str = "error") -> str: """Format an error response as a JSON string.""" return json.dumps({"status": status, "message": message})