@mastra/brightdata 0.0.0-observability-branches-20260512155417

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,53 @@
1
+ # @mastra/brightdata
2
+
3
+ ## 0.0.0-observability-branches-20260512155417
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `@mastra/brightdata` integration with `brightdata-search` and `brightdata-fetch` tools backed by Bright Data's SERP API and Web Unlocker. The tools bypass bot detection and CAPTCHAs out of the box. ([#16392](https://github.com/mastra-ai/mastra/pull/16392))
8
+
9
+ ```typescript
10
+ import { Agent } from '@mastra/core/agent';
11
+ import { createBrightDataTools } from '@mastra/brightdata';
12
+
13
+ const agent = new Agent({
14
+ id: 'research-agent',
15
+ name: 'Research Agent',
16
+ model: 'anthropic/claude-sonnet-4-6',
17
+ instructions: 'Use brightdata-search to find pages and brightdata-fetch to read them.',
18
+ tools: createBrightDataTools(),
19
+ });
20
+ ```
21
+
22
+ Set `BRIGHTDATA_API_TOKEN` in your environment, or pass `{ apiKey }` explicitly.
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`ac47842`](https://github.com/mastra-ai/mastra/commit/ac478427aa7a5f5fdaed633a911218689b438c60), [`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`ce01024`](https://github.com/mastra-ai/mastra/commit/ce010242eee9bdfc09e4c26725b9d37998679a8d), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`8373ff4`](https://github.com/mastra-ai/mastra/commit/8373ff46745d77af79f183c4470f80fa2727a6b2), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`11c1528`](https://github.com/mastra-ai/mastra/commit/11c152848c5d0ef227184853b5040f5b41ee7b1e), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066), [`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
27
+ - @mastra/core@0.0.0-observability-branches-20260512155417
28
+
29
+ ## 0.2.0-alpha.0
30
+
31
+ ### Minor Changes
32
+
33
+ - Added `@mastra/brightdata` integration with `brightdata-search` and `brightdata-fetch` tools backed by Bright Data's SERP API and Web Unlocker. The tools bypass bot detection and CAPTCHAs out of the box. ([#16392](https://github.com/mastra-ai/mastra/pull/16392))
34
+
35
+ ```typescript
36
+ import { Agent } from '@mastra/core/agent';
37
+ import { createBrightDataTools } from '@mastra/brightdata';
38
+
39
+ const agent = new Agent({
40
+ id: 'research-agent',
41
+ name: 'Research Agent',
42
+ model: 'anthropic/claude-sonnet-4-6',
43
+ instructions: 'Use brightdata-search to find pages and brightdata-fetch to read them.',
44
+ tools: createBrightDataTools(),
45
+ });
46
+ ```
47
+
48
+ Set `BRIGHTDATA_API_TOKEN` in your environment, or pass `{ apiKey }` explicitly.
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [[`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a)]:
53
+ - @mastra/core@1.33.0-alpha.12
package/LICENSE.md ADDED
@@ -0,0 +1,30 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
16
+ # Apache License 2.0
17
+
18
+ Copyright (c) 2025 Kepler Software, Inc.
19
+
20
+ Licensed under the Apache License, Version 2.0 (the "License");
21
+ you may not use this file except in compliance with the License.
22
+ You may obtain a copy of the License at
23
+
24
+ http://www.apache.org/licenses/LICENSE-2.0
25
+
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ See the License for the specific language governing permissions and
30
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # @mastra/brightdata
2
+
3
+ [Bright Data](https://brightdata.com) web search and web fetch tools for [Mastra](https://mastra.ai) agents.
4
+
5
+ Backed by the official [`@brightdata/sdk`](https://github.com/brightdata/sdk-js). Bright Data's SERP API and Web Unlocker bypass bot detection and CAPTCHAs, so the tools work on sites that block typical scrapers.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @mastra/brightdata zod
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ Use `createBrightDataTools()` to get both tools with a shared configuration:
16
+
17
+ ```typescript
18
+ import { Agent } from '@mastra/core/agent';
19
+ import { createBrightDataTools } from '@mastra/brightdata';
20
+
21
+ const tools = createBrightDataTools();
22
+ // Or pass an explicit API token:
23
+ // const tools = createBrightDataTools({ apiKey: 'brd_...' });
24
+
25
+ const agent = new Agent({
26
+ id: 'realtime-information-agent',
27
+ name: 'Realtime Information Agent',
28
+ instructions:
29
+ 'You are a realtime information agent. Use brightdata-search to find pages, and brightdata-fetch to read them.',
30
+ model: 'anthropic/claude-sonnet-4-6',
31
+ tools,
32
+ });
33
+ ```
34
+
35
+ By default the tools read `BRIGHTDATA_API_TOKEN` from your environment. You can also pass `{ apiKey }` explicitly.
36
+
37
+ ## Individual Tools
38
+
39
+ Each tool can be created independently:
40
+
41
+ ```typescript
42
+ import { createBrightDataSearchTool, createBrightDataFetchTool } from '@mastra/brightdata';
43
+
44
+ const search = createBrightDataSearchTool({ apiKey: 'brd_...' });
45
+ const fetch = createBrightDataFetchTool(); // uses BRIGHTDATA_API_TOKEN env var
46
+ ```
47
+
48
+ ### Web Search (`brightdata-search`)
49
+
50
+ ```typescript
51
+ import { createBrightDataSearchTool } from '@mastra/brightdata';
52
+
53
+ const searchTool = createBrightDataSearchTool();
54
+
55
+ // When called by an agent, accepts:
56
+ // - query (required)
57
+ // - country: 2-letter code (e.g., 'us', 'gb')
58
+ // - start: result offset for pagination (e.g. 10 for the second page of 10 results)
59
+ //
60
+ // Returns:
61
+ // {
62
+ // query: string,
63
+ // results: Array<{ link, title, description }>,
64
+ // currentPage: number
65
+ // }
66
+ ```
67
+
68
+ ### Web Fetch (`brightdata-fetch`)
69
+
70
+ ```typescript
71
+ import { createBrightDataFetchTool } from '@mastra/brightdata';
72
+
73
+ const fetchTool = createBrightDataFetchTool();
74
+
75
+ // Accepts: url (required)
76
+ // Returns: { url, content } // content is Markdown
77
+ ```
78
+
79
+ ## Configuration
80
+
81
+ | Option | Type | Default | Description |
82
+ |---|---|---|---|
83
+ | `apiKey` | `string` | `process.env.BRIGHTDATA_API_TOKEN` | Your Bright Data API token |
84
+
85
+ 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.
86
+
87
+ ## RAG Pairing Example
88
+
89
+ Combine search and fetch for retrieval-augmented generation:
90
+
91
+ ```typescript
92
+ import { Agent } from '@mastra/core/agent';
93
+ import { createBrightDataTools } from '@mastra/brightdata';
94
+
95
+ const agent = new Agent({
96
+ id: 'rag-agent',
97
+ name: 'Research Assistant',
98
+ model: 'anthropic/claude-sonnet-4-6',
99
+ 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.`,
100
+ tools: createBrightDataTools(),
101
+ });
102
+ ```
103
+
104
+ ## License
105
+
106
+ Apache-2.0
@@ -0,0 +1,6 @@
1
+ import { bdclient } from '@brightdata/sdk';
2
+ export type BrightDataClientOptions = ConstructorParameters<typeof bdclient>[0];
3
+ export type BrightDataClient = bdclient;
4
+ export declare function getBrightDataClient(config?: BrightDataClientOptions): BrightDataClient;
5
+ export declare function closeClient(client: BrightDataClient): Promise<void>;
6
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAChF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAExC,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,gBAAgB,CAQtF;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CASzE"}
@@ -0,0 +1,8 @@
1
+ import type { BrightDataClientOptions } from './client.js';
2
+ export declare function createBrightDataFetchTool(config?: BrightDataClientOptions): import("@mastra/core/tools").Tool<{
3
+ url: string;
4
+ }, {
5
+ url: string;
6
+ content: string;
7
+ }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-fetch", unknown>;
8
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAW3D,wBAAgB,yBAAyB,CAAC,MAAM,CAAC,EAAE,uBAAuB;;;;;gIAuBzE"}
package/dist/index.cjs ADDED
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ var sdk = require('@brightdata/sdk');
4
+ var tools = require('@mastra/core/tools');
5
+ var zod = require('zod');
6
+
7
+ // src/client.ts
8
+ function getBrightDataClient(config) {
9
+ const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;
10
+ if (!apiKey) {
11
+ throw new Error(
12
+ "Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var."
13
+ );
14
+ }
15
+ return new sdk.bdclient({ ...config, apiKey });
16
+ }
17
+ async function closeClient(client) {
18
+ const close = client.close;
19
+ if (typeof close === "function") {
20
+ try {
21
+ await close.call(client);
22
+ } catch {
23
+ }
24
+ }
25
+ }
26
+ var inputSchema = zod.z.object({
27
+ query: zod.z.string().describe("The search query"),
28
+ country: zod.z.string().length(2).optional().describe('2-letter country code for geo-targeted results (e.g., "us", "gb")'),
29
+ start: zod.z.number().int().nonnegative().optional().describe("Result offset for pagination (e.g. 10 to get the second page of 10 results)")
30
+ });
31
+ var outputSchema = zod.z.object({
32
+ query: zod.z.string(),
33
+ results: zod.z.array(
34
+ zod.z.object({
35
+ link: zod.z.string(),
36
+ title: zod.z.string(),
37
+ description: zod.z.string()
38
+ })
39
+ ),
40
+ currentPage: zod.z.number()
41
+ });
42
+ function createBrightDataSearchTool(config) {
43
+ return tools.createTool({
44
+ id: "brightdata-search",
45
+ description: "Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.",
46
+ inputSchema,
47
+ outputSchema,
48
+ execute: async (input) => {
49
+ const client = getBrightDataClient(config);
50
+ try {
51
+ const rawResponse = await client.search.google(input.query, {
52
+ country: input.country,
53
+ start: input.start
54
+ });
55
+ const response = typeof rawResponse === "string" ? JSON.parse(rawResponse) : rawResponse;
56
+ const organic = Array.isArray(response.organic) ? response.organic : [];
57
+ const results = organic.map((entry) => {
58
+ if (!entry || typeof entry !== "object") return null;
59
+ const e = entry;
60
+ const link = typeof e.link === "string" ? e.link.trim() : "";
61
+ const title = typeof e.title === "string" ? e.title.trim() : "";
62
+ const description = typeof e.description === "string" ? e.description.trim() : "";
63
+ if (!link || !title) return null;
64
+ return { link, title, description };
65
+ }).filter((r) => r !== null);
66
+ const parsedPage = Number(response.current_page);
67
+ const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;
68
+ return {
69
+ query: input.query,
70
+ results,
71
+ currentPage
72
+ };
73
+ } finally {
74
+ await closeClient(client);
75
+ }
76
+ }
77
+ });
78
+ }
79
+ var inputSchema2 = zod.z.object({
80
+ url: zod.z.string().url().describe("The URL to fetch")
81
+ });
82
+ var outputSchema2 = zod.z.object({
83
+ url: zod.z.string(),
84
+ content: zod.z.string().describe("Page content as Markdown")
85
+ });
86
+ function createBrightDataFetchTool(config) {
87
+ return tools.createTool({
88
+ id: "brightdata-fetch",
89
+ description: "Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.",
90
+ inputSchema: inputSchema2,
91
+ outputSchema: outputSchema2,
92
+ execute: async (input) => {
93
+ const client = getBrightDataClient(config);
94
+ try {
95
+ const content = await client.scrapeUrl(input.url, {
96
+ dataFormat: "markdown"
97
+ });
98
+ return {
99
+ url: input.url,
100
+ content
101
+ };
102
+ } finally {
103
+ await closeClient(client);
104
+ }
105
+ }
106
+ });
107
+ }
108
+
109
+ // src/tools.ts
110
+ function createBrightDataTools(config) {
111
+ return {
112
+ webSearch: createBrightDataSearchTool(config),
113
+ webFetch: createBrightDataFetchTool(config)
114
+ };
115
+ }
116
+
117
+ exports.createBrightDataFetchTool = createBrightDataFetchTool;
118
+ exports.createBrightDataSearchTool = createBrightDataSearchTool;
119
+ exports.createBrightDataTools = createBrightDataTools;
120
+ exports.getBrightDataClient = getBrightDataClient;
121
+ //# sourceMappingURL=index.cjs.map
122
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts","../src/tools.ts"],"names":["bdclient","z","createTool","inputSchema","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,CAAO,SAAA,CAAU,MAAM,GAAA,EAAK;AAAA,UAChD,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,KAAK,KAAA,CAAM,GAAA;AAAA,UACX;AAAA,SACF;AAAA,MACF,CAAA,SAAE;AACA,QAAA,MAAM,YAAY,MAAM,CAAA;AAAA,MAC1B;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;AClCO,SAAS,sBAAsB,MAAA,EAAkC;AACtE,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,2BAA2B,MAAM,CAAA;AAAA,IAC5C,QAAA,EAAU,0BAA0B,MAAM;AAAA,GAC5C;AACF","file":"index.cjs","sourcesContent":["import { bdclient } from '@brightdata/sdk';\n\nexport type BrightDataClientOptions = ConstructorParameters<typeof bdclient>[0];\nexport type BrightDataClient = bdclient;\n\nexport function getBrightDataClient(config?: BrightDataClientOptions): BrightDataClient {\n const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;\n if (!apiKey) {\n throw new Error(\n 'Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var.',\n );\n }\n return new bdclient({ ...config, apiKey });\n}\n\nexport async function closeClient(client: BrightDataClient): Promise<void> {\n const close = (client as { close?: () => Promise<void> | void }).close;\n if (typeof close === 'function') {\n try {\n await close.call(client);\n } catch {\n // best-effort cleanup; never mask the primary tool error from the finally block\n }\n }\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n country: z\n .string()\n .length(2)\n .optional()\n .describe('2-letter country code for geo-targeted results (e.g., \"us\", \"gb\")'),\n start: z\n .number()\n .int()\n .nonnegative()\n .optional()\n .describe('Result offset for pagination (e.g. 10 to get the second page of 10 results)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n link: z.string(),\n title: z.string(),\n description: z.string(),\n }),\n ),\n currentPage: z.number(),\n});\n\nexport function createBrightDataSearchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-search',\n description:\n \"Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const rawResponse = await client.search.google(input.query, {\n country: input.country,\n start: input.start,\n });\n\n const response: { organic?: unknown; current_page?: unknown } =\n typeof rawResponse === 'string' ? JSON.parse(rawResponse) : rawResponse;\n\n const organic = Array.isArray(response.organic) ? response.organic : [];\n const results = organic\n .map((entry: unknown) => {\n if (!entry || typeof entry !== 'object') return null;\n const e = entry as Record<string, unknown>;\n const link = typeof e.link === 'string' ? e.link.trim() : '';\n const title = typeof e.title === 'string' ? e.title.trim() : '';\n const description = typeof e.description === 'string' ? e.description.trim() : '';\n if (!link || !title) return null;\n return { link, title, description };\n })\n .filter((r): r is { link: string; title: string; description: string } => r !== null);\n\n const parsedPage = Number(response.current_page);\n const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;\n\n return {\n query: input.query,\n results,\n currentPage,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL to fetch'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n content: z.string().describe('Page content as Markdown'),\n});\n\nexport function createBrightDataFetchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-fetch',\n description:\n \"Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const content = await client.scrapeUrl(input.url, {\n dataFormat: 'markdown',\n });\n\n return {\n url: input.url,\n content,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import type { BrightDataClientOptions } from './client.js';\nimport { createBrightDataFetchTool } from './fetch.js';\nimport { createBrightDataSearchTool } from './search.js';\n\nexport function createBrightDataTools(config?: BrightDataClientOptions) {\n return {\n webSearch: createBrightDataSearchTool(config),\n webFetch: createBrightDataFetchTool(config),\n };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export { getBrightDataClient, type BrightDataClientOptions, type BrightDataClient } from './client.js';
2
+ export { createBrightDataSearchTool } from './search.js';
3
+ export { createBrightDataFetchTool } from './fetch.js';
4
+ export { createBrightDataTools } from './tools.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,117 @@
1
+ import { bdclient } from '@brightdata/sdk';
2
+ import { createTool } from '@mastra/core/tools';
3
+ import { z } from 'zod';
4
+
5
+ // src/client.ts
6
+ function getBrightDataClient(config) {
7
+ const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;
8
+ if (!apiKey) {
9
+ throw new Error(
10
+ "Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var."
11
+ );
12
+ }
13
+ return new bdclient({ ...config, apiKey });
14
+ }
15
+ async function closeClient(client) {
16
+ const close = client.close;
17
+ if (typeof close === "function") {
18
+ try {
19
+ await close.call(client);
20
+ } catch {
21
+ }
22
+ }
23
+ }
24
+ var inputSchema = z.object({
25
+ query: z.string().describe("The search query"),
26
+ country: z.string().length(2).optional().describe('2-letter country code for geo-targeted results (e.g., "us", "gb")'),
27
+ start: z.number().int().nonnegative().optional().describe("Result offset for pagination (e.g. 10 to get the second page of 10 results)")
28
+ });
29
+ var outputSchema = z.object({
30
+ query: z.string(),
31
+ results: z.array(
32
+ z.object({
33
+ link: z.string(),
34
+ title: z.string(),
35
+ description: z.string()
36
+ })
37
+ ),
38
+ currentPage: z.number()
39
+ });
40
+ function createBrightDataSearchTool(config) {
41
+ return createTool({
42
+ id: "brightdata-search",
43
+ description: "Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.",
44
+ inputSchema,
45
+ outputSchema,
46
+ execute: async (input) => {
47
+ const client = getBrightDataClient(config);
48
+ try {
49
+ const rawResponse = await client.search.google(input.query, {
50
+ country: input.country,
51
+ start: input.start
52
+ });
53
+ const response = typeof rawResponse === "string" ? JSON.parse(rawResponse) : rawResponse;
54
+ const organic = Array.isArray(response.organic) ? response.organic : [];
55
+ const results = organic.map((entry) => {
56
+ if (!entry || typeof entry !== "object") return null;
57
+ const e = entry;
58
+ const link = typeof e.link === "string" ? e.link.trim() : "";
59
+ const title = typeof e.title === "string" ? e.title.trim() : "";
60
+ const description = typeof e.description === "string" ? e.description.trim() : "";
61
+ if (!link || !title) return null;
62
+ return { link, title, description };
63
+ }).filter((r) => r !== null);
64
+ const parsedPage = Number(response.current_page);
65
+ const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;
66
+ return {
67
+ query: input.query,
68
+ results,
69
+ currentPage
70
+ };
71
+ } finally {
72
+ await closeClient(client);
73
+ }
74
+ }
75
+ });
76
+ }
77
+ var inputSchema2 = z.object({
78
+ url: z.string().url().describe("The URL to fetch")
79
+ });
80
+ var outputSchema2 = z.object({
81
+ url: z.string(),
82
+ content: z.string().describe("Page content as Markdown")
83
+ });
84
+ function createBrightDataFetchTool(config) {
85
+ return createTool({
86
+ id: "brightdata-fetch",
87
+ description: "Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.",
88
+ inputSchema: inputSchema2,
89
+ outputSchema: outputSchema2,
90
+ execute: async (input) => {
91
+ const client = getBrightDataClient(config);
92
+ try {
93
+ const content = await client.scrapeUrl(input.url, {
94
+ dataFormat: "markdown"
95
+ });
96
+ return {
97
+ url: input.url,
98
+ content
99
+ };
100
+ } finally {
101
+ await closeClient(client);
102
+ }
103
+ }
104
+ });
105
+ }
106
+
107
+ // src/tools.ts
108
+ function createBrightDataTools(config) {
109
+ return {
110
+ webSearch: createBrightDataSearchTool(config),
111
+ webFetch: createBrightDataFetchTool(config)
112
+ };
113
+ }
114
+
115
+ export { createBrightDataFetchTool, createBrightDataSearchTool, createBrightDataTools, getBrightDataClient };
116
+ //# sourceMappingURL=index.js.map
117
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts","../src/tools.ts"],"names":["inputSchema","z","outputSchema","createTool"],"mappings":";;;;;AAKO,SAAS,oBAAoB,MAAA,EAAoD;AACtF,EAAA,MAAM,MAAA,GAAS,MAAA,EAAQ,MAAA,IAAU,OAAA,CAAQ,GAAA,CAAI,oBAAA;AAC7C,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAG,MAAA,EAAQ,QAAQ,CAAA;AAC3C;AAEA,eAAsB,YAAY,MAAA,EAAyC;AACzE,EAAA,MAAM,QAAS,MAAA,CAAkD,KAAA;AACjE,EAAA,IAAI,OAAO,UAAU,UAAA,EAAY;AAC/B,IAAA,IAAI;AACF,MAAA,MAAM,KAAA,CAAM,KAAK,MAAM,CAAA;AA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AAA,MAC1B;AAAA,IACF;AAAA,GACD,CAAA;AACH;ACvEA,IAAMA,YAAAA,GAAcC,EAAE,MAAA,CAAO;AAAA,EAC3B,KAAKA,CAAAA,CAAE,MAAA,GAAS,GAAA,EAAI,CAAE,SAAS,kBAAkB;AACnD,CAAC,CAAA;AAED,IAAMC,aAAAA,GAAeD,EAAE,MAAA,CAAO;AAAA,EAC5B,GAAA,EAAKA,EAAE,MAAA,EAAO;AAAA,EACd,OAAA,EAASA,CAAAA,CAAE,MAAA,EAAO,CAAE,SAAS,0BAA0B;AACzD,CAAC,CAAA;AAEM,SAAS,0BAA0B,MAAA,EAAkC;AAC1E,EAAA,OAAOE,UAAAA,CAAW;AAAA,IAChB,EAAA,EAAI,kBAAA;AAAA,IACJ,WAAA,EACE,0LAAA;AAAA,IACF,WAAA,EAAAH,YAAAA;AAAA,IACA,YAAA,EAAAE,aAAAA;AAAA,IACA,OAAA,EAAS,OAAM,KAAA,KAAS;AACtB,MAAA,MAAM,MAAA,GAAS,oBAAoB,MAAM,CAAA;AACzC,MAAA,IAAI;AACF,QAAA,MAAM,OAAA,GAAU,MAAM,MAAA,CAAO,SAAA,CAAU,MAAM,GAAA,EAAK;AAAA,UAChD,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,KAAK,KAAA,CAAM,GAAA;AAAA,UACX;AAAA,SACF;AAAA,MACF,CAAA,SAAE;AACA,QAAA,MAAM,YAAY,MAAM,CAAA;AAAA,MAC1B;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;AClCO,SAAS,sBAAsB,MAAA,EAAkC;AACtE,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,2BAA2B,MAAM,CAAA;AAAA,IAC5C,QAAA,EAAU,0BAA0B,MAAM;AAAA,GAC5C;AACF","file":"index.js","sourcesContent":["import { bdclient } from '@brightdata/sdk';\n\nexport type BrightDataClientOptions = ConstructorParameters<typeof bdclient>[0];\nexport type BrightDataClient = bdclient;\n\nexport function getBrightDataClient(config?: BrightDataClientOptions): BrightDataClient {\n const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;\n if (!apiKey) {\n throw new Error(\n 'Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var.',\n );\n }\n return new bdclient({ ...config, apiKey });\n}\n\nexport async function closeClient(client: BrightDataClient): Promise<void> {\n const close = (client as { close?: () => Promise<void> | void }).close;\n if (typeof close === 'function') {\n try {\n await close.call(client);\n } catch {\n // best-effort cleanup; never mask the primary tool error from the finally block\n }\n }\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n country: z\n .string()\n .length(2)\n .optional()\n .describe('2-letter country code for geo-targeted results (e.g., \"us\", \"gb\")'),\n start: z\n .number()\n .int()\n .nonnegative()\n .optional()\n .describe('Result offset for pagination (e.g. 10 to get the second page of 10 results)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n link: z.string(),\n title: z.string(),\n description: z.string(),\n }),\n ),\n currentPage: z.number(),\n});\n\nexport function createBrightDataSearchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-search',\n description:\n \"Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const rawResponse = await client.search.google(input.query, {\n country: input.country,\n start: input.start,\n });\n\n const response: { organic?: unknown; current_page?: unknown } =\n typeof rawResponse === 'string' ? JSON.parse(rawResponse) : rawResponse;\n\n const organic = Array.isArray(response.organic) ? response.organic : [];\n const results = organic\n .map((entry: unknown) => {\n if (!entry || typeof entry !== 'object') return null;\n const e = entry as Record<string, unknown>;\n const link = typeof e.link === 'string' ? e.link.trim() : '';\n const title = typeof e.title === 'string' ? e.title.trim() : '';\n const description = typeof e.description === 'string' ? e.description.trim() : '';\n if (!link || !title) return null;\n return { link, title, description };\n })\n .filter((r): r is { link: string; title: string; description: string } => r !== null);\n\n const parsedPage = Number(response.current_page);\n const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;\n\n return {\n query: input.query,\n results,\n currentPage,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL to fetch'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n content: z.string().describe('Page content as Markdown'),\n});\n\nexport function createBrightDataFetchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-fetch',\n description:\n \"Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const content = await client.scrapeUrl(input.url, {\n dataFormat: 'markdown',\n });\n\n return {\n url: input.url,\n content,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import type { BrightDataClientOptions } from './client.js';\nimport { createBrightDataFetchTool } from './fetch.js';\nimport { createBrightDataSearchTool } from './search.js';\n\nexport function createBrightDataTools(config?: BrightDataClientOptions) {\n return {\n webSearch: createBrightDataSearchTool(config),\n webFetch: createBrightDataFetchTool(config),\n };\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { BrightDataClientOptions } from './client.js';
2
+ export declare function createBrightDataSearchTool(config?: BrightDataClientOptions): import("@mastra/core/tools").Tool<{
3
+ query: string;
4
+ country?: string | undefined;
5
+ start?: number | undefined;
6
+ }, {
7
+ query: string;
8
+ results: {
9
+ link: string;
10
+ title: string;
11
+ description: string;
12
+ }[];
13
+ currentPage: number;
14
+ }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-search", unknown>;
15
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AA6B3D,wBAAgB,0BAA0B,CAAC,MAAM,CAAC,EAAE,uBAAuB;;;;;;;;;;;;iIA4C1E"}
@@ -0,0 +1,23 @@
1
+ import type { BrightDataClientOptions } from './client.js';
2
+ export declare function createBrightDataTools(config?: BrightDataClientOptions): {
3
+ webSearch: import("@mastra/core/tools").Tool<{
4
+ query: string;
5
+ country?: string | undefined;
6
+ start?: number | undefined;
7
+ }, {
8
+ query: string;
9
+ results: {
10
+ link: string;
11
+ title: string;
12
+ description: string;
13
+ }[];
14
+ currentPage: number;
15
+ }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-search", unknown>;
16
+ webFetch: import("@mastra/core/tools").Tool<{
17
+ url: string;
18
+ }, {
19
+ url: string;
20
+ content: string;
21
+ }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-fetch", unknown>;
22
+ };
23
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAI3D,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,uBAAuB;;;;;;;;;;;;;;;;;;;;EAKrE"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@mastra/brightdata",
3
+ "version": "0.0.0-observability-branches-20260512155417",
4
+ "description": "Bright Data web search and web fetch tools for Mastra agents",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "CHANGELOG.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "keywords": [
26
+ "mastra",
27
+ "brightdata",
28
+ "brightdata-search",
29
+ "brightdata-fetch",
30
+ "tools",
31
+ "ai-agent"
32
+ ],
33
+ "license": "Apache-2.0",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/mastra-ai/mastra.git",
37
+ "directory": "integrations/brightdata"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/mastra-ai/mastra/issues"
41
+ },
42
+ "homepage": "https://mastra.ai",
43
+ "engines": {
44
+ "node": ">=22.13.0"
45
+ },
46
+ "dependencies": {
47
+ "@brightdata/sdk": "^1.1.0"
48
+ },
49
+ "peerDependencies": {
50
+ "zod": ">=3.0.0",
51
+ "@mastra/core": "0.0.0-observability-branches-20260512155417"
52
+ },
53
+ "devDependencies": {
54
+ "tsup": "^8.5.1",
55
+ "typescript": "^6.0.3",
56
+ "vitest": "4.1.5",
57
+ "zod": "^4.3.6",
58
+ "@internal/lint": "0.0.0-observability-branches-20260512155417",
59
+ "@internal/types-builder": "0.0.0-observability-branches-20260512155417",
60
+ "@mastra/core": "0.0.0-observability-branches-20260512155417"
61
+ },
62
+ "scripts": {
63
+ "build:lib": "tsup --silent --config tsup.config.ts",
64
+ "build:watch": "pnpm build:lib --watch",
65
+ "lint": "eslint .",
66
+ "test": "vitest run"
67
+ }
68
+ }