SkillsMar 30, 2026·2 min read

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.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Community
Entrypoint
Mastra — TypeScript AI Agent Framework
Direct install command
npx -y tokrepo@latest install 59d6f322-d438-4ed3-ab97-ea580be76f48 --target codex

Run after dry-run confirms the install plan.

TL;DR
A TypeScript framework for building AI agents with built-in RAG, tool use, workflows, and third-party integrations.
§01

What it is

Mastra is an open-source TypeScript framework for building AI agents. It provides a unified API for creating agents with tool use, retrieval-augmented generation (RAG), multi-step workflows, and integrations with third-party services. Unlike Python-centric agent frameworks, Mastra is designed from the ground up for the TypeScript/Node.js ecosystem.

The framework targets full-stack TypeScript developers who want to build AI-powered applications without switching to Python. It includes a CLI for project scaffolding (npx create-mastra@latest), a local development server, and built-in support for popular LLM providers (OpenAI, Anthropic, Google).

§02

How it saves time or tokens

Mastra reduces the integration burden of building AI agents. Instead of wiring together separate libraries for LLM calls, vector search, tool execution, and workflow orchestration, Mastra provides all of these as first-class features in a single package. This eliminates dependency management overhead and ensures components work together without compatibility issues.

The built-in RAG support is particularly valuable. Mastra handles document chunking, embedding generation, vector storage, and retrieval within the same framework, so you do not need to set up a separate vector database pipeline. This saves both development time and the tokens that would be wasted on hallucinated answers without proper context retrieval.

§03

How to use

  1. Create a new Mastra project:

```bash

npx create-mastra@latest my-agent

cd my-agent

npm run dev

```

  1. Or add to an existing project:

```bash

npm install mastra @mastra/core

```

  1. Define an agent with tools and start using it.
§04

Example

A Mastra agent with a custom tool:

import { Agent, createTool } from '@mastra/core';
import { z } from 'zod';

const weatherTool = createTool({
  id: 'get-weather',
  description: 'Get current weather for a city',
  inputSchema: z.object({
    city: z.string().describe('City name'),
  }),
  execute: async ({ context }) => {
    const resp = await fetch(
      `https://wttr.in/${context.city}?format=j1`
    );
    const data = await resp.json();
    return { temp: data.current_condition[0].temp_C };
  },
});

const agent = new Agent({
  name: 'WeatherBot',
  instructions: 'Help users check weather conditions.',
  model: { provider: 'ANTHROPIC', name: 'claude-sonnet-4-20250514' },
  tools: { 'get-weather': weatherTool },
});

const response = await agent.generate(
  'What is the weather in Tokyo?'
);
console.log(response.text);

Mastra core features:

FeatureDescription
AgentLLM with instructions, tools, and memory
ToolsType-safe tool definitions with Zod schemas
RAGBuilt-in document chunking, embedding, and retrieval
WorkflowsMulti-step agent pipelines with conditional logic
IntegrationsPre-built connectors for APIs and services
Dev ServerLocal development server with playground UI
§05

Related on TokRepo

§06

Common pitfalls

  • Expecting full parity with Python agent frameworks. Mastra is TypeScript-native, which means some Python-only libraries (LangChain integrations, certain vector stores) are not directly available. Check Mastra's integration list before assuming a specific service is supported.
  • Not using Zod schemas for tool inputs. Mastra uses Zod for type-safe tool parameter validation. Defining tools without proper schemas leads to runtime errors when the LLM passes unexpected parameter types.
  • Running the dev server in production. The npm run dev command starts a local development server with hot reloading and debugging features. For production, build the project and run the compiled output, or deploy to a serverless platform.

Frequently Asked Questions

How does Mastra compare to LangChain.js?+

Mastra is designed as a simpler, more opinionated framework specifically for building agents. LangChain.js is a broader toolkit with more building blocks and integration options. Mastra provides built-in RAG, tool use, and workflows in a cohesive package, while LangChain.js requires assembling these components from separate modules. Choose Mastra for a faster start; choose LangChain.js for maximum flexibility.

Which LLM providers does Mastra support?+

Mastra supports OpenAI, Anthropic (Claude), and Google (Gemini) as built-in providers. You can also configure custom providers that implement the OpenAI-compatible API format, which covers local models via Ollama or LM Studio. The provider is specified in the agent configuration.

Does Mastra include a vector database for RAG?+

Mastra includes built-in vector storage that works for development and small-scale production. For large-scale deployments, it integrates with external vector databases like Pinecone, Qdrant, and Chroma. The RAG pipeline (chunking, embedding, retrieval) works the same regardless of the storage backend.

Can I use Mastra in a Next.js application?+

Yes. Mastra is designed for the Node.js runtime and integrates well with Next.js API routes and server actions. You can define agents and tools in your Next.js backend and call them from the frontend. The framework handles server-side execution and streams responses to the client.

Is Mastra suitable for production deployments?+

Yes. Mastra is designed for production use with proper error handling, streaming support, and observability. It can be deployed on any Node.js hosting platform (Vercel, Railway, AWS Lambda). The framework handles conversation state management and tool execution lifecycle for reliable production operation.

Citations (3)
🙏

Source & Thanks

Created by Mastra AI (from the Gatsby team). Licensed under MIT. mastra-ai/mastra — 22,000+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets