# Mastra — TypeScript AI Agent Framework > Production TypeScript framework for building AI agents with tool use, workflows, RAG, and memory. First-class MCP support. Deploy anywhere Node.js runs. 9,000+ GitHub stars. ## Install Save as a script file and run: ## Quick Use ```bash npx create-mastra@latest my-agent cd my-agent && npm run dev ``` ```typescript import { Agent } from "@mastra/core"; const agent = new Agent({ name: "code-reviewer", model: "claude-sonnet-4-20250514", instructions: "You are a senior code reviewer...", tools: [analyzeCode, searchDocs, createIssue], }); const result = await agent.generate("Review this pull request"); ``` --- ## Intro Mastra is a production-ready TypeScript framework for building AI agents with tool use, workflows, RAG pipelines, and persistent memory with 9,000+ GitHub stars. It provides first-class MCP support — connect any MCP server as a tool source — and deploys anywhere Node.js runs. Unlike Python-only agent frameworks, Mastra is built for TypeScript-first teams who want type safety, IDE autocomplete, and the npm ecosystem. Best for full-stack TypeScript developers building production AI applications. Works with: Claude, GPT-4, Gemini, any OpenAI-compatible provider. Setup time: under 3 minutes. --- ## Core Features ### Agents with Tools ```typescript 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 ```typescript 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: ```typescript 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 ```typescript 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 ```typescript const agent = new Agent({ memory: { provider: "postgres", connectionString: process.env.DATABASE_URL, }, }); // Agent remembers conversations across sessions ``` ### Key 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. --- ## Source & Thanks > Created by [Mastra](https://github.com/mastra-ai). Licensed under Apache 2.0. > > [mastra](https://github.com/mastra-ai/mastra) — ⭐ 9,000+ Thanks for giving TypeScript developers a proper AI agent framework. --- ## 快速使用 ```bash npx create-mastra@latest my-agent cd my-agent && npm run dev ``` --- ## 简介 Mastra 是一个生产级 TypeScript AI Agent 框架,GitHub 9,000+ stars。内置工具使用、MCP 支持、工作流编排、RAG 和持久记忆。TypeScript 优先,完整类型安全。适合构建生产 AI 应用的全栈 TypeScript 开发者。 --- ## 来源与感谢 > Created by [Mastra](https://github.com/mastra-ai). Licensed under Apache 2.0. > > [mastra](https://github.com/mastra-ai/mastra) — ⭐ 9,000+ --- Source: https://tokrepo.com/en/workflows/3e118616-e727-4dc7-a561-db39e91cadcd Author: Agent Toolkit