fix(elicitation): guard ctx=None in elicit_and_configure, cover all settings/docker/notifications actions

- setup.py: elicit_and_configure now accepts Context | None; returns False
  immediately when ctx is None instead of crashing with AttributeError
- settings.py: added CredentialsNotConfiguredError try/except guard around
  make_graphql_request calls in all 8 previously-unguarded actions
  (update_temperature, update_time, configure_ups, update_api, connect_sign_in,
  connect_sign_out, setup_remote_access, enable_dynamic_remote_access)
- docker.py: added guards to all 20 previously-unguarded make_graphql_request
  calls (details, logs, networks, network_details, port_conflicts, check_updates,
  restart, update_all, all 11 organizer mutations, and single-container fallback)
- notifications.py: added guards to all 11 previously-unguarded calls
  (list, warnings, create, archive/unread, delete, delete_archived, archive_all,
  archive_many, create_unique, unarchive_many, unarchive_all, recalculate)
This commit is contained in:
Jacob Magar
2026-03-14 04:28:34 -04:00
parent e1c80cf1da
commit 85cd173449
4 changed files with 447 additions and 88 deletions

View File

@@ -21,15 +21,26 @@ class _UnraidCredentials:
api_key: str
async def elicit_and_configure(ctx: Context) -> bool:
async def elicit_and_configure(ctx: Context | None) -> bool:
"""Prompt the user for Unraid credentials via MCP elicitation.
Writes accepted credentials to .env in PROJECT_ROOT and applies them
to the running process via apply_runtime_config().
Args:
ctx: The MCP context for elicitation. If None, returns False immediately
(no context available to prompt the user).
Returns:
True if credentials were accepted and applied, False if declined/cancelled.
"""
if ctx is None:
logger.warning(
"Cannot elicit credentials: no MCP context available. "
"Run unraid_health action=setup to configure credentials."
)
return False
result = await ctx.elicit(
message=(
"Unraid MCP needs your Unraid server credentials to connect.\n\n"