Elicitation (bonus، advanced)
عنوان اصلی: Elicitation
هدف یادگیری: استفاده از elicitation/create که اجازه میدهد server وسط یک task از user ورودی اضافه بپرسد.
Elicitation آینه sampling است، اما بدون LLM call. وقتی server به یک تایید صریح user یا یک پاسخ free-text نیاز دارد که نباید LLM آن را تولید کند، از elicitation استفاده میکند. capability را client بهصورت "elicitation": {} اعلام میکند.
مثال عملی — Python (server درخواست elicitation از داخل tool)
@mcp.tool()
async def delete_file(path: str, ctx) -> str:
"""Delete a file after confirming with the user."""
confirm = await ctx.session.elicit(
message=f"Are you sure you want to delete {path}? Type 'yes' to confirm.",
requested_schema={"type": "object",
"properties": {"answer": {"type": "string"}},
"required": ["answer"]},
)
if confirm.content.get("answer") != "yes":
return "Cancelled by user"
# ... actual delete ...
return f"Deleted {path}"
اشتباهات رایج
- استفاده از elicitation برای جمعآوری ورودی روتین که میتواند inputSchema یک tool باشد. UX را خراب میکند.
- نداشتن fallback وقتی client elicitation را پشتیبانی نمیکند.