AI Hints
Home›MCP Tutorial›Client Callbacks and Practice
MCP · Lesson 61 of 120

Answering Elicitation

The client side.

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

When a server asks the user a question, the host must show it, and collect an answer. In the client, that's the elicitation callback. It receives the message and schema, and returns the user's answer.

Answering Elicitation
From the video: Answering Elicitation
  • Server asks
  • Host shows it
  • Callback answers

A host-side callback

Ask user receives the request. It shows the message and the fields the server wants. Here a pretend user types yes. The callback returns accept, with the content. Run it. The question is shown, and the order is cancelled.

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

async def ask_user(ctx, params):
    print("SERVER ASKS:", params.message)
    print("fields:", list(params.requested_schema["properties"]))
    typed = "yes"  # in a real host, the user types this
    print("user typed:", typed)
    return ElicitResult(action="accept", content={"ok": typed == "yes"})

result = call(mcp, "cancel_order", {"order_id": 1043}, elicitation_callback=ask_user)
print("result:", result.content[0].text)
Output
SERVER ASKS: Cancel order 1043?
fields: ['ok']
user typed: yes
result: cancelled
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"

Host responsibilities

Show which server is asking. Never let a server ask for passwords or card numbers in a form. Let the user decline. And if the host can't show forms, it shouldn't claim to support elicitation.

keyvalue
Showwhich server asks
Neverpasswords in forms
Allowdecline
Supportonly if you can

Summary

The elicitation callback shows the server's question, and returns the user's answer. Next, progress on the client.

Key takeaways
  • elicitation_callback
  • Show the message
  • Return the answer
Next up: Progress on the Client — callbacks