User Elicitation
Handle server-initiated user input requests with structured schemas.
New in version: 2.10.0
What is Elicitation?
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?”
How FastMCP Makes Elicitation Easy
FastMCP’s client provides a helpful abstraction layer that:
- Converts JSON schemas to Python types: The raw MCP protocol uses JSON schemas, but FastMCP automatically converts these to Python dataclasses
- Provides structured constructors: Instead of manually building dictionaries that match the schema, you get dataclass constructors that ensure correct structure
- Handles type conversion: FastMCP takes care of converting between JSON representations and Python objects
- Runtime introspection: You can inspect the generated dataclass fields to understand the expected structure
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.
Elicitation Handler
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:
Handler Parameters
The elicitation handler receives four parameters:
Elicitation Handler Parameters
The prompt message to display to the user
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.
The original MCP elicitation request parameters, including the raw JSON schema in params.requestedSchema
if you need it
Request context containing metadata about the elicitation request
Response Actions
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 thecontent
fielddecline
: User chose not to provide the requested information - omitcontent
cancel
: User cancelled the entire operation - omitcontent