You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Form elicitation fails when a multi-select field has only one string option #3975
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.
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.
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.
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.
Activity
ansh-rohilla commentedon Dec 5, 2026
Confirmed on
main(77001c9): Pydantic'sGenerateJsonSchema.literal_schemaemits{"const": "email", "type": "string"}for a single-valueLiteral(vs{"enum": [...], "type": "string"}for 2+ values). In_validate_rendered_properties,list[Literal["email"]]then failsPrimitiveSchemaDefinitionvalidation becauseUntitledMultiSelectEnumSchema(Items1) requiresitems.enum: list[str]. Single-selectLiteral["email"]is also affected subtly:{"const": "email", "type": "string"}missesUntitledSingleSelectEnumSchemaand falls through toStringSchema(extra="ignore"), silently droppingconst.Proposed approach:
literal_schemaon_ElicitationJsonSchemainsrc/mcp/server/elicitation.pyto rewrite"const"into"enum": [result.pop("const")], so 1-optionLiteral[...]renders identically to multi-optionLiteral[...]for both single-select and multi-select fields.tests/server/mcpserver/test_elicitation.pycoveringLiteral["email"],list[Literal["email"]], andlist[Literal["sms"]] | None.One question before putting up a PR: should
_ElicitationJsonSchema.literal_schemanormalize"const"→"enum"for all literals emitted bysuper().literal_schema, or only whenresult.get("type") == "string"? (Note thatLiteral[1, 2]already emits{"enum": [1, 2], "type": "integer"}and still validates asNumberSchema, whilelist[Literal[1]]fails validation either way sinceItems1requirestype: "string".)Happy to open a small PR for this if you'd like to assign the issue.
saifullah-ai-engineer commentedon Dec 5, 2026
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.
saggl commentedon Dec 5, 2026
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 ofNonestays optional.Codex helped draft this reply.