Mastra — TypeScript AI Agent Toolkit
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.
Safe staging for this asset
This asset is staged first. The copied prompt tells the agent to inspect the staged files and ask before activating scripts, MCP config, or global config.
npx -y tokrepo@latest install 3e118616-e727-4dc7-a561-db39e91cadcd --target codexStages files first; activation requires review of the staged README and plan.
What it is
Mastra is a production-ready TypeScript framework for building AI agents. It provides first-class support for tool use, workflows, retrieval-augmented generation (RAG), and agent memory. Mastra integrates natively with the Model Context Protocol (MCP), letting agents connect to external services through standardized tool interfaces.
TypeScript developers building AI-powered applications who want type safety, IDE autocompletion, and a familiar Node.js deployment model will find Mastra a natural fit.
How it saves time or tokens
Mastra eliminates the need to glue together separate libraries for LLM calls, tool schemas, vector search, and workflow orchestration. Everything ships in one framework with TypeScript types. The estimated token usage per session is approximately 2,800 tokens.
How to use
- Install Mastra via npm.
- Define agents with tools, instructions, and model configuration.
- Deploy as a standard Node.js application.
import { Agent } from '@mastra/core';
import { openai } from '@mastra/openai';
const agent = new Agent({
name: 'researcher',
model: openai('gpt-4o'),
instructions: 'You are a research assistant. Search and summarize findings.',
tools: [searchTool, summarizeTool],
});
const result = await agent.generate('Find recent papers on prompt compression');
console.log(result.text);
Example
A multi-step workflow that researches a topic, drafts a summary, and sends it via email:
import { Workflow } from '@mastra/core';
const researchWorkflow = new Workflow({
name: 'research-and-report',
steps: [
{ id: 'research', agent: researchAgent, input: '{{topic}}' },
{ id: 'draft', agent: writerAgent, input: '{{research.output}}' },
{ id: 'send', tool: emailTool, input: { body: '{{draft.output}}' } },
],
});
Related on TokRepo
- Multi-agent frameworks — Compare Mastra with other agent orchestration tools
- AI tools for agents — Browse agent frameworks and toolkits
Common pitfalls
- Mastra is TypeScript-only. Python-based teams should look at LangChain or CrewAI instead.
- MCP server compatibility depends on the server implementation. Test integrations individually.
- Workflow error handling requires explicit try-catch or error step definitions; there is no automatic retry by default.
Frequently Asked Questions
LangChain supports Python and JavaScript with a broader ecosystem of integrations. Mastra is TypeScript-native with stronger type safety and a more opinionated architecture. Choose Mastra for TypeScript-first projects; choose LangChain for multi-language or Python-heavy teams.
Yes. Mastra has first-class MCP support, meaning agents can connect to any MCP server and use its tools natively. This includes filesystem, database, GitHub, and custom MCP servers.
Yes. Mastra supports any OpenAI-compatible API endpoint, so you can point it at Ollama, vLLM, or any local inference server that exposes a compatible API.
Mastra runs anywhere Node.js runs. Deploy as a standard server application, serverless function, or containerized service. There is no vendor lock-in to a specific hosting platform.
Yes. Mastra includes built-in RAG capabilities with document loading, chunking, embedding, and vector search. It integrates with popular vector databases like Pinecone, Weaviate, and pgvector.
Citations (3)
- Mastra GitHub— Mastra is a production TypeScript framework for AI agents with MCP support
- Mastra Documentation— First-class Model Context Protocol integration for tool use
- MCP Specification— MCP provides standardized tool interfaces for AI agents
Related on TokRepo
Source & Thanks
Discussion
Related Assets
Mastra — TypeScript AI Agent Framework
AI agent framework for TypeScript from the Gatsby team. Build agents with tools, workflows, RAG, memory, evals, and 50+ integrations. Modern TS-native design. 22K+ stars.
Mastra Workflows — TypeScript Agent Orchestration
Mastra Workflows defines multi-step typed agent flows in TypeScript. Build pipelines with .then(), .branch(), .parallel(), .while(). End-to-end type-safe.
OpenAI Agents JS — TypeScript Multi-Agent SDK
OpenAI Agents JS brings multi-agent workflows to TypeScript with provider-agnostic runs, zod schemas, tracing hooks, and sandbox agent patterns.
Stripe Agent Toolkit — Payments SDK for LLM Agents
Stripe Agent Toolkit gives LangChain, OpenAI Agents SDK, CrewAI, and Vercel AI SDK direct tool access to charges, customers, and refunds.