🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@mastra/brightdata

Package Overview
Dependencies
Maintainers
6
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
This package has malicious versions linked to the ongoing "Mastra AI framework compromise" supply chain attack.

Affected versions:

0.2.2
View campaign page

@mastra/brightdata

Bright Data web search and web fetch tools for Mastra agents

latest
Source
npmnpm
Version
0.3.0
Version published
Weekly downloads
1.3K
74.29%
Maintainers
6
Weekly downloads
 
Created
Source

@mastra/brightdata

Bright Data web search and web fetch tools for Mastra agents.

Backed by the official @brightdata/sdk. Bright Data's SERP API and Web Unlocker bypass bot detection and CAPTCHAs, so the tools work on sites that block typical scrapers.

Installation

npm install @mastra/brightdata zod

Quick Start

Use createBrightDataTools() to get both tools with a shared configuration:

import { Agent } from '@mastra/core/agent';
import { createBrightDataTools } from '@mastra/brightdata';

const tools = createBrightDataTools();
// Or pass an explicit API token:
// const tools = createBrightDataTools({ apiKey: 'brd_...' });

const agent = new Agent({
  id: 'realtime-information-agent',
  name: 'Realtime Information Agent',
  instructions:
    'You are a realtime information agent. Use brightdata-search to find pages, and brightdata-fetch to read them.',
  model: 'anthropic/claude-sonnet-4-6',
  tools,
});

By default the tools read BRIGHTDATA_API_TOKEN from your environment. You can also pass { apiKey } explicitly.

Individual Tools

Each tool can be created independently:

import { createBrightDataSearchTool, createBrightDataFetchTool } from '@mastra/brightdata';

const search = createBrightDataSearchTool({ apiKey: 'brd_...' });
const fetch = createBrightDataFetchTool(); // uses BRIGHTDATA_API_TOKEN env var
import { createBrightDataSearchTool } from '@mastra/brightdata';

const searchTool = createBrightDataSearchTool();

// When called by an agent, accepts:
// - query (required)
// - country: 2-letter code (e.g., 'us', 'gb')
// - start: result offset for pagination (e.g. 10 for the second page of 10 results)
//
// Returns:
// {
//   query: string,
//   results: Array<{ link, title, description }>,
//   currentPage: number
// }

Web Fetch (brightdata-fetch)

import { createBrightDataFetchTool } from '@mastra/brightdata';

const fetchTool = createBrightDataFetchTool();

// Accepts: url (required)
// Returns: { url, content }  // content is Markdown

Configuration

OptionTypeDefaultDescription
apiKeystringprocess.env.BRIGHTDATA_API_TOKENYour Bright Data API token

All tools accept the full BrightDataClientOptions from @brightdata/sdk (including timeout, webUnlockerZone, serpZone, rateLimit, etc.). If no API token is found, the tool throws a clear error at execution time.

RAG Pairing Example

Combine search and fetch for retrieval-augmented generation:

import { Agent } from '@mastra/core/agent';
import { createBrightDataTools } from '@mastra/brightdata';

const agent = new Agent({
  id: 'rag-agent',
  name: 'Research Assistant',
  model: 'anthropic/claude-sonnet-4-6',
  instructions: `You are a research assistant. Use brightdata-search to find relevant pages, then use brightdata-fetch to get full Markdown content from the best results.`,
  tools: createBrightDataTools(),
});

License

Apache-2.0

Keywords

mastra

FAQs

Package last updated on 19 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts