MastraStorage
MastraStorage provides a unified interface for managing:
- Suspended Workflows: the serialized state of suspended workflows (so they can be resumed later)
- Memory: threads and messages per
resourceIdin your application - Traces: OpenTelemetry traces from all components of Mastra
- Eval Datasets: scores and scoring reasons from eval runs

Mastra provides different storage providers, but you can treat them as interchangeable. Eg, you could use libsql in development but postgres in production, and your code will work the same both ways.
Configuration
Mastra can be configured with a default storage option:
import { Mastra } from "@mastra/core/mastra";
import { LibSQLStore } from "@mastra/libsql";
const mastra = new Mastra({
storage: new LibSQLStore({
url: "file:./mastra.db",
}),
});
If you do not specify any storage configuration, Mastra will not persist data across application restarts or deployments. For any
deployment beyond local testing you should provide your own storage
configuration either on Mastra or directly within new Memory().
Data Schema
- Messages
- Threads
- Resources
- Workflows
- Evals
- Traces
Stores conversation messages and their metadata. Each message belongs to a thread and contains the actual content along with metadata about the sender role and message type.
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx){ format: 2, parts: [...] }user | assistantThe message content column contains a JSON object conforming to the MastraMessageContentV2 type, which is designed to align closely with the AI SDK UIMessage message shape.
type.Groups related messages together and associates them with a resource. Contains metadata about the conversation.
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx){
"category": "support",
"priority": 1
}Stores user-specific data for resource-scoped working memory. Each resource represents a user or entity, allowing working memory to persist across all conversation threads for that user.
{
"preferences": {
"language": "en",
"timezone": "UTC"
},
"tags": [
"premium",
"beta-user"
]
}Note: This table is only created and used by storage adapters that support resource-scoped working memory (LibSQL, PostgreSQL, Upstash). Other storage adapters will provide helpful error messages if resource-scoped memory is attempted.
When suspend is called on a workflow, its state is saved in the following format. When resume is called, that state is rehydrated.
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx){
"value": {
"currentState": "running"
},
"context": {
"stepResults": {},
"attempts": {},
"triggerData": {}
},
"activePaths": [],
"runId": "550e8400-e29b-41d4-a716-446655440000",
"timestamp": 1648176000000
}Stores eval results from running metrics against agent outputs.
{
"score": 0.95,
"details": {
"reason": "Response accurately reflects source material",
"citations": [
"page 1",
"page 3"
]
}
}xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)Captures OpenTelemetry traces for monitoring and debugging.
workflow.myWorkflow.execute, http.request, database.query)@mastra/core, express, pg)INTERNAL (0, within process), CLIENT (1, outgoing calls), SERVER (2, incoming calls), PRODUCER (3, async job creation), CONSUMER (4, async job processing)code (UNSET=0, ERROR=1, OK=2) and optional message. Example:{
"code": 1,
"message": "HTTP request failed with status 500"
}{
"droppedAttributesCount": 2,
"droppedEventsCount": 1,
"instrumentationLibrary": "@opentelemetry/instrumentation-http"
}Querying Messages
Messages are stored in a V2 format internally, which is roughly equivalent to the AI SDK's UIMessage format. When querying messages using getMessages, you can specify the desired output format, defaulting to v1 for backwards compatibility:
// Get messages in the default V1 format (roughly equivalent to AI SDK's CoreMessage format)
const messagesV1 = await mastra
.getStorage()
.getMessages({ threadId: "your-thread-id" });
// Get messages in the V2 format (roughly equivalent to AI SDK's UIMessage format)
const messagesV2 = await mastra
.getStorage()
.getMessages({ threadId: "your-thread-id", format: "v2" });
You can also retrieve messages using an array of message IDs. Note that unlike getMessages, this defaults to the V2 format:
const messagesV1 = await mastra
.getStorage()
.getMessagesById({ messageIds: messageIdArr, format: "v1" });
const messagesV2 = await mastra
.getStorage()
.getMessagesById({ messageIds: messageIdArr });
Storage Providers
Mastra supports the following providers:
- For local development, check out LibSQL Storage
- For production, check out PostgreSQL Storage
- For serverless deployments, check out Upstash Storage
- For document-based storage, check out MongoDB Storage