elicitation
Elicitation utilities for MCP servers.
AcceptedElicitation
Bases: BaseModel, Generic[ElicitSchemaModelT]
Result when user accepts the elicitation.
Source code in src/mcp/server/elicitation.py
17 18 19 20 21 | |
DeclinedElicitation
Bases: BaseModel
Result when user declines the elicitation.
Source code in src/mcp/server/elicitation.py
24 25 26 27 | |
CancelledElicitation
Bases: BaseModel
Result when user cancels the elicitation.
Source code in src/mcp/server/elicitation.py
30 31 32 33 | |
AcceptedUrlElicitation
Bases: BaseModel
Result when user accepts a URL mode elicitation.
Source code in src/mcp/server/elicitation.py
39 40 41 42 | |
elicit_with_validation
async
elicit_with_validation(
session: ServerSession,
message: str,
schema: type[ElicitSchemaModelT],
related_request_id: RequestId | None = None,
) -> ElicitationResult[ElicitSchemaModelT]
Elicit information from the client/user with schema validation (form mode).
This method can be used to interactively ask for additional information from the client within a tool's execution. The client might display the message to the user and collect a response according to the provided schema. If the client is an agent, it might decide how to handle the elicitation -- either by asking the user or automatically generating a response.
For sensitive data like credentials or OAuth flows, use elicit_url() instead.
Source code in src/mcp/server/elicitation.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
elicit_url
async
elicit_url(
session: ServerSession,
message: str,
url: str,
elicitation_id: str,
related_request_id: RequestId | None = None,
) -> UrlElicitationResult
Elicit information from the user via out-of-band URL navigation (URL mode).
This method directs the user to an external URL where sensitive interactions can occur without passing data through the MCP client. Use this for: - Collecting sensitive credentials (API keys, passwords) - OAuth authorization flows with third-party services - Payment and subscription flows - Any interaction where data should not pass through the LLM context
The response indicates whether the user consented to navigate to the URL. The actual interaction happens out-of-band. When the elicitation completes, the server should send an ElicitCompleteNotification to notify the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ServerSession
|
The server session |
required |
message
|
str
|
Human-readable explanation of why the interaction is needed |
required |
url
|
str
|
The URL the user should navigate to |
required |
elicitation_id
|
str
|
Unique identifier for tracking this elicitation |
required |
related_request_id
|
RequestId | None
|
Optional ID of the request that triggered this elicitation |
None
|
Returns:
| Type | Description |
|---|---|
UrlElicitationResult
|
UrlElicitationResult indicating accept, decline, or cancel |
Source code in src/mcp/server/elicitation.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |