Core Features
Agents with Tools
import { Agent, Tool } from "@mastra/core";
const weatherTool = new Tool({
name: "get_weather",
description: "Get current weather for a location",
parameters: z.object({ city: z.string() }),
execute: async ({ city }) => {
const res = await fetch(`https://api.weather.com/${city}`);
return res.json();
},
});
const agent = new Agent({
model: "claude-sonnet-4-20250514",
tools: [weatherTool],
});First-Class MCP Support
import { MCPClient } from "@mastra/mcp";
const github = new MCPClient({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-github"],
env: { GITHUB_TOKEN: process.env.GITHUB_TOKEN },
});
const agent = new Agent({
tools: [...github.getTools()], // All MCP tools available
});Workflows
Multi-step workflows with branching and error handling:
import { Workflow, Step } from "@mastra/core";
const workflow = new Workflow("deploy-pipeline")
.step(analyzeCode)
.step(runTests, { dependsOn: [analyzeCode] })
.step(deploy, { dependsOn: [runTests], condition: "tests.passed" })
.step(notify, { dependsOn: [deploy] });
await workflow.execute({ repo: "my-app" });RAG Pipeline
import { RAG } from "@mastra/rag";
const rag = new RAG({
embedder: "openai/text-embedding-3-small",
vectorStore: "pinecone",
chunker: { strategy: "recursive", size: 512 },
});
await rag.index("./docs");
const context = await rag.retrieve("How does auth work?");Persistent Memory
const agent = new Agent({
memory: {
provider: "postgres",
connectionString: process.env.DATABASE_URL,
},
});
// Agent remembers conversations across sessionsKey Stats
- 9,000+ GitHub stars
- TypeScript-first (full type safety)
- Native MCP support
- Workflow orchestration
- RAG + memory built-in
FAQ
Q: What is Mastra? A: Mastra is a TypeScript framework for building production AI agents with tool use, MCP integration, workflows, RAG, and persistent memory.
Q: Is Mastra free? A: Yes, fully open-source under Apache 2.0 license.
Q: How is Mastra different from LangChain.js? A: Mastra is TypeScript-native with first-class MCP support, built-in workflows, and a CLI scaffolding tool. LangChain.js is a port of the Python library.