AI Hints
Home›MCP Tutorial›Limiting Damage
MCP · Lesson 96 of 120

Confirm Before Acting

Humans approve.

⏱ 2 min read▶ Video at 1:25:49🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

Some actions can't be undone. Cancelling an order, sending money, deleting files. For these, a human should approve, every time, even if the model seems sure.

Confirm Before Acting
From the video: Confirm Before Acting
  • Can't be undone
  • A human approves
  • Every time

The user says no

Our cancel tool asks for confirmation with elicitation. This time the user declines. Run it. The order is kept, so a tricked model can't cancel orders on its own.

confirm.pypython
from mcp_types import ElicitResult
from elicit_server import mcp
from tester import call

async def careful_user(ctx, params):
    print("asked:", params.message, "| user says no")
    return ElicitResult(action="decline")

r = call(mcp, "cancel_order", {"order_id": 1042}, elicitation_callback=careful_user)
print("result:", r.content[0].text)
Output
asked: Cancel order 1042? | user says no
result: kept
Also uses tester.py
import asyncio
from mcp import Client

def call(server, tool, args=None, **options):
    async def go():
        async with Client(server, **options) as client:
            return await client.call_tool(tool, args or {})
    return asyncio.run(go())

def tools(server):
    async def go():
        async with Client(server) as client:
            return (await client.list_tools()).tools
    return asyncio.run(go())
Also uses elicit_server.py
from mcp.server.mcpserver import MCPServer, Context
from mcp_types import InputRequiredResult, ElicitRequest, ElicitRequestFormParams

mcp = MCPServer("shop")
YES_NO = {"type": "object", "properties": {"ok": {"type": "boolean"}}, "required": ["ok"]}

@mcp.tool()
async def cancel_order(order_id: int, ctx: Context) -> str:
    """Cancel an order, after the user confirms."""
    answer = (ctx.input_responses or {}).get("confirm")
    if answer is None:
        ask = ElicitRequestFormParams(message=f"Cancel order {order_id}?", requested_schema=YES_NO)
        return InputRequiredResult(input_requests={"confirm": ElicitRequest(params=ask)})
    return "cancelled" if answer.action == "accept" and answer.content["ok"] else "kept"

Layers of approval

The server asks, with elicitation. The host also asks, before running any tool. Mark risky tools as destructive, so hosts can warn. Together, these stop most harmful actions.

keyvalue
Serverelicitation
Hostapprove each call
Annotationsdestructive_hint
Togetherdefense in depth

Summary

Let humans approve anything that can't be undone, in the server and in the host. Next, authentication.

Key takeaways
  • Elicitation
  • Host approval
  • destructive_hint
Next up: Authentication — OAuth for HTTP servers