Bright Data tools
The @mastra/brightdata package wraps the Bright Data SDK as Mastra-compatible tools. It exposes factory functions for web search and web fetch — each returning a tool created with createTool() that includes full Zod input/output schemas.
The search tool is backed by Bright Data's SERP API and the fetch tool by Web Unlocker. Both bypass bot detection and CAPTCHAs.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/brightdata zod
pnpm add @mastra/brightdata zod
yarn add @mastra/brightdata zod
bun add @mastra/brightdata zod
Quick startDirect link to Quick start
Use createBrightDataTools() to get both tools with shared configuration:
import { createBrightDataTools } from '@mastra/brightdata'
const { webSearch, webFetch } = createBrightDataTools()
// Or pass an explicit API key:
// const { webSearch, webFetch } = createBrightDataTools({ apiKey: 'brd-...' })
Each tool can also be created individually:
import { createBrightDataSearchTool, createBrightDataFetchTool } from '@mastra/brightdata'
const searchTool = createBrightDataSearchTool()
const fetchTool = createBrightDataFetchTool({ apiKey: 'brd-...' })
By default, all tools read BRIGHTDATA_API_TOKEN from the environment. You can pass { apiKey } explicitly to override.
ConfigurationDirect link to Configuration
All factory functions accept BrightDataClientOptions from @brightdata/sdk:
apiKey?:
Additional fields supported by the bdclient constructor (such as timeout, webUnlockerZone, serpZone, and rateLimit) can be passed through the same options object.
createBrightDataTools()Direct link to createbrightdatatools
Returns an object containing both tools with a shared configuration.
import { createBrightDataTools } from '@mastra/brightdata'
const tools = createBrightDataTools({ apiKey: 'brd-...' })
// tools.webSearch, tools.webFetch
Returns: { webSearch, webFetch }
createBrightDataSearchTool()Direct link to createbrightdatasearchtool
Creates a tool that searches Google through Bright Data's SERP API. Returns parsed organic results.
Tool ID: brightdata-search
import { createBrightDataSearchTool } from '@mastra/brightdata'
const searchTool = createBrightDataSearchTool()
InputDirect link to Input
query:
country?:
start?:
OutputDirect link to Output
query:
results:
link:
title:
description:
currentPage:
createBrightDataFetchTool()Direct link to createbrightdatafetchtool
Creates a tool that fetches a webpage through Bright Data's Web Unlocker and returns the page content as Markdown.
Tool ID: brightdata-fetch
import { createBrightDataFetchTool } from '@mastra/brightdata'
const fetchTool = createBrightDataFetchTool()
InputDirect link to Input
url:
OutputDirect link to Output
url:
content:
Agent exampleDirect link to Agent example
The following example demonstrates a research agent that combines search and fetch:
import { Agent } from '@mastra/core/agent'
import { createBrightDataTools } from '@mastra/brightdata'
const { webSearch, webFetch } = createBrightDataTools()
const agent = new Agent({
id: 'research-agent',
name: 'Research Agent',
model: 'anthropic/claude-sonnet-4-6',
instructions:
'You are a research assistant. Use the search tool to find relevant pages, then use the fetch tool to read full Markdown content from the best results.',
tools: {
webSearch,
webFetch,
},
})
Environment variablesDirect link to Environment variables
| Variable | Description |
|---|---|
BRIGHTDATA_API_TOKEN | Your Bright Data API token. Used as the default when apiKey is not passed to a factory function. |