You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Streamable HTTP client builds per-message debug log strings even when DEBUG is off #3931
StreamableHTTPTransport formats every message into a debug log with an f-string, so the full repr of each JSON-RPC message is built even when DEBUG is off:
src/mcp/client/streamable_http.py: logger.debug(f"SSE message: {message}") (every received SSE message)
src/mcp/client/streamable_http.py: logger.debug(f"Sending client message: {message}") (every sent message)
Impact: in a proxy that relays MCP traffic with large tool results, CPU profiles showed about 2.4% of total CPU going into these discarded reprs.
Expected: use lazy %s formatting (logger.debug("SSE message: %s", message)), so the repr is only built when DEBUG is enabled. Log output is unchanged.
I'd be happy to send the two-line PR if you assign this to me.
(Drafted with AI assistance; I hit this in production and reviewed it.)
Confirmed this reproduction on main (77001c9): src/mcp/client/streamable_http.py still uses eager f-strings in logger.debug(f"SSE message: {message}") (L191) and logger.debug(f"Sending client message: {message}") (L635), evaluating message.__repr__() on every message even when DEBUG is disabled.
Proposed fix:
Replace both eager f-strings with lazy %s logging (logger.debug("SSE message: %s", message) and logger.debug("Sending client message: %s", message)).
Add a regression test in tests/client/test_streamable_http.py using a tracked message object to assert __repr__ is called 0 times when logger level is WARNING and >=1 time when DEBUG is enabled.
Tested locally against tests/client/test_streamable_http.py (pytest + ruff check passing). If a maintainer is open to assigning #3931, I can open a clean PR with the fix and test.
(Disclosure: prepared with AI-assisted tooling and verified locally by test execution and diff review.)
Activity
ezumba commentedon Nov 29, 2026
Confirmed this reproduction on
main(77001c9):src/mcp/client/streamable_http.pystill uses eager f-strings inlogger.debug(f"SSE message: {message}")(L191) andlogger.debug(f"Sending client message: {message}")(L635), evaluatingmessage.__repr__()on every message even whenDEBUGis disabled.Proposed fix:
%slogging (logger.debug("SSE message: %s", message)andlogger.debug("Sending client message: %s", message)).tests/client/test_streamable_http.pyusing a tracked message object to assert__repr__is called 0 times when logger level isWARNINGand >=1 time whenDEBUGis enabled.Tested locally against
tests/client/test_streamable_http.py(pytest+ruff checkpassing). If a maintainer is open to assigning #3931, I can open a clean PR with the fix and test.(Disclosure: prepared with AI-assisted tooling and verified locally by test execution and diff review.)