Mastra
TypeScript-first agent framework with built-in workflows, RAG, integrations, and evaluation tools. Mastra provides a cohesive toolkit for building production agents in the TypeScript/Node.js ecosystem, with first-class support for structured outputs, tool calling, and multi-step workflows using an XState-inspired state machine approach.
Architecture Overview
Mastra uses an Agent class that combines a model, tools, and system instructions. Workflows are defined as state machines with steps, transitions, and conditional logic, similar to XState. The framework includes a built-in RAG module with vector store abstractions, an integration layer for connecting to external APIs, and an evaluation module for testing agent outputs. All components are TypeScript-native with full type safety.
When to Use Mastra
- TypeScript/Node.js backend agents and services
- Full-stack AI applications with React frontends
- API automation with third-party integrations
- Workflow automation with state machine logic
- RAG applications in the TypeScript ecosystem
Strengths & Weaknesses
Strengths
- TypeScript-native with full type safety throughout
- Built-in workflow engine with state machine semantics
- Integrated RAG, evaluation, and observability
- Good integration library for third-party APIs
- MCP support for standardized tool access
Weaknesses
- Newer framework with a smaller community
- TypeScript-only limits accessibility for Python developers
- Fewer pre-built tools compared to LangChain ecosystem
Quick Start
import { Agent } from "@mastra/core/agent";
import { createTool } from "@mastra/core/tools";
import { openai } from "@ai-sdk/openai";
import { z } from "zod";
const weatherTool = createTool({
id: "get-weather",
description: "Get the current weather for a location",
inputSchema: z.object({
location: z.string().describe("The city name"),
}),
outputSchema: z.object({
temperature: z.number(),
condition: z.string(),
}),
execute: async ({ context }) => {
// context.location comes from the input schema
return { temperature: 72, condition: "Sunny in " + context.location };
},
});
const agent = new Agent({
name: "Weather Agent",
instructions: "You are a helpful weather assistant.",
model: openai("gpt-4o"),
tools: { "get-weather": weatherTool },
});
const response = await agent.generate(
"What's the weather in San Francisco?"
);
console.log(response.text);Features at a Glance
| Developer | Mastra |
| Language | TypeScript |
| License | MIT |
| GitHub Stars | 8k+ |
| MCP Support | Yes |
| Multi-Agent | Yes |
Notable Users
Resources
Explore Related Content
Tool Use & Function Calling
How agents interact with external tools, APIs, and services to take action in the real world.
GuideYour First Agent in 5 Minutes
Build a working AI agent from scratch in under 5 minutes using the OpenAI Agents SDK or Anthropic SDK.
PatternReAct Pattern
Reasoning and Acting — the agent thinks step-by-step, then acts on its reasoning in iterative loops.