fix: Support string enum for elicitation#1563
fix: Support string enum for elicitation#1563vincent0426 wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
a44e8b3 to
07bef73
Compare
|
Hey sorry it took so long to get to this! Would you still be interested in updating this to the latest from |
07bef73 to
97b156d
Compare
|
Hey! Thanks for putting this together. I took a closer look at where things stand now, and wanted to share what I found. Since this PR was opened, SEP-1330 landed via PR #1246 (merged Nov 23), which added enum support but took a different approach - using class FavoriteColorSchema(BaseModel):
favorite_color: str = Field(
description="Select your favorite color",
json_schema_extra={
"oneOf": [
{"const": "red", "title": "Red"},
{"const": "green", "title": "Green"},
]
},
)The tricky thing with native Python enums is that Pydantic generates That said, native enum support could still be valuable from a DX perspective - it's more Pythonic and gives you better type checking. It would just need some extra work to inline the Given all this, I'm thinking we close this PR and instead open an issue for implementing native Python enum support properly - @vincent0426 what do you think? |
Add support for string Enum types in elicitation schemas
Related PR: modelcontextprotocol/inspector#902
Changes Made
StrEnumto_ELICITATION_PRIMITIVE_TYPEStuple_is_primitive_field()to detect string enum types usingissubclass()checksMotivation and Context
Per https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation#supported-schema-types, elicitation schemas support enum types.
Currently,
python-sdkonly supported basic primitive types (str,int,float,bool) in elicitation schemas, but did not recognize Enum types.How Has This Been Tested?
Added test cases in
test_elicitation_schema_validation()to verify enum schemasManual test with
Results
Breaking Changes
Types of changes
Checklist
Additional context
The documentation doesn't explicitly specify that enums must be string enums. Should we add that clarification since both the TypeScript and Rust SDKs only support string enums?
https://github.com/modelcontextprotocol/typescript-sdk/blob/783d53be1049041cc1f0a23c070c3400208a94ff/src/types.ts#L1221-L1229
https://github.com/modelcontextprotocol/rust-sdk/blob/04e0590652d029e2cdfadee6f4c7255280dfba0e/crates/rmcp/src/model/elicitation_schema.rs#L479-L481