diff --git a/src/cp210x_mcp/server.py b/src/cp210x_mcp/server.py index fde8c47..56ea56b 100644 --- a/src/cp210x_mcp/server.py +++ b/src/cp210x_mcp/server.py @@ -325,15 +325,24 @@ async def lock_device(device_index: int = 0, ctx: Context = None) -> dict: f"will be frozen forever." ) - if ctx: - confirmed = await confirm_write(ctx, info) - else: - # No context = no way to confirm, refuse + if not ctx: return { "error": "Lock requires interactive confirmation", "message": "This operation is too dangerous without user confirmation.", } + # Strict confirmation — do NOT fall back to True on failure. + # Unlike regular writes, an irreversible lock must get explicit consent. + try: + result = await ctx.elicit(info, ["Confirm", "Cancel"]) + confirmed = isinstance(result, AcceptedElicitation) and result.data == "Confirm" + except Exception: + return { + "error": "Lock requires elicitation support", + "message": "Your MCP client does not support elicitation. " + "Lock is too dangerous to proceed without explicit confirmation.", + } + if not confirmed: return {"cancelled": True, "message": "Lock cancelled by user"}