Introduction
Mastra is a TypeScript framework for building AI agents and workflows. The@mastra/tavily package exposes Tavily’s Search, Extract, Crawl, and Map APIs as Mastra-compatible tools with Zod-based input/output schemas.
For full reference docs, please refer to the Mastra documentation.
Step-by-Step Integration Guide
Step 1: Install Required Packages
Step 2: Set Up API Keys
- Tavily API Key: Get your Tavily API key here
- Anthropic API Key (or any Mastra-supported provider): Get an Anthropic API key here
TAVILY_API_KEY by default. You can override per tool by passing { apiKey }.
Step 3: Create Tavily Tools
UsecreateTavilyTools() to get all four tools with shared configuration:
Step 4: Wire Tools into a Mastra Agent
Available Tools
Tavily Search
Real-time web search. Tool ID:tavily-search.
query(required) — the search querysearchDepth—"basic","advanced","fast", or"ultra-fast"maxResults— 1–20includeAnswer—boolean,"basic", or"advanced"for an AI-generated summaryincludeImages,includeImageDescriptionsincludeRawContent—false,"markdown", or"text"includeDomains,excludeDomains— string arraystimeRange—"day","week","month", or"year"
Tavily Extract
Clean, structured content extraction from one or more URLs (up to 20 per request). Tool ID:tavily-extract.
urls(required) — 1–20 URLsextractDepth—"basic"or"advanced"(use"advanced"for tables and embedded content)query— user intent used to rerank extracted chunksincludeImagesformat—"markdown"(default) or"text"
Tavily Crawl
Crawl a website from a starting URL with configurable depth, breadth, and domain constraints. Tool ID:tavily-crawl.
url(required) — root URL for the crawlmaxDepth,maxBreadth,limitinstructions— natural-language crawling hintsselectPaths,selectDomains,excludePaths,excludeDomains— regex arraysallowExternalextractDepth,includeImages,format
Tavily Map
Discover site structure without extracting content — returns a list of URLs. Tool ID:tavily-map.
url(required) — root URL for the mapmaxDepth,maxBreadth,limitinstructionsselectPaths,selectDomains,excludePaths,excludeDomainsallowExternal
Configuration
All factory functions accept the sameTavilyClientOptions:
apiKey— falls back to theTAVILY_API_KEYenvironment variableclientSource— attribution string sent with each request (defaults to"mastra")apiBaseURL— override the Tavily API base URLproxies— proxy configuration for the underlying HTTP clientprojectId— Tavily project ID for request scoping
Using Multiple Tools Together
Combine tools for richer research workflows — for example, map a site first, then crawl the paths you care about:Environment Variables
| Variable | Description |
|---|---|
TAVILY_API_KEY | Your Tavily API key. Used as the default when apiKey is not passed to a factory function. |
Benefits of Tavily + Mastra
- First-class tools: drop-in
createTool()-compatible factories with Zod input/output schemas. - Lazy, cached client: each tool instantiates
@tavily/coreon first use and reuses it across calls.