fastmcp.server.middleware.caching
A middleware for response caching.
Classes
CachableReadResourceContents
A wrapper for ReadResourceContents that can be cached.
Methods:
get_size
get_sizes
wrap
unwrap
CachableToolResult
Methods:
wrap
unwrap
SharedMethodSettings
Shared config for a cache method.
ListToolsSettings
Configuration options for Tool-related caching.
ListResourcesSettings
Configuration options for Resource-related caching.
ListPromptsSettings
Configuration options for Prompt-related caching.
CallToolSettings
Configuration options for Tool-related caching.
ReadResourceSettings
Configuration options for Resource-related caching.
GetPromptSettings
Configuration options for Prompt-related caching.
ResponseCachingStatistics
ResponseCachingMiddleware
The response caching middleware offers a simple way to cache responses to mcp methods. The Middleware
supports cache invalidation via notifications from the server. The Middleware implements TTL-based caching
but cache implementations may offer additional features like LRU eviction, size limits, and more.
When items are retrieved from the cache they will no longer be the original objects, but rather no-op objects
this means that response caching may not be compatible with other middleware that expects original subclasses.
Notes:
- Caches
tools/call
,resources/read
,prompts/get
,tools/list
,resources/list
, andprompts/list
requests. - Cache keys are derived from method name and arguments.