Skip to main content
FastMCP uses pluggable storage backends for caching responses and managing OAuth state. By default, all storage is in-memory, which is perfect for development but doesn’t persist across restarts. FastMCP includes support for multiple storage backends, and you can easily extend it with custom implementations.
The storage layer is powered by py-key-value-aio, an async key-value library maintained by a core FastMCP maintainer. This library provides a unified interface for multiple backends, making it easy to swap implementations based on your deployment needs.

Available Backends

In-Memory Storage

Best for: Development, testing, single-process deployments In-memory storage is the default for all FastMCP storage needs. It’s fast, requires no setup, and is perfect for getting started.
Characteristics:
  • ✅ No setup required
  • ✅ Very fast
  • ❌ Data lost on restart
  • ❌ Not suitable for multi-process deployments

Disk Storage

Best for: Single-server production deployments, persistent caching Disk storage persists data to the filesystem, allowing it to survive server restarts.
Or with OAuth token storage:
Characteristics:
  • ✅ Data persists across restarts
  • ✅ Good performance for moderate load
  • ❌ Not suitable for distributed deployments
  • ❌ Filesystem access required

Redis

Best for: Distributed production deployments, shared caching across multiple servers
Redis support requires an optional dependency: pip install 'py-key-value-aio[redis]'
Redis provides distributed caching and state management, ideal for production deployments with multiple server instances.
With authentication:
For OAuth token storage:
Characteristics:
  • ✅ Distributed and highly available
  • ✅ Fast in-memory performance
  • ✅ Works across multiple server instances
  • ✅ Built-in TTL support
  • ❌ Requires Redis infrastructure
  • ❌ Network latency vs local storage

Other Backends from py-key-value-aio

The py-key-value-aio library includes additional implementations for various storage systems:
  • DynamoDB - AWS distributed database
  • MongoDB - NoSQL document store
  • Elasticsearch - Distributed search and analytics
  • Memcached - Distributed memory caching
  • RocksDB - Embedded high-performance key-value store
  • Valkey - Redis-compatible server
For configuration details on these backends, consult the py-key-value-aio documentation.
Before using these backends in production, review the py-key-value documentation to understand the maturity level and limitations of your chosen backend. Some backends may be in preview or have specific constraints that make them unsuitable for production use.

Use Cases in FastMCP

Server-Side OAuth Token Storage

The OAuth Proxy and OAuth auth providers use storage for persisting OAuth client registrations and upstream tokens. By default, storage is automatically encrypted using FernetEncryptionWrapper. When providing custom storage, wrap it in FernetEncryptionWrapper to encrypt sensitive OAuth tokens at rest. Development (default behavior): By default, FastMCP automatically manages keys and storage based on your platform:
  • Mac/Windows: Keys are auto-managed via system keyring, storage defaults to disk. Suitable only for development and local testing.
  • Linux: Keys are ephemeral, storage defaults to memory.
No configuration needed:
Production: For production deployments, configure explicit keys and persistent network-accessible storage with encryption:
Both parameters are required for production. Wrap your storage in FernetEncryptionWrapper to encrypt sensitive OAuth tokens at rest - without it, tokens are stored in plaintext. See OAuth Token Security and Key and Storage Management for complete setup details.

Response Caching Middleware

The Response Caching Middleware caches tool calls, resource reads, and prompt requests. Storage configuration is passed via the cache_storage parameter:
For multi-server deployments sharing a Redis instance:

Client-Side OAuth Token Storage

The FastMCP Client uses storage for persisting OAuth tokens locally. By default, tokens are stored in memory:
This allows clients to reconnect without re-authenticating after restarts.

Choosing a Backend

Decision tree:
  1. Just starting? Use Memory (default) - no configuration needed
  2. Single server, needs persistence? Use Disk
  3. Multiple servers or cloud deployment? Use Redis or DynamoDB
  4. Existing infrastructure? Look for a matching py-key-value-aio backend

More Resources