Repository navigation
Description
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
render_elicitation_schema() in src/mcp/server/elicitation.py rejects Pydantic models whose fields use StrEnum or (str, Enum) — both single-select (color: Color, color: Color | None = None) and multi-select (colors: list[Color]) — even though the equivalent Literal["red", "blue"] and list[Literal["red", "blue"]] fields are accepted and MCP elicitation explicitly supports string enums and multi-select enums.
Root cause: Pydantic emits a $defs entry and a {"$ref": "#/$defs/Color"} property for Enum subclasses, and _ElicitationJsonSchema does not inline enum schemas before _validate_rendered_properties() validates each property against PrimitiveSchemaDefinition. As a result, ctx.elicit() and Resolve(..., Elicit(...)) both raise TypeError before sending the request.
Example Code
from enum import StrEnum
from typing import Literal
from pydantic import BaseModel
from mcp.server.elicitation import render_elicitation_schema
class Color(StrEnum):
RED = "red"
BLUE = "blue"
class LiteralForm(BaseModel):
color: Literal["red", "blue"]
colors: list[Literal["red", "blue"]]
class EnumForm(BaseModel):
color: Color
class MultiEnumForm(BaseModel):
colors: list[Color]
print("LiteralForm OK:", render_elicitation_schema(LiteralForm)["properties"]["color"])
for cls in (EnumForm, MultiEnumForm):
try:
render_elicitation_schema(cls)
except TypeError as exc:
print(f"{cls.__name__} TypeError: {exc}")Observed output:
LiteralForm OK: {'enum': ['red', 'blue'], 'title': 'Color', 'type': 'string'}
EnumForm TypeError: Elicitation schema field 'color' rendered as {'$ref': '#/$defs/Color'}, which is not a valid PrimitiveSchemaDefinition
MultiEnumForm TypeError: Elicitation schema field 'colors' rendered as {'items': {'$ref': '#/$defs/Color'}, 'title': 'Colors', 'type': 'array'}, which is not a valid PrimitiveSchemaDefinition
Expected behavior: StrEnum / string Enum fields (single, optional, and list[Enum] multi-select) should render inline {"type": "string", "enum": [...]} (or array-of-enum) schemas matching Literal without emitting $defs/$ref, while non-primitive models still get rejected.
I would be happy to submit a PR with regression tests if assigned.
Python & MCP Python SDK
- Python: 3.14.8
- mcp: 2.3.1.dev20+77001c96 (main @ 77001c9)
AI disclosure: AI assistance was used to help investigate and draft this issue; the reproduction and observed output were verified locally.
Activity
Shanmukh-l33t commentedon Nov 21, 2026
Branch with a fix and a regression test: main...Shanmukh-l33t:python-sdk:fix/elicitation-string-enum
Root cause: pydantic emits a
$defsentry plus a$refproperty for everyEnumsubclass, andPrimitiveSchemaDefinitionhas no$refform, so_validate_rendered_propertiesrejects the field before anything is sent. The renderer now inlines the string enums pydantic hoisted (member values allstr), which produces the same shape asLiteral, and still rejects non-string enums and nested models.Test evidence:
pytest tests/server/mcpserver/test_elicitation.py -k string_enum -qfails, the tool raisesUnexpectedToolErrorfromElicitation schema field 'color' rendered as {'$ref': '#/$defs/Color'}.tests/server/mcpserver/test_elicitation.py,test_resolve.py,test_url_elicitation.py,test_url_elicitation_error_throw.pyandtests/docs_src/test_elicitation.py.coverage reportfiltered tosrc/mcp/server/elicitation.py: 81 statements, 24 branches, 0 missed, 0 partial branches, 100.00%, exit 0.ruff check,ruff formatcheck andpyrightare clean.Cases covered:
StrEnumsingle select,(str, Enum)optional,list[StrEnum]multi select, and a plainEnumof ints that must stay rejected.AI assistance was used to prepare this branch.
0718lol commentedon Nov 21, 2026
One design question for maintainers on the fix direction: would you prefer preventing
$defs/$refhoisting for string enums inside_ElicitationJsonSchema(via Pydantic'sGenerateJsonSchemahooks), or post-processing$defs/$refinrender_elicitation_schema()aftermodel_json_schema()?As noted in the OP (and per
CONTRIBUTING.md), I'd be happy to own the PR and regression tests once a maintainer confirms the preferred approach.MrSpy00 commentedon Nov 24, 2026
I have a tested fix ready for this (inlining string Enum schemas in
render_elicitation_schemainstead of emitting$defs/$ref). Could you assign this issue to me so I can reopen the PR?