@@ -39,7 +39,9 @@ def generate_secret_path() -> str:
3939
4040
4141_SECRET_PATH_RE = re .compile (r"^/(?!.*://)\S{7,}$" )
42- _SECRET_PATH_HINT = "Path must start with '/', contain no '://', and be at least 8 characters."
42+ _SECRET_PATH_HINT = (
43+ "Path must start with '/', contain no '://', and be at least 8 characters."
44+ )
4345
4446
4547def _is_valid_secret_path (path : str ) -> bool :
@@ -65,7 +67,9 @@ def get_or_create_secret_path(data_dir: Path, custom_path: str = "") -> str:
6567 if not path .startswith ("/" ):
6668 path = "/" + path
6769 if not _is_valid_secret_path (path ):
68- log_error (f"Custom secret path is invalid ({ path !r} ), ignoring. { _SECRET_PATH_HINT } " )
70+ log_error (
71+ f"Custom secret path is invalid ({ path !r} ), ignoring. { _SECRET_PATH_HINT } "
72+ )
6973 else :
7074 log_info ("Using custom secret path from configuration" )
7175 # Update stored path for consistency
@@ -80,7 +84,9 @@ def get_or_create_secret_path(data_dir: Path, custom_path: str = "") -> str:
8084 log_info ("Using existing auto-generated secret path" )
8185 return stored_path
8286 elif stored_path :
83- log_error (f"Stored secret path is invalid ({ stored_path !r} ), regenerating. { _SECRET_PATH_HINT } " )
87+ log_error (
88+ f"Stored secret path is invalid ({ stored_path !r} ), regenerating. { _SECRET_PATH_HINT } "
89+ )
8490 else :
8591 log_error ("Stored secret path is empty, regenerating" )
8692 except Exception as e :
@@ -234,31 +240,59 @@ def main() -> int:
234240 backup_hint = config .get ("backup_hint" , "normal" )
235241 custom_secret_path = config .get ("secret_path" , "" )
236242 raw_tool_search = config .get ("enable_tool_search" , False )
237- enable_tool_search = raw_tool_search if isinstance (raw_tool_search , bool ) else False
243+ enable_tool_search = (
244+ raw_tool_search if isinstance (raw_tool_search , bool ) else False
245+ )
238246 raw_yaml_config = config .get ("enable_yaml_config_editing" , False )
239- enable_yaml_config_editing = raw_yaml_config if isinstance (raw_yaml_config , bool ) else False
247+ enable_yaml_config_editing = (
248+ raw_yaml_config if isinstance (raw_yaml_config , bool ) else False
249+ )
240250 raw_filesystem_tools = config .get ("enable_filesystem_tools" , False )
241- enable_filesystem_tools = raw_filesystem_tools if isinstance (raw_filesystem_tools , bool ) else False
242- raw_custom_component = config .get ("enable_custom_component_integration" , False )
243- enable_custom_component_integration = raw_custom_component if isinstance (raw_custom_component , bool ) else False
251+ enable_filesystem_tools = (
252+ raw_filesystem_tools
253+ if isinstance (raw_filesystem_tools , bool )
254+ else False
255+ )
256+ raw_custom_component = config .get (
257+ "enable_custom_component_integration" , False
258+ )
259+ enable_custom_component_integration = (
260+ raw_custom_component
261+ if isinstance (raw_custom_component , bool )
262+ else False
263+ )
244264 raw_code_mode = config .get ("enable_code_mode" , False )
245- enable_code_mode = raw_code_mode if isinstance (raw_code_mode , bool ) else False
265+ enable_code_mode = (
266+ raw_code_mode if isinstance (raw_code_mode , bool ) else False
267+ )
246268 raw_lite_docstrings = config .get ("enable_lite_docstrings" , False )
247- enable_lite_docstrings = raw_lite_docstrings if isinstance (raw_lite_docstrings , bool ) else False
269+ enable_lite_docstrings = (
270+ raw_lite_docstrings if isinstance (raw_lite_docstrings , bool ) else False
271+ )
248272 raw_auto_backup = config .get ("enable_auto_backup" , False )
249- enable_auto_backup = raw_auto_backup if isinstance (raw_auto_backup , bool ) else False
273+ enable_auto_backup = (
274+ raw_auto_backup if isinstance (raw_auto_backup , bool ) else False
275+ )
250276 raw_throttle = config .get ("auto_backup_throttle_minutes" , 0 )
251- auto_backup_throttle_minutes = raw_throttle if isinstance (raw_throttle , int ) else 0
277+ auto_backup_throttle_minutes = (
278+ raw_throttle if isinstance (raw_throttle , int ) else 0
279+ )
252280 raw_retain = config .get ("auto_backup_retain_per_entity" , 20 )
253- auto_backup_retain_per_entity = raw_retain if isinstance (raw_retain , int ) else 20
281+ auto_backup_retain_per_entity = (
282+ raw_retain if isinstance (raw_retain , int ) else 20
283+ )
254284 raw_max_results = config .get ("tool_search_max_results" , 5 )
255- tool_search_max_results = raw_max_results if isinstance (raw_max_results , int ) else 5
285+ tool_search_max_results = (
286+ raw_max_results if isinstance (raw_max_results , int ) else 5
287+ )
256288 raw_disabled = config .get ("disabled_tools" , "" )
257289 disabled_tools_raw = raw_disabled if isinstance (raw_disabled , str ) else ""
258290 raw_pinned = config .get ("pinned_tools" , "" )
259291 pinned_tools_raw = raw_pinned if isinstance (raw_pinned , str ) else ""
260292 verify_ssl = resolve_bool_option (config , "verify_ssl" , True )
261- advanced_debug_logging = resolve_bool_option (config , "advanced_debug_logging" , False )
293+ advanced_debug_logging = resolve_bool_option (
294+ config , "advanced_debug_logging" , False
295+ )
262296 except Exception as e :
263297 log_error (f"Failed to read config: { e } , using defaults" )
264298
@@ -288,7 +322,9 @@ def main() -> int:
288322 os .environ ["ENABLE_TOOL_SEARCH" ] = str (enable_tool_search ).lower ()
289323 os .environ ["ENABLE_YAML_CONFIG_EDITING" ] = str (enable_yaml_config_editing ).lower ()
290324 os .environ ["HAMCP_ENABLE_FILESYSTEM_TOOLS" ] = str (enable_filesystem_tools ).lower ()
291- os .environ ["HAMCP_ENABLE_CUSTOM_COMPONENT_INTEGRATION" ] = str (enable_custom_component_integration ).lower ()
325+ os .environ ["HAMCP_ENABLE_CUSTOM_COMPONENT_INTEGRATION" ] = str (
326+ enable_custom_component_integration
327+ ).lower ()
292328 os .environ ["ENABLE_CODE_MODE" ] = str (enable_code_mode ).lower ()
293329 os .environ ["ENABLE_LITE_DOCSTRINGS" ] = str (enable_lite_docstrings ).lower ()
294330 os .environ ["ENABLE_AUTO_BACKUP" ] = str (enable_auto_backup ).lower ()
@@ -302,9 +338,7 @@ def main() -> int:
302338 # tool isn't registered anyway, so the file is never read or
303339 # written. Operators can override by setting CODE_MODE_SAVED_TOOLS_PATH
304340 # in the add-on's environment if they want a different location.
305- os .environ .setdefault (
306- "CODE_MODE_SAVED_TOOLS_PATH" , "/data/saved_tools.json"
307- )
341+ os .environ .setdefault ("CODE_MODE_SAVED_TOOLS_PATH" , "/data/saved_tools.json" )
308342 os .environ ["TOOL_SEARCH_MAX_RESULTS" ] = str (tool_search_max_results )
309343 os .environ ["DISABLED_TOOLS" ] = disabled_tools_raw
310344 os .environ ["PINNED_TOOLS" ] = pinned_tools_raw
@@ -331,6 +365,7 @@ def main() -> int:
331365
332366 # Configure logging before server start (v3 removed log_level from run())
333367 import logging
368+
334369 logging .basicConfig (level = logging .INFO )
335370
336371 # Import and register browser landing before server start
@@ -353,6 +388,7 @@ def main() -> int:
353388 from ha_mcp .utils .kill_signal_diagnostics import (
354389 schedule_install_after_uvicorn ,
355390 )
391+
356392 schedule_install_after_uvicorn ()
357393 except Exception as e :
358394 log_error (f"advanced_debug_logging install failed: { e !r} ; continuing" )
@@ -364,7 +400,9 @@ def main() -> int:
364400 # server's actual FastMCP instance (not the _DeferredMCP wrapper)
365401 # so mypy doesn't trip over the duck-typed __getattr__ forwarding.
366402 server_instance = _get_server ()
367- register_settings_routes (server_instance .mcp , server_instance , secret_path = secret_path )
403+ register_settings_routes (
404+ server_instance .mcp , server_instance , secret_path = secret_path
405+ )
368406 logging .getLogger ("mcp.server.streamable_http" ).addFilter (
369407 StatelessSessionLogFilter ()
370408 )
@@ -391,7 +429,9 @@ def main() -> int:
391429 cause = e .__cause__ or e .__context__
392430 if cause :
393431 log_error (f"Caused by: { cause } " )
394- traceback .print_exception (type (cause ), cause , cause .__traceback__ , file = sys .stderr )
432+ traceback .print_exception (
433+ type (cause ), cause , cause .__traceback__ , file = sys .stderr
434+ )
395435 if isinstance (e , SystemExit ):
396436 return int (e .code ) if isinstance (e .code , int ) else 1
397437 return 1
0 commit comments