AI Hints
Home›MCP Tutorial›Elicitation and Progress
MCP · Lesson 26 of 120

Saying No

Decline and cancel.

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

Users don't always say yes. They can accept and answer, decline the request, or cancel and walk away. A good tool handles all three safely.

Saying No
From the video: Saying No
  • Accept
  • Decline
  • Cancel

Three actions

Accept means the user answered, and the content holds their answer. Decline means they chose not to. Cancel means they dismissed the question. For anything risky, only accept with a clear yes should go ahead.

ActionMeaningSafe response
acceptansweredcheck the answer
declinesaid nodo nothing
canceldismisseddo nothing

When the user declines

We reuse the cancel order server, but this time the callback declines. Run it. The order is kept, because only a clear yes cancels it.

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

async def user_declines(ctx, params):
    print("asked:", params.message)
    return ElicitResult(action="decline")

print(call(mcp, "cancel_order", {"order_id": 1042}, elicitation_callback=user_declines).content[0].text)
Output
asked: Cancel order 1042?
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"

Summary

Treat decline and cancel as no. Only a clear accepted yes should trigger a risky action. Next, progress for long tools.

Key takeaways
  • accept
  • decline
  • cancel
Next up: Progress — long-running tools