
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@mastra/convex
Advanced tools
Affected versions:
Convex provider for Mastra - includes both storage and vector adapters plus Convex server helpers
Convex adapters for Mastra:
ConvexStore implements the Mastra storage contract (threads, messages, workflows, scores, resources, schedules, channels, background tasks).ConvexVector stores embeddings inside Convex and performs development-scale cosine similarity search.ConvexNativeVector uses Convex native vector search for production workloads.ConvexServerCache stores Mastra server cache entries in Convex for durable stream replay and response caching.@mastra/convex/server exposes the required Convex table definitions, storage mutation, cache handlers, and native vector handlers.pnpm add @mastra/convex
In convex/schema.ts:
import { defineSchema } from 'convex/server';
import {
mastraThreadsTable,
mastraMessagesTable,
mastraResourcesTable,
mastraWorkflowSnapshotsTable,
mastraScoresTable,
mastraSchedulesTable,
mastraScheduleTriggersTable,
mastraChannelInstallationsTable,
mastraChannelConfigTable,
mastraBackgroundTasksTable,
mastraVectorIndexesTable,
mastraVectorsTable,
mastraCacheTable,
mastraCacheListItemsTable,
mastraDocumentsTable,
} from '@mastra/convex/schema';
export default defineSchema({
mastra_threads: mastraThreadsTable,
mastra_messages: mastraMessagesTable,
mastra_resources: mastraResourcesTable,
mastra_workflow_snapshots: mastraWorkflowSnapshotsTable,
mastra_scorers: mastraScoresTable,
mastra_schedules: mastraSchedulesTable,
mastra_schedule_triggers: mastraScheduleTriggersTable,
mastra_channel_installations: mastraChannelInstallationsTable,
mastra_channel_config: mastraChannelConfigTable,
mastra_background_tasks: mastraBackgroundTasksTable,
mastra_vector_indexes: mastraVectorIndexesTable,
mastra_vectors: mastraVectorsTable,
mastra_cache: mastraCacheTable,
mastra_cache_list_items: mastraCacheListItemsTable,
mastra_documents: mastraDocumentsTable,
});
In convex/mastra/storage.ts:
import { mastraStorage } from '@mastra/convex/server';
export const handle = mastraStorage;
In convex/mastra/cache.ts:
import { mastraCache } from '@mastra/convex/server';
export const handle = mastraCache;
npx convex dev
# or for production
npx convex deploy
import { ConvexServerCache, ConvexStore } from '@mastra/convex';
const storage = new ConvexStore({
id: 'convex',
deploymentUrl: process.env.CONVEX_URL!,
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
storageFunction: 'mastra/storage:handle', // default
});
const cache = new ConvexServerCache({
deploymentUrl: process.env.CONVEX_URL!,
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
cacheFunction: 'mastra/cache:handle', // default
requestTimeoutMs: 30_000, // default
});
clear() removes rows whose stored prefix exactly matches the configured cache prefix. Cleanup runs in bounded batches, so reads for a key being cleared can return empty results until cleanup finishes. During cleanup, cache metadata can briefly use an internal deleted state before the next cleanup pass removes it. List pushes refresh the configured cache TTL.
Use this cache for durable replay of moderate-frequency events; batch high-frequency token streams or use a lower-latency cache backend.
For vectors:
import { ConvexVector } from '@mastra/convex';
const vector = new ConvexVector({
id: 'convex-vectors',
deploymentUrl: process.env.CONVEX_URL!,
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
});
ConvexVector scans stored vectors through the storage handler and computes similarity in the adapter. Use it for local development, tests, and small datasets.
For native Convex vector search, define a dedicated table in convex/schema.ts:
import { defineSchema } from 'convex/server';
import { defineMastraNativeVectorTable } from '@mastra/convex/schema';
export default defineSchema({
docs_vectors: defineMastraNativeVectorTable({
dimensions: 1536,
}),
});
Export the native vector handlers in convex/mastra/nativeVector.ts:
import { mastraNativeVectorAction, mastraNativeVectorMutation, mastraNativeVectorQuery } from '@mastra/convex/server';
export const query = mastraNativeVectorAction;
export const read = mastraNativeVectorQuery;
export const write = mastraNativeVectorMutation;
Configure the native vector adapter:
import { ConvexNativeVector } from '@mastra/convex';
const vector = new ConvexNativeVector({
id: 'convex-native-vectors',
deploymentUrl: process.env.CONVEX_URL!,
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
indexes: {
docs: {
tableName: 'docs_vectors',
vectorIndexName: 'by_embedding',
dimension: 1536,
},
},
});
Native vector search uses Convex's schema-defined vector indexes and action-only ctx.vectorSearch API. It supports topK values from 1 to 256 and equality filters on fields declared in the Convex vector index filterFields.
This adapter uses typed Convex tables for each Mastra domain:
| Domain | Convex Table | Purpose |
|---|---|---|
| Threads | mastra_threads | Conversation threads |
| Messages | mastra_messages | Chat messages |
| Resources | mastra_resources | User working memory |
| Workflows | mastra_workflow_snapshots | Workflow state |
| Scorers | mastra_scorers | Evaluation data |
| Schedules | mastra_schedules | Workflow schedules |
| Triggers | mastra_schedule_triggers | Schedule history |
| Channels | mastra_channel_installations, mastra_channel_config | Channel installations and config |
| Background Tasks | mastra_background_tasks | Background task state |
| Vector Indexes | mastra_vector_indexes | Index metadata |
| Vectors | mastra_vectors | Embeddings |
| Cache | mastra_cache | Cache metadata |
| Cache Items | mastra_cache_list_items | Cache list entries |
| Fallback | mastra_documents | Unknown tables |
All typed tables include:
id field for Mastra's record ID (distinct from Convex's auto-generated _id)by_record_id index for efficient lookups by Mastra IDSchedule due reads and trigger-history reads use bounded Convex queries to avoid deployment read limits. When no explicit trigger-history limit is provided, the adapter returns the newest 100 rows. Schedule listing is capped at 8,000 rows per call. Schedule rows also store a normalized workflow_id alongside the serialized target so workflow filters can run inside Convex before the listing cap is applied.
Background task reads and updates also tolerate older rows that were written to the fallback mastra_documents table.
Set the following environment variables before running tests:
CONVEX_TEST_URL – the Convex deployment URL (e.g., https://your-name.convex.cloud)CONVEX_TEST_ADMIN_KEY – an admin token for that deploymentCONVEX_TEST_STORAGE_FUNCTION (optional) – override if you mounted mastraStorage elsewherepnpm --filter @mastra/convex test
Experimental – expect breaking changes while the adapter matures.
FAQs
Convex provider for Mastra - includes both storage and vector adapters plus Convex server helpers
The npm package @mastra/convex receives a total of 3,672 weekly downloads. As such, @mastra/convex popularity was classified as popular.
We found that @mastra/convex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.