Skip to content

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

Backlog

Description

@saggl

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.

Activity

  1. ansh-rohilla commented on Dec 5, 2026

    @ansh-rohilla

    Confirmed on main (77001c9): Pydantic's GenerateJsonSchema.literal_schema emits {"const": "email", "type": "string"} for a single-value Literal (vs {"enum": [...], "type": "string"} for 2+ values). In _validate_rendered_properties, list[Literal["email"]] then fails PrimitiveSchemaDefinition validation because UntitledMultiSelectEnumSchema (Items1) requires items.enum: list[str]. Single-select Literal["email"] is also affected subtly: {"const": "email", "type": "string"} misses UntitledSingleSelectEnumSchema and falls through to StringSchema (extra="ignore"), silently dropping const.

    Proposed approach:

    • Override literal_schema on _ElicitationJsonSchema in src/mcp/server/elicitation.py to rewrite "const" into "enum": [result.pop("const")], so 1-option Literal[...] renders identically to multi-option Literal[...] for both single-select and multi-select fields.
    • Add an end-to-end regression test in tests/server/mcpserver/test_elicitation.py covering Literal["email"], list[Literal["email"]], and list[Literal["sms"]] | None.

    One question before putting up a PR: should _ElicitationJsonSchema.literal_schema normalize "const" → "enum" for all literals emitted by super().literal_schema, or only when result.get("type") == "string"? (Note that Literal[1, 2] already emits {"enum": [1, 2], "type": "integer"} and still validates as NumberSchema, while list[Literal[1]] fails validation either way since Items1 requires type: "string".)

    Happy to open a small PR for this if you'd like to assign the issue.

  2. saifullah-ai-engineer commented on Dec 5, 2026

    @saifullah-ai-engineer

    Reproduced this on main at 77001c9: list[Literal['email']] renders the items schema as {'const': 'email', 'type': 'string'}, and render_elicitation_schema raises TypeError because no PrimitiveSchemaDefinition accepts const inside items. A scalar Literal['email'] renders the same const shape but slips through the gate, since StringSchema ignores the extra key.

    My approach: override literal_schema in _ElicitationJsonSchema so a single-value Literal renders as a one-item enum (keeping the type pydantic already adds), matching how multi-value Literals already render. That makes the list case render {'items': {'enum': ['email'], 'type': 'string'}} exactly as expected, and normalizes the scalar case to {'enum': ['email'], 'type': 'string'}. The change is confined to pydantic-generated Literal schemas, so oneOf/const entries supplied through json_schema_extra (the titled-enum path) are untouched.

    I have the fix implemented and tested locally on branch fix/3975-elicitation-single-literal (fork saifullah-ai-engineer/python-sdk): repro fails before and passes after, new regression test covering both the scalar and list cases with a full in-memory round trip, tests/server/mcpserver/test_elicitation.py 8/8 passed, full suite 6233 passed with one pre-existing failure (test_permission_error, fails on clean main as root), ruff and pyright clean.

    If the approach looks right, could you assign #3975 to me so I can open the PR? Happy to adjust if you would rather handle single-option Literals differently.

    Disclosure: I worked on the fix with AI assistance and have reviewed and tested it myself.

  3. saggl commented on Dec 5, 2026

    @saggl
    Author

    Thanks for reproducing this. I’d limit the conversion to string literals, since MCP form enum choices are strings. That fixes the reported case while preserving the existing behavior for integer and boolean literals.

    I ran the in-memory client against 2.3.0 and the local patch. With the patch, the client received the single email option and its selection reached the tool. Codex also checked that an optional list[Literal["email"]] field with a default of None stays optional.

    Codex helped draft this reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions