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 摘要。