Clean up MCP connections, suppressing noisy asyncgen teardown tracebacks.
()
| 468 | |
| 469 | |
| 470 | async def _quiet_cleanup(): |
| 471 | """Clean up MCP connections, suppressing noisy asyncgen teardown tracebacks.""" |
| 472 | # Silence the asyncgen finalization noise that anyio/mcp emits when |
| 473 | # stdio_client's task group is torn down across tasks. The handler is |
| 474 | # intentionally NOT restored: asyncgen finalization happens during |
| 475 | # asyncio.run() shutdown (after run_agent returns), so restoring the |
| 476 | # handler here would still let the noise through. Since this runs |
| 477 | # right before process exit, swallowing late exceptions is safe. |
| 478 | loop = asyncio.get_event_loop() |
| 479 | loop.set_exception_handler(lambda _loop, _ctx: None) |
| 480 | try: |
| 481 | await cleanup_mcp_connections() |
| 482 | except Exception: |
| 483 | pass |
| 484 | |
| 485 | |
| 486 | async def run_agent(workspace_dir: Path, task: str = None): |
no test coverage detected