Tavily tools
Added in: @mastra/tavily@0.1.0-alpha.0
The @mastra/tavily package wraps the Tavily API as Mastra-compatible tools. It exposes factory functions for search, extract, crawl, and map — each returning a tool created with createTool() that includes full Zod input/output schemas.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/tavily @tavily/core zod
pnpm add @mastra/tavily @tavily/core zod
yarn add @mastra/tavily @tavily/core zod
bun add @mastra/tavily @tavily/core zod
Quick startDirect link to Quick start
Use createTavilyTools() to get all four tools with shared configuration:
import { createTavilyTools } from '@mastra/tavily'
const tools = createTavilyTools()
// Or pass an explicit API key:
// const tools = createTavilyTools({ apiKey: 'tvly-...' })
Each tool can also be created individually:
import { createTavilySearchTool, createTavilyExtractTool } from '@mastra/tavily'
const searchTool = createTavilySearchTool()
const extractTool = createTavilyExtractTool({ apiKey: 'tvly-...' })
By default, all tools read TAVILY_API_KEY from the environment. You can pass { apiKey } explicitly to override.
ConfigurationDirect link to Configuration
All factory functions accept TavilyClientOptions from @tavily/core:
apiKey?:
clientSource?:
apiBaseURL?:
proxies?:
projectId?:
createTavilyTools()Direct link to createtavilytools
Returns an object containing all four tools with a shared configuration.
import { createTavilyTools } from '@mastra/tavily'
const tools = createTavilyTools({ apiKey: 'tvly-...' })
// tools.tavilySearch, tools.tavilyExtract, tools.tavilyCrawl, tools.tavilyMap
Returns: { tavilySearch, tavilyExtract, tavilyCrawl, tavilyMap }
createTavilySearchTool()Direct link to createtavilysearchtool
Creates a tool that searches the web using Tavily. Returns relevant results with content snippets, optional AI-generated answers, and images.
Tool ID: tavily-search
import { createTavilySearchTool } from '@mastra/tavily'
const searchTool = createTavilySearchTool()
InputDirect link to Input
query:
searchDepth?:
maxResults?:
includeAnswer?:
includeImages?:
includeImageDescriptions?:
includeRawContent?:
includeDomains?:
excludeDomains?:
timeRange?:
OutputDirect link to Output
query:
answer?:
images?:
results:
title:
url:
content:
score:
rawContent?:
responseTime:
createTavilyExtractTool()Direct link to createtavilyextracttool
Creates a tool that extracts content from one or more URLs. Returns raw page content in markdown or text format with up to 20 URLs per request.
Tool ID: tavily-extract
import { createTavilyExtractTool } from '@mastra/tavily'
const extractTool = createTavilyExtractTool()
InputDirect link to Input
urls:
extractDepth?:
query?:
includeImages?:
format?:
OutputDirect link to Output
results:
url:
rawContent:
images?:
failedResults:
url:
error:
responseTime:
createTavilyCrawlTool()Direct link to createtavilycrawltool
Creates a tool that crawls a website starting from a URL. Extracts content from discovered pages with configurable depth, breadth, and domain constraints.
Tool ID: tavily-crawl
import { createTavilyCrawlTool } from '@mastra/tavily'
const crawlTool = createTavilyCrawlTool()
InputDirect link to Input
url:
maxDepth?:
maxBreadth?:
limit?:
instructions?:
selectPaths?:
selectDomains?:
excludePaths?:
excludeDomains?:
allowExternal?:
extractDepth?:
includeImages?:
format?:
OutputDirect link to Output
baseUrl:
results:
url:
rawContent:
images?:
responseTime:
createTavilyMapTool()Direct link to createtavilymaptool
Creates a tool that maps a website's structure starting from a URL. Discovers and returns a list of URLs without extracting page content. Use this to understand site structure before targeted extraction.
Tool ID: tavily-map
import { createTavilyMapTool } from '@mastra/tavily'
const mapTool = createTavilyMapTool()
InputDirect link to Input
url:
maxDepth?:
maxBreadth?:
limit?:
instructions?:
selectPaths?:
selectDomains?:
excludePaths?:
excludeDomains?:
allowExternal?:
OutputDirect link to Output
baseUrl:
results:
responseTime:
Agent exampleDirect link to Agent example
The following example demonstrates a research agent that combines search and extract:
import { Agent } from '@mastra/core/agent'
import { createTavilySearchTool, createTavilyExtractTool } from '@mastra/tavily'
const agent = new Agent({
id: 'web-search-agent',
name: 'Web Search Agent',
model: 'anthropic/claude-sonnet-4-6',
instructions:
'You are a web search assistant. Use search tool to find relevant pages, then use extract tool to get full content from the best results.',
tools: {
search: createTavilySearchTool(),
extract: createTavilyExtractTool(),
},
})
Environment variablesDirect link to Environment variables
| Variable | Description |
|---|---|
TAVILY_API_KEY | Your Tavily API key. Used as the default when apiKey is not passed to a factory function. |