#5327·fastmcp

ctx.elicit() raises KeyError when a response model uses the same Enum in two fields

Author: asasemahmedCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbugserver

What happened?

Passing a model or dataclass to ctx.elicit() fails with a KeyError from pydantic's schema generation when two of its fields share an Enum type. The same model with only one enum field works.

Example Code

python
import asyncio
from enum import Enum

from pydantic import BaseModel

from fastmcp import Client, Context, FastMCP


class Currency(Enum):
    USD = "usd"
    EUR = "eur"


class Conversion(BaseModel):
    source: Currency
    target: Currency


mcp = FastMCP()


@mcp.tool
async def convert(ctx: Context) -> str:
    result = await ctx.elicit("Pick currencies", response_type=Conversion)
    return f"{result.data.source.value} -> {result.data.target.value}"


async def handler(message, response_type, params, context):
    return {"source": "usd", "target": "eur"}


async def main():
    async with Client(mcp, mode="legacy", elicitation_handler=handler) as client:
        result = await client.call_tool("convert", raise_on_error=False)
        print(result.content[0].text)


asyncio.run(main())

Output: Error calling tool 'convert': '__main____Currency-Input__1' (a KeyError)

Version Information

FastMCP version:                                          4.0.11.dev11+89b00b7f
MCP version:                                                              2.0.0
Python version:                                                         3.12.14
Platform:                                             Windows-11-10.0.26200-SP0