diff --git a/pyproject.toml b/pyproject.toml index 6b41c1ae36..22fdd6b683 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,9 @@ filterwarnings = [ # Suppress OAuth in-memory token storage warnings in tests # Tests intentionally use ephemeral storage; this warning is for end users "ignore:Using in-memory token storage:UserWarning", + # Treat unawaited coroutine warnings as errors - these are almost always bugs + "error:coroutine .* was never awaited:RuntimeWarning", + "error:Exception ignored in.*coroutine:pytest.PytestUnraisableExceptionWarning", ] timeout = 5 env = [ diff --git a/src/fastmcp/client/client.py b/src/fastmcp/client/client.py index 4b8488280f..910b6d9982 100644 --- a/src/fastmcp/client/client.py +++ b/src/fastmcp/client/client.py @@ -686,6 +686,8 @@ async def _await_with_session_monitoring( # If session task already failed, raise immediately if session_task.done(): + # Close the coroutine to avoid "was never awaited" warning + coro.close() exc = session_task.exception() if exc: raise exc