This guide provides instructions for developers who want to contribute to or work with the Mastra codebase.
- Node.js (v20.0+)
- pnpm (v9.7.0+) - Mastra uses pnpm for package management
- Docker (for local development services)
Mastra is organized as a monorepo with the following key directories:
-
packages/ - Core packages that make up the Mastra framework
- core/ - The foundation of the Mastra framework that provides essential components including agent system, LLM abstractions, workflow orchestration, vector storage, memory management, and tools infrastructure
- cli/ - Command-line interface for creating, running, and managing Mastra projects, including the interactive playground UI for testing agents and workflows
- deployer/ - Server infrastructure and build tools for deploying Mastra applications to various environments, with API endpoints for agents, workflows, and memory management
- rag/ - Retrieval-augmented generation tools for document processing, chunking, embedding, and semantic search with support for various reranking strategies
- memory/ - Memory systems for storing and retrieving conversation history, vector data, and application state across sessions
- evals/ - Evaluation frameworks for measuring LLM performance with metrics for accuracy, relevance, toxicity, and other quality dimensions
- mcp/ - Model Context Protocol implementation for standardized communication with AI models, enabling tool usage and structured responses across different providers
-
deployers/ - Platform-specific deployment adapters for services like Vercel, Netlify, and Cloudflare, handling environment configuration and serverless function deployment
-
stores/ - Storage adapters for various vector and key-value databases, providing consistent APIs for data persistence across different storage backends
-
voice/ - Speech-to-text and voice processing capabilities for real-time transcription and voice-based interactions
-
client-sdks/ - Client libraries for different platforms and frameworks that provide type-safe interfaces to interact with Mastra services
-
examples/ - Example applications demonstrating various Mastra features including agents, workflows, memory systems, and integrations with different frameworks
-
Clone the repository:
git clone https://github.com/mastra-ai/mastra.git cd mastra
-
Enable corepack (ensures correct pnpm version):
corepack enable
-
Install dependencies and build initial packages:
pnpm setup
This command installs all dependencies and builds the CLI package, which is required for other packages.
-
Build all packages:
pnpm build
-
Build specific package groups:
pnpm build:packages # All core packages pnpm build:deployers # All deployment adapters pnpm build:combined-stores # All vector and data stores pnpm build:speech # All speech processing packages pnpm build:clients # All client SDKs
-
Build individual packages:
pnpm build:core # Core framework package pnpm build:cli # CLI and playground package pnpm build:deployer # Deployer package pnpm build:rag # RAG package pnpm build:memory # Memory package pnpm build:evals # Evaluation framework package pnpm build:docs-mcp # MCP documentation server
Mastra uses Vitest for testing. To run tests:
-
Ensure development services are running:
pnpm run dev:services:up
-
Set up environment variables:
cp .env.example .env
Add any necessary API keys to the
.env
file. -
Run tests:
- All tests:
pnpm test
- Specific package tests:
pnpm test:core # Core package tests pnpm test:cli # CLI tests pnpm test:rag # RAG tests pnpm test:memory # Memory tests pnpm test:evals # Evals tests pnpm test:clients # Client SDK tests
- Watch mode (for development):
pnpm test:watch
- All tests:
-
Create a branch for your changes:
git checkout -b feature/your-feature-name
-
Make your changes and ensure tests pass:
pnpm test
-
Create a changeset (for version management):
pnpm changeset
Follow the prompts to describe your changes.
-
Open a pull request with your changes.
The documentation site is built from the /docs
directory. To contribute to documentation:
- Make changes to the relevant Markdown files in the
/docs
directory - Test your changes locally
- Submit a pull request with your documentation updates
Join the Mastra Discord community for support and discussions.