Skip to content

Make CacheConfig() the Client cache default and None the off switch - #3164

Merged
maxisbey merged 1 commit into
mainfrom
cache-config-none-disables
Jul 25, 2026
Merged

maxisbey merged 1 commit into
mainfrom
cache-config-none-disables

Conversation

@maxisbey

Copy link
Copy Markdown
Contributor

Client.cache was typed CacheConfig | Literal[False] | None, a three-state sentinel where None meant "use the default config" and False meant "disabled". This collapses it to CacheConfig | None with field(default_factory=CacheConfig): the default CacheConfig() is cache-on, and None turns caching off.

Motivation and Context

The None-as-auto sentinel exists to avoid sharing a default instance, but that concern isn't real here: CacheConfig is a frozen dataclass and store=None already means "build a fresh InMemoryResponseCacheStore per client", so the config carries no per-client state. With that gone, None can mean what it means everywhere else (no cache), and the if self.cache is not False: config = self.cache if self.cache is not None else CacheConfig() dance in __post_init__ collapses to if self.cache is not None.

How Has This Been Tested?

Updated the existing caching, subscription and docs tests for the new spelling (cache=None in place of cache=False); exercised default / CacheConfig() / None end-to-end against an in-process server with a ttlMs hint.

Breaking Changes

cache=False is now cache=None. The response cache is new on main (SEP-2549, not on v1.x), so there's no released API to migrate.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

The cache field was a three-state CacheConfig | Literal[False] | None where
None meant "use the default config" and False meant "disabled". Since
CacheConfig is a frozen dataclass and the store is instantiated per client,
a plain CacheConfig() default is inert to share, so the sentinel bought
nothing. Default to CacheConfig() and let None disable caching.
@maxisbey
maxisbey marked this pull request as ready for review July 25, 2026 16:39
@github-actions

Copy link
Copy Markdown
Contributor

📚 Documentation preview

Preview https://pr-3164.mcp-python-docs.pages.dev
Deployment https://bb6f0303.mcp-python-docs.pages.dev
Commit 63eaad5
Triggered by @maxisbey
Updated 2026-07-25 16:40:54 UTC

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Re-trigger cubic

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.