render_elicitation_schema rejects StrEnum and (str, Enum) fields because Pydantic emits $defs/$ref
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Bắt đầu trong src/mcp/server/elicitation.py tại _ElicitationJsonSchema và _validate_rendered_properties(), và chạy repro trong issue để xem các giá trị $defs/$ref được phát ra. Bản sửa là inline các schema enum của $defs (trường hợp đơn, tùy chọn và list[...]) trước khi xác thực, để các ref model khác bị từ chối. Hoàn tất khi các trường StrEnum và (str, Enum) được render thành {"type": "string", "enum": [...]} giống Literal, cùng với các test hồi quy bên cạnh các test schema elicitation hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 @ 77001c96)
AI disclosure: AI assistance was used to help investigate and draft this issue; the reproduction and observed output were verified locally.
- Ngôn ngữ chính
- Python
- Star
- 25k
- Fork
- 4.2k
- Merge trung bình
- 10 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/python-sdk
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
modelcontextprotocol/python-sdk#3978 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Client serves cached tools after its context exits with an exceptionCó thể đã có người làm @jonxsong đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
modelcontextprotocol/python-sdk#3968 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
modelcontextprotocol/python-sdk#3957 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
modelcontextprotocol/python-sdk#3934 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug v1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
modelcontextprotocol/python-sdk#3929 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/python-sdk
Issue tương tự
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwiseCó thể đã có người làm @abdulwaarith0 đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
MakazhanAlpamys/Soup#3690 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug data-types native-format
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ClickHouse/clickhouse-connect#1320 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Public benchmark import end-to-end test fails when the test stack's worker runs the parity jobĐang mởaccepted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
future-agi/future-agi#6392 ·
Maintainer thường phản hồi trong vòng 1 ngày