Normalize asyncio.TimeoutError to builtin in task input timeout (py3.10)

asyncio.wait_for raises asyncio.TimeoutError, a distinct type from the builtin
before Python 3.11, so an elicitation-callback timeout leaked an uncaught type
on 3.10. Convert it to the builtin TimeoutError the rest of the drive raises.
This commit is contained in:
Jeremiah Lowin 2026-07-23 18:35:57 -04:00
commit 95f766cb74
No known key found for this signature in database

View file

@ -199,7 +199,15 @@ async def _answer_input_requests(
)
budget = _remaining()
call = elicitation_callback(context, request.params)
answer = await (asyncio.wait_for(call, budget) if budget is not None else call)
try:
answer = await (
asyncio.wait_for(call, budget) if budget is not None else call
)
except asyncio.TimeoutError as exc:
# Normalize to the builtin: on Python 3.10 `asyncio.wait_for` raises
# `asyncio.TimeoutError`, a distinct type from the builtin the rest of
# the drive raises (they were unified in 3.11).
raise TimeoutError(f"Task {task_id} timed out awaiting input") from exc
if isinstance(answer, mcp_types.ErrorData):
raise ToolError(f"Elicitation for task {task_id} failed: {answer.message}")
responses[surfaced_key] = answer.model_dump(