mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-23 12:39:24 -07:00
refactor(guards): remove elicit_destructive_confirmation from setup.py (moved to guards.py)
Update array, keys, and plugins tool imports to source elicit_destructive_confirmation from core.guards instead of core.setup.
This commit is contained in:
@@ -29,51 +29,37 @@ class _UnraidCredentials:
|
|||||||
api_key: str
|
api_key: str
|
||||||
|
|
||||||
|
|
||||||
async def elicit_destructive_confirmation(
|
async def elicit_reset_confirmation(ctx: Context | None, current_url: str) -> bool:
|
||||||
ctx: Context | None, action: str, description: str
|
"""Ask the user whether to overwrite already-working credentials.
|
||||||
) -> bool:
|
|
||||||
"""Prompt the user to confirm a destructive action via MCP elicitation.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
ctx: The MCP context for elicitation. If None, returns False immediately.
|
ctx: The MCP context for elicitation. If None, returns False immediately.
|
||||||
action: The action name (for display in the prompt).
|
current_url: The currently configured URL (displayed for context).
|
||||||
description: Human-readable description of what the action will do.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True if the user accepted, False if declined, cancelled, or no context.
|
True if the user confirmed the reset, False otherwise.
|
||||||
"""
|
"""
|
||||||
if ctx is None:
|
if ctx is None:
|
||||||
logger.warning(
|
|
||||||
"Cannot elicit confirmation for '%s': no MCP context available. "
|
|
||||||
"Re-run with confirm=True to bypass elicitation.",
|
|
||||||
action,
|
|
||||||
)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = await ctx.elicit(
|
result = await ctx.elicit(
|
||||||
message=(
|
message=(
|
||||||
f"**Confirm destructive action: `{action}`**\n\n"
|
"Credentials are already configured and working.\n\n"
|
||||||
f"{description}\n\n"
|
f"**Current URL:** `{current_url}`\n\n"
|
||||||
"Are you sure you want to proceed?"
|
"Do you want to reset your API URL and key?"
|
||||||
),
|
),
|
||||||
response_type=bool,
|
response_type=bool,
|
||||||
)
|
)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
logger.warning(
|
logger.warning("MCP client does not support elicitation for reset confirmation.")
|
||||||
"MCP client does not support elicitation for action '%s'. "
|
|
||||||
"Re-run with confirm=True to bypass.",
|
|
||||||
action,
|
|
||||||
)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if result.action != "accept":
|
if result.action != "accept":
|
||||||
logger.info("Destructive action '%s' declined by user (%s).", action, result.action)
|
logger.info("Credential reset declined by user (%s).", result.action)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
confirmed: bool = result.data # type: ignore[union-attr]
|
confirmed: bool = result.data # type: ignore[union-attr]
|
||||||
if not confirmed:
|
|
||||||
logger.info("Destructive action '%s' not confirmed by user.", action)
|
|
||||||
return confirmed
|
return confirmed
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from fastmcp import Context, FastMCP
|
|||||||
from ..config.logging import logger
|
from ..config.logging import logger
|
||||||
from ..core.client import make_graphql_request
|
from ..core.client import make_graphql_request
|
||||||
from ..core.exceptions import ToolError, tool_error_handler
|
from ..core.exceptions import ToolError, tool_error_handler
|
||||||
from ..core.setup import elicit_destructive_confirmation
|
from ..core.guards import elicit_destructive_confirmation
|
||||||
|
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from fastmcp import Context, FastMCP
|
|||||||
from ..config.logging import logger
|
from ..config.logging import logger
|
||||||
from ..core.client import make_graphql_request
|
from ..core.client import make_graphql_request
|
||||||
from ..core.exceptions import ToolError, tool_error_handler
|
from ..core.exceptions import ToolError, tool_error_handler
|
||||||
from ..core.setup import elicit_destructive_confirmation
|
from ..core.guards import elicit_destructive_confirmation
|
||||||
|
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from fastmcp import Context, FastMCP
|
|||||||
from ..config.logging import logger
|
from ..config.logging import logger
|
||||||
from ..core.client import make_graphql_request
|
from ..core.client import make_graphql_request
|
||||||
from ..core.exceptions import ToolError, tool_error_handler
|
from ..core.exceptions import ToolError, tool_error_handler
|
||||||
from ..core.setup import elicit_destructive_confirmation
|
from ..core.guards import elicit_destructive_confirmation
|
||||||
|
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user