Use this file to discover all available pages before exploring further.
New in version 2.10.0Use this when you need to respond to server requests for user input during tool execution.Elicitation allows MCP servers to request structured input from users during operations. Instead of requiring all inputs upfront, servers can interactively ask for missing parameters, request clarification, or gather additional context.
from fastmcp import Clientfrom fastmcp.client.elicitation import ElicitResult, ElicitRequestParams, RequestContextasync def elicitation_handler( message: str, response_type: type | None, params: ElicitRequestParams, context: RequestContext) -> ElicitResult | object: """ Handle server requests for user input. Args: message: The prompt to display to the user response_type: Python dataclass type for the response (None if no data expected) params: Original MCP elicitation parameters including raw JSON schema context: Request context with metadata Returns: - Data directly (implicitly accepts the elicitation) - ElicitResult for explicit control over the action """ # Present the message and collect input user_input = input(f"{message}: ") if not user_input: return ElicitResult(action="decline") # Create response using the provided dataclass type return response_type(value=user_input)client = Client( "my_mcp_server.py", elicitation_handler=elicitation_handler,)
When a server needs user input, it sends an elicitation request with a message prompt and a JSON schema describing the expected response structure. FastMCP automatically converts this schema into a Python dataclass type, making it easy to construct properly typed responses without manually parsing JSON schemas.The handler receives four parameters:
A Python dataclass type that FastMCP created from the server’s JSON schema. Use this to construct your response with proper typing. If the server requests an empty object, this will be None.