mastra

Mastra TypeScript framework for AI agents with memory, tools, workflows, and RAG. Use when working with @mastra/* packages or building AI agents.

1,481 stars

Best use case

mastra is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Mastra TypeScript framework for AI agents with memory, tools, workflows, and RAG. Use when working with @mastra/* packages or building AI agents.

Teams using mastra should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/mastra/SKILL.md --create-dirs "https://raw.githubusercontent.com/hashintel/hash/main/.claude/skills/mastra/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/mastra/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How mastra Compares

Feature / AgentmastraStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Mastra TypeScript framework for AI agents with memory, tools, workflows, and RAG. Use when working with @mastra/* packages or building AI agents.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Mastra Framework

Open-source TypeScript framework for building AI agents with memory, tools, workflows, and RAG capabilities. Fetch the relevant documentation URL below to get current API details.

## Documentation Entry Points

### Getting Started and Installation

https://mastra.ai/docs/v1/getting-started/installation

Covers: create-mastra CLI, project setup wizard, Node.js 20+ prerequisites, LLM provider API keys, Studio interface (localhost:4111), manual installation, TypeScript config, example weather agent

### Building Agents

https://mastra.ai/docs/v1/agents/overview

Covers: Agent definition with LLMs and tools, instruction formats (string/array/system message), provider options, agent registration in Mastra instance, generate() vs stream() methods, structured output with Zod schemas, maxSteps parameter, image processing, onStepFinish callbacks, RuntimeContext for request-specific behavior

### Agent Memory

https://mastra.ai/docs/v1/memory/overview

Covers: Three memory types (working memory, conversation history, semantic recall), thread-scoped vs resource-scoped memory, storage adapters (LibSQL, MongoDB, Postgres, Upstash), context management, memory processors for token limits, tracing integration

### Creating Tools

https://mastra.ai/docs/v1/agents/using-tools

Covers: Tool definition (inputSchema, outputSchema, execute), loading tools from MCP servers, RuntimeContext in tools, AbortSignal for cancellation, AI SDK tool format compatibility, Studio testing

### Workflows (Deterministic Pipelines)

https://mastra.ai/docs/v1/workflows/overview

Covers: createStep() with input/output schemas, .then() chaining, .commit() finalization, workflow state sharing, nested workflows, .start() vs .stream() execution, suspend/resume, automatic restart, status tracking (running/suspended/success/failed)

### RAG (Retrieval-Augmented Generation)

https://mastra.ai/docs/v1/rag/overview

Covers: MDocument for document processing, chunking strategies (recursive, sliding window), embedding generation, vector stores (pgvector, Pinecone, Qdrant, MongoDB), similarity search, cost monitoring, query pattern analysis

### MCP (Model Context Protocol)

https://mastra.ai/docs/v1/mcp/overview

Covers: MCPClient (connect to MCP servers), MCPServer (expose Mastra tools), static vs dynamic tools configuration, local packages vs remote HTTP endpoints, serverless deployment (Cloudflare Workers, Vercel, Lambda), MCP registry integration (Klavis AI, mcp.run, Composio, Smithery)

### Voice Capabilities

https://mastra.ai/docs/v1/voice/overview

Covers: Text-to-Speech (TTS), Speech-to-Text (STT), Speech-to-Speech (real-time), providers (OpenAI, Azure, ElevenLabs, PlayAI, Google, Deepgram, Cloudflare), CompositeVoice for mixing providers, OpenAI Realtime, Google Gemini Live

### Streaming

https://mastra.ai/docs/v1/streaming/overview

Covers: .stream() (V2/AI SDK v5) vs .streamLegacy() (V1/AI SDK v4), textStream iteration, stream properties (text, finishReason, usage), Agent.network() for multi-agent, workflow event streaming, Run.streamVNext()

### Deployment

https://mastra.ai/docs/v1/deployment/overview

Covers: Mastra Cloud (managed platform), web framework integration (Next.js, Astro), Node.js HTTP server, serverless deployers (Cloudflare Workers, Vercel, Netlify), runtime compatibility (Node 20+, Bun, Deno), Client SDK

### Observability and Tracing

https://mastra.ai/docs/v1/observability/overview

Covers: Structured logging with trace correlation, AI tracing (LLM calls, agent paths, tool calls, workflow steps), token usage/latency tracking, external providers (Langfuse, Braintrust, Datadog, New Relic, SigNoz), Studio/Cloud dashboards

## Quick API Reference

| Class/Function   | Reference                                              |
| ---------------- | ------------------------------------------------------ |
| Agent            | https://mastra.ai/reference/v1/agents/agent            |
| Agent.generate() | https://mastra.ai/reference/v1/agents/generate         |
| Agent.stream()   | https://mastra.ai/reference/v1/streaming/agents/stream |
| Workflow         | https://mastra.ai/reference/v1/workflows/workflow      |
| Memory           | https://mastra.ai/reference/v1/memory/memory-class     |
| createTool()     | https://mastra.ai/reference/v1/tools/create-tool       |
| MCPClient        | https://mastra.ai/reference/v1/tools/mcp-client        |
| MCPServer        | https://mastra.ai/reference/v1/tools/mcp-server        |

## Gotchas

- Workflows vs Workflows (Legacy): Prefer non-legacy. Legacy uses different API patterns.
- generate() vs stream(): Use stream() for real-time token delivery; generate() waits for complete response
- stream() vs streamLegacy(): stream() is V2 (AI SDK v5), streamLegacy() is V1 (AI SDK v4)
- Memory storage: Requires explicit storage backend (LibSQL, Postgres, etc.) - not automatic
- maxSteps default: Agent maxSteps defaults to 5 - increase for complex multi-tool tasks
- MCP tools: Use getTools() for static single-user, getToolsets() for multi-tenant with varying credentials

Related Skills

zod

1481
from hashintel/hash

Zod v4 TypeScript schema validation patterns and best practices. Use when writing or modifying Zod schemas, adding schema annotations/metadata, or validating data with Zod.

writing-hashql-jexpr

1481
from hashintel/hash

HashQL J-Expr syntax for writing queries. Use when writing J-Expr code, using #literal/#struct/#list constructs, understanding function call syntax, or working with HashQL query files (.jsonc).

writing-hashql-diagnostics

1481
from hashintel/hash

HashQL diagnostic writing patterns using hashql-diagnostics crate. Use when creating error messages, warnings, Labels, Messages, Severity levels, Patches, Suggestions, or improving diagnostic quality in HashQL code.

testing-hashql

1481
from hashintel/hash

HashQL testing strategies including compiletest (UI tests), unit tests, and snapshot tests. Use when writing tests for HashQL code, using //~ annotations, running --bless, debugging test failures, or choosing the right testing approach.

skill-creator

1481
from hashintel/hash

Guide for creating effective Agent Skills. Use when users want to create a new skill (or update an existing skill) that extends an AI agent's capabilities with specialized knowledge, workflows, or tool integrations. Covers skill structure, YAML frontmatter, trigger configuration, and the 500-line rule.

panda-css

1481
from hashintel/hash

Panda CSS styling framework guidance. Use when working with @pandacss packages, styled components, design tokens, or responsive/conditional styles.

managing-git-workflow

1481
from hashintel/hash

Git workflow for HASH including branch naming, PR creation, and PR reviews. Use when creating branches, making commits, opening pull requests, or reviewing PRs.

managing-cargo-dependencies

1481
from hashintel/hash

Cargo.toml dependency management patterns for HASH workspace. Use when adding, updating, or removing dependencies, organizing Cargo.toml sections, configuring version pinning and default features, or managing public dependencies.

handling-rust-errors

1481
from hashintel/hash

HASH error handling patterns using error-stack crate. Use when working with Result types, Report types, defining custom errors, propagating errors with change_context, adding context with attach, implementing Error trait, or documenting error conditions in Rust code.

exploring-rust-crates

1481
from hashintel/hash

Generate Rust documentation to understand crate APIs, structure, and usage. Use when exploring Rust code, understanding crate organization, finding functions/types/traits, or needing context about a Rust package in the HASH workspace.

documenting-rust-code

1481
from hashintel/hash

Rust documentation practices for HASH codebase. Use when writing doc comments, documenting functions/types/traits/modules, creating error sections, using intra-doc links, or following rustdoc conventions.

ark-ui

1481
from hashintel/hash

Headless component library for React. Use when building UI components with @ark-ui/react, implementing accessible form inputs, overlays, navigation patterns, or needing guidance on Ark UI's data attributes, composition (asChild), and state management patterns.