docs/v2/clients/elicitation.mdx
import { VersionBadge } from "/snippets/version-badge.mdx";
<VersionBadge version="2.10.0" />Elicitation allows MCP servers to request structured input from users during tool execution. Instead of requiring all inputs upfront, servers can interactively ask users for information as needed - like prompting for missing parameters, requesting clarification, or gathering additional context.
For example, a file management tool might ask "Which directory should I create?" or a data analysis tool might request "What date range should I analyze?"
FastMCP's client provides a helpful abstraction layer that:
When you implement an elicitation handler, FastMCP gives you a dataclass type that matches the server's schema, making it easy to create properly structured responses without having to manually parse JSON schemas.
Provide an elicitation_handler function when creating the client. FastMCP automatically converts the server's JSON schema into a Python dataclass type, making it easy to construct the response:
from fastmcp import Client
from fastmcp.client.elicitation import ElicitResult
async def elicitation_handler(message: str, response_type: type, params, context):
# Present the message to the user and collect input
user_input = input(f"{message}: ")
# Create response using the provided dataclass type
# FastMCP converted the JSON schema to this Python type for you
response_data = response_type(value=user_input)
# You can return data directly - FastMCP will implicitly accept the elicitation
return response_data
# Or explicitly return an ElicitResult for more control
# return ElicitResult(action="accept", content=response_data)
client = Client(
"my_mcp_server.py",
elicitation_handler=elicitation_handler,
)
The elicitation handler receives four parameters:
<Card icon="code" title="Elicitation Handler Parameters"> <ResponseField name="message" type="str"> The prompt message to display to the user </ResponseField> <ResponseField name="response_type" type="type"> A Python dataclass type that FastMCP created from the server's JSON schema. Use this to construct your response with proper typing and IDE support. If the server requests an empty object (indicating no response), this will be `None`. </ResponseField> <ResponseField name="params" type="ElicitRequestParams"> The original MCP elicitation request parameters, including the raw JSON schema in `params.requestedSchema` if you need it </ResponseField> <ResponseField name="context" type="RequestContext"> Request context containing metadata about the elicitation request </ResponseField> </Card>The handler can return data directly (which implicitly accepts the elicitation) or an ElicitResult object for more control over the response action:
Action Types:
accept: User provided valid input - include their data in the content fielddecline: User chose not to provide the requested information - omit contentcancel: User cancelled the entire operation - omit contentfrom fastmcp import Client
from fastmcp.client.elicitation import ElicitResult
async def basic_elicitation_handler(message: str, response_type: type, params, context):
print(f"Server asks: {message}")
# Simple text input for demonstration
user_response = input("Your response: ")
if not user_response:
# For non-acceptance, use ElicitResult explicitly
return ElicitResult(action="decline")
# Use the response_type dataclass to create a properly structured response
# FastMCP handles the conversion from JSON schema to Python type
# Return data directly - FastMCP will implicitly accept the elicitation
return response_type(value=user_response)
client = Client(
"my_mcp_server.py",
elicitation_handler=basic_elicitation_handler
)