| 1362 | """ |
| 1363 | |
| 1364 | async def _elicit(params: dict[str, Any]) -> dict[str, Any]: |
| 1365 | request_id = str(_uuid.uuid4()) |
| 1366 | pending = _Pending(event=threading.Event()) |
| 1367 | with sess._lock: |
| 1368 | sess._pending[request_id] = pending |
| 1369 | sess._emit({ |
| 1370 | "type": "control_request", |
| 1371 | "request_id": request_id, |
| 1372 | "request": {"subtype": "mcp_elicitation", "params": params}, |
| 1373 | }) |
| 1374 | loop = asyncio.get_event_loop() |
| 1375 | try: |
| 1376 | got = await loop.run_in_executor( |
| 1377 | None, pending.event.wait, sess.config.permission_timeout_s |
| 1378 | ) |
| 1379 | finally: |
| 1380 | with sess._lock: |
| 1381 | sess._pending.pop(request_id, None) |
| 1382 | if not got: |
| 1383 | return {"action": "cancel"} |
| 1384 | return pending.reply or {"action": "decline"} |
| 1385 | |
| 1386 | return _elicit |
| 1387 | |