fastmcp.utilities.storage
Key-value storage utilities for persistent data management.
Classes
KVStorage
Protocol for key-value storage of JSON data.
Methods:
get
set
delete
JSONFileStorage
File-based key-value storage for JSON data with automatic metadata tracking.
Each key-value pair is stored as a separate JSON file on disk.
Keys are sanitized to be filesystem-safe.
The storage automatically wraps all data with metadata:
- timestamp: Timestamp when the entry was last written
cache_dir
: Directory for storing JSON files
get
key
: The key to retrieve
- The stored dict or None if not found
set
key
: The key to store undervalue
: The dict to store
delete
key
: The key to delete
cleanup_old_entries
max_age_seconds
: Maximum age in seconds (default 30 days)
- Number of entries removed