mcp: @dont_throw swallows Client.__aenter__/__aexit__ errors (async with gives None)

Author: doronkopit5Created Sep 27, 2026Updated Sep 27, 2026

Problem

_fastmcp_client_enter_wrapper and _fastmcp_client_exit_wrapper are decorated with @dont_throw, and they await wrapped(...) inside it. So when Client.__aenter__ or __aexit__ raises, the instrumentation swallows the exception and logs it at DEBUG.

With instrumentation on, a failed connect doesn't raise, and the async with body runs with c = None:

python
from fastmcp import Client

async with Client("http://127.0.0.1:1/mcp") as c:
    print(c)  # None, no exception

Without instrumentation this raises the connection error. With it, users get an AttributeError on None somewhere later instead. Teardown errors from __aexit__ also disappear.

InstrumentedStreamWriter.send has the same pattern: a failing transport send gets swallowed, and the caller thinks the message went out.

Expected

Instrumentation should never change what the wrapped call raises or returns. dont_throw should only guard the instrumentation's own code (starting/ending spans, setting attributes), not the call to wrapped.

Found while reviewing #4466 / #4517.