fix(client): clamp inbound ttlMs only for cacheable methods

Closed
EN
3d ago
+44-3

Fixes #3866

Summary

  • Guard _clamp_inbound_ttl(raw) in ClientSession.send_request (src/mcp/client/session.py) with if method in _methods.CACHEABLE_METHODS: so non-cacheable extension results (e.g., tools/call claimed results) retain their raw ttlMs values for their own model validation.
  • Cacheable methods (such as resources/read, tools/list, and server/discover) continue to normalize negative ttlMs.
  • Add test_non_cacheable_claimed_result_preserves_negative_and_fractional_ttl_ms in tests/client/test_session_claims.py.

Verification

  • .venv\Scripts\python.exe -m pytest tests/client/test_session_claims.py tests/client/test_client_caching.py -q --basetemp=.pytest-tmp -> 91 passed
  • .venv\Scripts\ruff.exe check src/mcp/client/session.py tests/client/test_session_claims.py -> All checks passed!
  • .venv\Scripts\pyright.exe tests/client/test_session_claims.py -> 0 errors, 0 warnings, 0 informations