Skip to content

Commit f952fe4

Browse files
julienldclaude
andauthored
fix: add error handling to ha_deep_search (#226)
Wrap smart_tools.deep_search() call in try/except to handle intermittent execution failures. Returns structured error response with exception details and helpful suggestions when the deep search fails. Closes #209 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 634d142 commit f952fe4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/ha_mcp/tools/tools_search.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,21 @@ async def ha_deep_search(
347347
"""
348348
# Parse search_types to handle JSON string input from MCP clients
349349
parsed_search_types = parse_string_list_param(search_types, "search_types")
350-
result = await smart_tools.deep_search(query, parsed_search_types, limit)
351-
return cast(dict[str, Any], result)
350+
try:
351+
result = await smart_tools.deep_search(query, parsed_search_types, limit)
352+
return cast(dict[str, Any], result)
353+
except Exception as e:
354+
return {
355+
"success": False,
356+
"error": str(e),
357+
"query": query,
358+
"search_types": parsed_search_types,
359+
"suggestions": [
360+
"Check Home Assistant connection",
361+
"Verify automation/script/helper configurations exist",
362+
"Try a simpler search query",
363+
],
364+
}
352365

353366
@mcp.tool(annotations={"idempotentHint": True, "readOnlyHint": True, "tags": ["search"], "title": "Get Entity State"})
354367
@log_tool_usage

0 commit comments

Comments
 (0)