mastra/Getting Started

Getting Started

Learn how to set up and start using Mastra for building AI-powered applications

getting-startedsetupinstallationproject

Getting Started with Mastra

Learn how to set up and start using Mastra for building AI-powered applications.

Topics

Project Structure

Mastra projects have a specific structure that organizes agents, tools, workflows, and other components.

Standard Project Layout

my-mastra-project/
├── src/
│   ├── agents/          # Agent definitions
│   ├── tools/           # Custom tools
│   ├── workflows/       # Workflow definitions
│   ├── memory/          # Memory configurations
│   └── index.ts         # Main entry point
├── mastra.config.ts     # Mastra configuration
└── package.json

Key Files

  • mastra.config.ts - Main configuration file for your Mastra instance
  • src/index.ts - Entry point where you initialize and export your Mastra instance

Creating a New Project

Use the create mastra CLI to scaffold a new project:

npx create mastra@latest my-project

See Manual Install for adding Mastra to an existing project.

Manual Install

Add Mastra to an existing TypeScript project.

Installation

npm install @mastra/core

Configuration

Create a mastra.config.ts file in your project root:

import { Mastra } from '@mastra/core';

export const mastra = new Mastra({
  // Configure your agents, tools, memory, etc.
});

TypeScript Configuration

Ensure your tsconfig.json supports ES modules:

{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "bundler"
  }
}

Build with AI

Get started building AI-powered applications with Mastra.

Quick Start

  1. Create a new Mastra project
  2. Define your first agent with tools and memory
  3. Run your agent to test it

Example: Create Your First Agent

import { Mastra } from '@mastra/core';
import { createTool } from '@mastra/tools';

const searchTool = createTool({
  name: 'webSearch',
  description: 'Search the web for information',
  execute: async (query: string) => {
    // Implement search
    return `Results for: ${query}`;
  },
});

export const mastra = new Mastra({
  agents: {
    myAgent: {
      name: 'My First Agent',
      instructions: 'You are a helpful assistant',
      tools: [searchTool],
    },
  },
});

Next Steps