mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-23 12:39:24 -07:00
fix(guards): use Pydantic model for elicitation to get labeled checkbox instead of 'Value: []'
This commit is contained in:
@@ -6,6 +6,8 @@ tool action with interactive user confirmation or confirm=True bypass.
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from fastmcp import Context
|
from fastmcp import Context
|
||||||
@@ -14,6 +16,10 @@ from ..config.logging import logger
|
|||||||
from .exceptions import ToolError
|
from .exceptions import ToolError
|
||||||
|
|
||||||
|
|
||||||
|
class _ConfirmAction(BaseModel):
|
||||||
|
confirmed: bool = Field(False, description="Check the box to confirm and proceed")
|
||||||
|
|
||||||
|
|
||||||
async def elicit_destructive_confirmation(
|
async def elicit_destructive_confirmation(
|
||||||
ctx: "Context | None", action: str, description: str
|
ctx: "Context | None", action: str, description: str
|
||||||
) -> bool:
|
) -> bool:
|
||||||
@@ -42,7 +48,7 @@ async def elicit_destructive_confirmation(
|
|||||||
f"{description}\n\n"
|
f"{description}\n\n"
|
||||||
"Are you sure you want to proceed?"
|
"Are you sure you want to proceed?"
|
||||||
),
|
),
|
||||||
response_type=bool,
|
response_type=_ConfirmAction,
|
||||||
)
|
)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@@ -56,7 +62,7 @@ async def elicit_destructive_confirmation(
|
|||||||
logger.info("Destructive action '%s' declined by user (%s).", action, result.action)
|
logger.info("Destructive action '%s' declined by user (%s).", action, result.action)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
confirmed: bool = result.data # type: ignore[union-attr]
|
confirmed: bool = result.data.confirmed # type: ignore[union-attr]
|
||||||
if not confirmed:
|
if not confirmed:
|
||||||
logger.info("Destructive action '%s' not confirmed by user.", action)
|
logger.info("Destructive action '%s' not confirmed by user.", action)
|
||||||
return confirmed
|
return confirmed
|
||||||
|
|||||||
Reference in New Issue
Block a user