Bright Data
The @mastra/brightdata package wraps the Bright Data SDK as Mastra-compatible tools. It exposes factory functions for web search and web fetch. Each function returns 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.
InstallationInstallation的直接链接
- 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 startQuick 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.
ConfigurationConfiguration的直接链接
All factory functions accept BrightDataClientOptions from @brightdata/sdk:
apiKey?:
BRIGHTDATA_API_TOKEN environment variable.Additional fields supported by the bdclient constructor (such as timeout, webUnlockerZone, serpZone, and rateLimit) can be passed through the same options object.
createBrightDataTools()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()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()
InputInput的直接链接
query:
country?:
us or gb).start?:
10 returns the second page of 10 results.OutputOutput的直接链接
query:
results:
link:
title:
description:
currentPage:
1 when the upstream response omits or returns a non-positive value.createBrightDataFetchTool()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()
InputInput的直接链接
url:
OutputOutput的直接链接
url:
content:
Agent exampleAgent 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 variablesEnvironment variables的直接链接
| Variable | Description |
|---|---|
BRIGHTDATA_API_TOKEN | Your Bright Data API token. Used as the default when apiKey isn't passed to a factory function. |