mastra-ai/mastra · critical · Error
Memory requires a storage provider to function. Add a storag
Error message
Memory requires a storage provider to function. Add a storage configuration to Memory or to your Mastra instance. https://mastra.ai/en/docs/memory/overview
What it means
Memory needs a storage adapter to persist threads and messages; the lazy `storage` getter throws this Error when accessed while `this._storage` is undefined. Storage can be attached directly to Memory or inherited from the Mastra instance. The getter exists so Memory fails with a clear actionable message instead of a confusing null dereference later.
Source
Thrown at packages/core/src/memory/memory.ts:234
}
/**
* Internal method used by Mastra to register itself with the memory.
* @param mastra The Mastra instance.
* @internal
*/
__registerMastra(mastra: Mastra): void {
this.#mastra = mastra;
}
protected _hasOwnStorage = false;
get hasOwnStorage() {
return this._hasOwnStorage;
}
get storage() {
if (!this._storage) {
throw new Error(
`Memory requires a storage provider to function. Add a storage configuration to Memory or to your Mastra instance.
https://mastra.ai/en/docs/memory/overview`,
);
}
return this._storage;
}
public setStorage(storage: MastraCompositeStore) {
this._storage = augmentWithInit(storage);
}
public setVector(vector: MastraVector) {
this.vector = vector;
}
public setEmbedder(
embedder: EmbeddingModelId | MastraEmbeddingModel<string>,View on GitHub (pinned to 75dd419e61)
Solutions
- Add a storage adapter to the Memory config, e.g. storage: new LibSQLStore({ url: 'file:memory.db' }).
- Or attach Memory to a Mastra instance that has storage configured, so Memory inherits it.
- Ensure the code path that accesses memory.storage runs only after the Memory instance is fully constructed/registered.
Example fix
// before
const memory = new Memory({ options: { lastMessages: 10 } });
// after
const memory = new Memory({
storage: new LibSQLStore({ url: 'file:memory.db' }),
options: { lastMessages: 10 },
}); Defensive patterns
Strategy: validation
Validate before calling
function ensureMemoryStorage(memory) {
if (!memory.hasOwnStorage) {
// only safe if Memory is registered on a Mastra instance with storage
throw new Error('Memory has no storage attached; pass storage or register on Mastra with storage');
}
} Type guard
function hasStorage(m) { return typeof m.hasOwnStorage === 'boolean' && m.hasOwnStorage; } Prevention
- Configure storage on the Mastra instance once and let all Memory instances inherit it.
- Never construct Memory with options-only config outside tests.
- Guard direct memory.storage access behind a helper that validates presence first.
When it happens
Trigger: Accessing memory.storage (directly or via internal operations like recall, thread creation, saveMessages) on a Memory instance constructed with no storage config and not attached to a Mastra instance that has storage.
Common situations: Standalone Memory usage in tests or scripts where a storage adapter was never configured; constructing `new Memory({ options })` with only semantic-recall/working-memory options; forgetting that Mastra instance-level storage only applies when Memory is registered on that instance.
Related errors
- Credential storage is not available
- Factory source control storage is unavailable
- DURABLE_AGENT_LIST_ACTIVE_RUNS_NO_STORAGE
- Storage is not configured on this AgentController
- Storage does not have a memory domain configured
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/479297943b791a2b.
Report an issue: GitHub.