What happened?
With the titled {"low": {...}} shorthand or the multi-select [["a", "b"]] shorthand, ctx.elicit() returns whatever the client sends as accepted data, even a value that wasn't offered or a string where a list is expected. The plain ["low", "high"] shorthand rejects such answers.
Example Code
import asyncio
from fastmcp import Client, Context, FastMCP
mcp = FastMCP()
@mcp.tool
async def pick(ctx: Context) -> str:
single = await ctx.elicit(
"Priority?",
response_type={"low": {"title": "Low"}, "high": {"title": "High"}},
)
multi = await ctx.elicit("Tags?", response_type=[["bug", "feature"]])
return f"{single.data!r} {multi.data!r}"
async def handler(message, response_type, params, context):
if message == "Priority?":
return {"value": "urgent"}
return {"value": "not-a-list"}
async def main():
async with Client(mcp, mode="legacy", elicitation_handler=handler) as client:
result = await client.call_tool("pick", raise_on_error=False)
print(result.content[0].text)
asyncio.run(main())
Output: 'urgent' 'not-a-list'
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
What happened?
With the titled
{"low": {...}}shorthand or the multi-select[["a", "b"]]shorthand,ctx.elicit()returns whatever the client sends as accepted data, even a value that wasn't offered or a string where a list is expected. The plain["low", "high"]shorthand rejects such answers.Example Code
Output:
'urgent' 'not-a-list'Version Information