Form elicitation fails when a multi-select field has only one string option

未關閉
#3,975 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

Start in mcp.server.elicitation.render_elicitation_schema and trace how Pydantic turns list[Literal["email"]] into the elicitation items schema. Compare the generated schema with the multi-option case and inspect the validation against PrimitiveSchemaDefinition. Add a regression test for the single-option case; done means the schema has "enum": ["email"] and the form returns the selected value.

由索引模型根據 Issue 內容生成。

描述

Initial Checks
Release line

2.x (current stable)

Description

With list[Literal["email", "print"]], the SDK sends the form. With list[Literal["email"]], I reproduced a failure before the client received the form. Both [] and ["email"] are meaningful selections.

I expected the items schema to contain "enum": ["email"]. On 2.3.0 it contains "const": "email", and the SDK raises TypeError when validating the channels field against PrimitiveSchemaDefinition.

I ran the same in-memory client twice. On 2.3.0 the tool returned Error executing tool subscribe. With a local patch, the client received {"enum": ["email"], "type": "string"} and the tool returned email successfully.

Related issue #3883 covers $ref for Enum classes. This example uses typing.Literal.

Codex helped investigate, wrote the local patch and regression test, and drafted this report.

Example Code
from typing import Literal

from mcp.server.elicitation import render_elicitation_schema
from pydantic import BaseModel

class Delivery(BaseModel):
    channels: list[Literal["email"]]

print(render_elicitation_schema(Delivery)["properties"]["channels"])
Python & MCP Python SDK
Python 3.14.4, mcp 2.3.0, Pydantic 2.12.5. Also reproduced on main at 77001c96.
主要語言
Python
星號
25k
分支
4.2k
平均合併
10 分鐘
30 天內合併 PR
1

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。