{{ message }}
fix: Support string enum for elicitation#1563
Closed
vincent0426 wants to merge 4 commits into
Closed
Conversation
a44e8b3 to
07bef73
Compare
Contributor
07bef73 to
97b156d
Compare
Contributor
MukundaKatta
added a commit
to MukundaKatta/python-sdk
that referenced
this pull request
Apr 15, 2026
…textprotocol#2384) Pydantic's model_json_schema() emits $ref/$defs for nested models, but LLM clients consuming tools/list often can't resolve $ref and serialize referenced parameters as stringified JSON instead of structured objects. Inline local $ref pointers in tool schemas so they're self-contained and LLM-consumable, matching behavior in typescript-sdk (modelcontextprotocol#1563) and go-sdk. Behavior: - Caches resolved defs (diamond references resolve each def once) - Cycles left in place with $defs entries preserved (degraded but correct) - Sibling keywords alongside $ref preserved per JSON Schema 2020-12 - External $ref and unknown local refs untouched - Input schema not mutated Changes: - Add mcp/server/mcpserver/utilities/schema.py with dereference_local_refs() - Apply to tool inputSchema at Tool.from_function() - 11 unit tests covering simple refs, diamond, cycles, siblings, legacy 'definitions' keyword, external refs, unknown refs, nested arrays/objects, input immutability Closes modelcontextprotocol#2384
MukundaKatta
added a commit
to MukundaKatta/python-sdk
that referenced
this pull request
Apr 15, 2026
…textprotocol#2384) Pydantic's model_json_schema() emits $ref/$defs for nested models, but LLM clients consuming tools/list often cannot resolve $ref and serialize referenced parameters as stringified JSON instead of structured objects. Inline local $ref pointers in tool schemas so they're self-contained and LLM-consumable, matching behavior in typescript-sdk (modelcontextprotocol#1563) and go-sdk. Behavior: - Caches resolved defs (diamond references resolve each def once) - Cycles left in place with $defs entries preserved (degraded but correct) - Sibling keywords alongside $ref preserved per JSON Schema 2020-12 - External $ref and unknown local refs untouched - Input schema not mutated Changes: - Add mcp/server/mcpserver/utilities/schema.py with dereference_local_refs() - Apply to tool inputSchema at Tool.from_function() - 11 unit tests covering simple refs, diamond, cycles, siblings, legacy 'definitions' keyword, external refs, unknown refs, nested arrays/objects, input immutability Closes modelcontextprotocol#2384 Signed-off-by: Mukunda Katta <mukunda.vjcs6@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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