URL: https://gofastmcp.com/clients/elicitation
Title: User Elicitation - FastMCP

Documentation Index
Fetch the complete documentation index at:
/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main content
Meet
Prefect Horizon
, the enterprise MCP gateway built by the team behind FastMCP
FastMCP
home page
v3
Prefect Horizon
PrefectHQ/fastmcp
25,596
PrefectHQ/fastmcp
25,596
Search...
Navigation
Operations
User Elicitation
Search the docs...
Ctrl
K
Documentation
Get Started
Welcome!
Installation
Quickstart
Servers
Overview
Core Components
Working with Tools
MCP Providers
Interactivity
Extensibility
Auth
Deployment
Apps
Overview
Quickstart
NEW
FastMCPApp
NEW
Interactive Tools
NEW
Generative UI
NEW
Custom HTML
Reference
Clients
Overview
Client-Only Package
Transports
fastmcp-remote
Operations
UPDATED
Tools
Resources
Prompts
Sampling
Elicitation
Tasks
NEW
Progress
Logging
Roots
Notifications
Authentication
UPDATED
Integrations
Auth
Web Frameworks
AI Assistants
AI SDKs
MCP.json
More
Settings
CLI
Upgrading
Development
What's New
FAQ
On this page
Handler Template
How It Works
Response Actions
Example
Operations
User Elicitation
Copy page
Handle server requests for structured user input.
Copy page
New in version
2.10.0
Use 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.
​
Handler Template
from
fastmcp
import
Client
from
fastmcp
.
client
.
elicitation
import
ElicitResult
,
ElicitRequestParams
,
RequestContext
async
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
,
)
​
How It Works
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:
Handler Parameters
​
message
str
The prompt message to display to the user
​
response_type
type | None
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
.
​
params
ElicitRequestParams
The original MCP elicitation parameters, including the raw JSON schema in
params.requestedSchema
​
context
RequestContext
Request context containing metadata about the elicitation request
​
Response Actions
You can return data directly, which implicitly accepts the elicitation:
async
def
elicitation_handler
(
message
,
response_type
,
params
,
context
):
user_input
=
input
(
f
"
{
message
}
: "
)
return
response_type
(
value
=
user_input
)
# Implicit accept
Or return an
ElicitResult
for explicit control over the action:
from
fastmcp
.
client
.
elicitation
import
ElicitResult
async
def
elicitation_handler
(
message
,
response_type
,
params
,
context
):
user_input
=
input
(
f
"
{
message
}
: "
)
if
not
user_input
:
return
ElicitResult
(
action
=
"
decline
"
)
# User declined
if
user_input
==
"
cancel
"
:
return
ElicitResult
(
action
=
"
cancel
"
)
# Cancel entire operation
return
ElicitResult
(
action
=
"
accept
"
,
content
=
response_type
(
value
=
user_input
)
)
Action types:
accept
: User provided valid input. Include the data in the
content
field.
decline
: User chose not to provide the requested information. Omit
content
.
cancel
: User cancelled the entire operation. Omit
content
.
​
Example
A file management tool might ask which directory to create:
from
fastmcp
import
Client
from
fastmcp
.
client
.
elicitation
import
ElicitResult
async
def
elicitation_handler
(
message
,
response_type
,
params
,
context
):
print
(
f
"Server asks:
{
message
}
"
)
user_response
=
input
(
"
Your response:
"
)
if
not
user_response
:
return
ElicitResult
(
action
=
"
decline
"
)
# Use the response_type dataclass to create a properly structured response
return
response_type
(
value
=
user_response
)
client
=
Client
(
"
my_mcp_server.py
"
,
elicitation_handler
=
elicitation_handler
)
LLM Sampling
Previous
Background Tasks
Next
Ctrl
+I
discord
github
website
x
Powered by
This documentation is built and hosted on Mintlify, a developer documentation platform
Assistant
Responses are generated using AI and may contain mistakes.
\n\n
\n
\n \n
\n
