mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 23:29:10 +02:00
* Update repository references from jlowin/fastmcp to prefecthq/fastmcp * Retrigger CI after repo transfer * chore: Update SDK documentation * Only run deep triage on bug issues for jlowin --------- Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
145 lines
5.3 KiB
Text
145 lines
5.3 KiB
Text
---
|
|
title: elicitation
|
|
sidebarTitle: elicitation
|
|
---
|
|
|
|
# `fastmcp.server.elicitation`
|
|
|
|
## Functions
|
|
|
|
### `parse_elicit_response_type` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L132" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
parse_elicit_response_type(response_type: Any) -> ElicitConfig
|
|
```
|
|
|
|
|
|
Parse response_type into schema and handling configuration.
|
|
|
|
Supports multiple syntaxes:
|
|
- None: Empty object schema, expect empty response
|
|
- dict: `{"low": {"title": "..."}}` -> single-select titled enum
|
|
- list patterns:
|
|
- `[["a", "b"]]` -> multi-select untitled
|
|
- `[{"low": {...}}]` -> multi-select titled
|
|
- `["a", "b"]` -> single-select untitled
|
|
- `list[X]` type annotation: multi-select with type
|
|
- Scalar types (bool, int, float, str, Literal, Enum): single value
|
|
- Other types (dataclass, BaseModel): use directly
|
|
|
|
|
|
### `handle_elicit_accept` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L265" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
handle_elicit_accept(config: ElicitConfig, content: Any) -> AcceptedElicitation[Any]
|
|
```
|
|
|
|
|
|
Handle an accepted elicitation response.
|
|
|
|
**Args:**
|
|
- `config`: The elicitation configuration from parse_elicit_response_type
|
|
- `content`: The response content from the client
|
|
|
|
**Returns:**
|
|
- AcceptedElicitation with the extracted/validated data
|
|
|
|
|
|
### `get_elicitation_schema` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L324" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_elicitation_schema(response_type: type[T]) -> dict[str, Any]
|
|
```
|
|
|
|
|
|
Get the schema for an elicitation response.
|
|
|
|
**Args:**
|
|
- `response_type`: The type of the response
|
|
|
|
|
|
### `validate_elicitation_json_schema` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L343" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
validate_elicitation_json_schema(schema: dict[str, Any]) -> None
|
|
```
|
|
|
|
|
|
Validate that a JSON schema follows MCP elicitation requirements.
|
|
|
|
This ensures the schema is compatible with MCP elicitation requirements:
|
|
- Must be an object schema
|
|
- Must only contain primitive field types (string, number, integer, boolean)
|
|
- Must be flat (no nested objects or arrays of objects)
|
|
- Allows const fields (for Literal types) and enum fields (for Enum types)
|
|
- Only primitive types and their nullable variants are allowed
|
|
|
|
**Args:**
|
|
- `schema`: The JSON schema to validate
|
|
|
|
**Raises:**
|
|
- `TypeError`: If the schema doesn't meet MCP elicitation requirements
|
|
|
|
|
|
## Classes
|
|
|
|
### `ElicitationJsonSchema` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L36" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Custom JSON schema generator for MCP elicitation that always inlines enums.
|
|
|
|
MCP elicitation requires inline enum schemas without $ref/$defs references.
|
|
This generator ensures enums are always generated inline for compatibility.
|
|
Optionally adds enumNames for better UI display when available.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `generate_inner` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L44" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
generate_inner(self, schema: core_schema.CoreSchema) -> JsonSchemaValue
|
|
```
|
|
|
|
Override to prevent ref generation for enums and handle list schemas.
|
|
|
|
|
|
#### `list_schema` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L57" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
list_schema(self, schema: core_schema.ListSchema) -> JsonSchemaValue
|
|
```
|
|
|
|
Generate schema for list types, detecting enum items for multi-select.
|
|
|
|
|
|
#### `enum_schema` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L94" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
enum_schema(self, schema: core_schema.EnumSchema) -> JsonSchemaValue
|
|
```
|
|
|
|
Generate inline enum schema.
|
|
|
|
Always generates enum pattern: `{"enum": [value, ...]}`
|
|
Titled enums are handled separately via dict-based syntax in ctx.elicit().
|
|
|
|
|
|
### `AcceptedElicitation` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L105" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Result when user accepts the elicitation.
|
|
|
|
|
|
### `ScalarElicitationType` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L113" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
### `ElicitConfig` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/elicitation.py#L118" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Configuration for an elicitation request.
|
|
|
|
**Attributes:**
|
|
- `schema`: The JSON schema to send to the client
|
|
- `response_type`: The type to validate responses with (None for raw schemas)
|
|
- `is_raw`: True if schema was built directly (extract "value" from response)
|
|
|