Skip to main content

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

Set these as environment variables:
All factory functions read TAVILY_API_KEY by default. You can override per tool by passing { apiKey }.

Step 3: Create Tavily Tools

Use createTavilyTools() to get all four tools with shared configuration:
Each tool can also be created individually when you only need one:

Step 4: Wire Tools into a Mastra Agent

Available Tools

Real-time web search. Tool ID: tavily-search.
Key input options:
  • query (required) — the search query
  • searchDepth"basic", "advanced", "fast", or "ultra-fast"
  • maxResults — 1–20
  • includeAnswerboolean, "basic", or "advanced" for an AI-generated summary
  • includeImages, includeImageDescriptions
  • includeRawContentfalse, "markdown", or "text"
  • includeDomains, excludeDomains — string arrays
  • timeRange"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.
Key input options:
  • urls (required) — 1–20 URLs
  • extractDepth"basic" or "advanced" (use "advanced" for tables and embedded content)
  • query — user intent used to rerank extracted chunks
  • includeImages
  • format"markdown" (default) or "text"

Tavily Crawl

Crawl a website from a starting URL with configurable depth, breadth, and domain constraints. Tool ID: tavily-crawl.
Key input options:
  • url (required) — root URL for the crawl
  • maxDepth, maxBreadth, limit
  • instructions — natural-language crawling hints
  • selectPaths, selectDomains, excludePaths, excludeDomains — regex arrays
  • allowExternal
  • extractDepth, includeImages, format

Tavily Map

Discover site structure without extracting content — returns a list of URLs. Tool ID: tavily-map.
Key input options:
  • url (required) — root URL for the map
  • maxDepth, maxBreadth, limit
  • instructions
  • selectPaths, selectDomains, excludePaths, excludeDomains
  • allowExternal

Configuration

All factory functions accept the same TavilyClientOptions:
  • apiKey — falls back to the TAVILY_API_KEY environment variable
  • clientSource — attribution string sent with each request (defaults to "mastra")
  • apiBaseURL — override the Tavily API base URL
  • proxies — proxy configuration for the underlying HTTP client
  • projectId — 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

Benefits of Tavily + Mastra

  • First-class tools: drop-in createTool()-compatible factories with Zod input/output schemas.
  • Lazy, cached client: each tool instantiates @tavily/core on first use and reuses it across calls.