-
-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathbrightdata-unit-test.test.ts
More file actions
143 lines (117 loc) · 5.28 KB
/
brightdata-unit-test.test.ts
File metadata and controls
143 lines (117 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { describe, test, expect, beforeAll, afterAll } from "vitest";
import { MCPClientManager } from "@mcpjam/sdk";
import "dotenv/config";
// Use token in URL as per BrightData docs
const BRIGHTDATA_URL = `https://mcp.brightdata.com/mcp?token=${process.env.BRIGHTDATA_API_TOKEN}&groups=ecommerce`;
const BRIGHTDATA_CONFIG = {
url: BRIGHTDATA_URL,
};
describe("SDK Feature: connectToServer", () => {
test("connects to MCP server with URL + token param", async () => {
if (!process.env.BRIGHTDATA_API_TOKEN) {
throw new Error("BRIGHTDATA_API_TOKEN environment variable is required");
}
const clientManager = new MCPClientManager();
await clientManager.connectToServer("brightdata-ecommerce", BRIGHTDATA_CONFIG);
expect(clientManager.getConnectionStatus("brightdata-ecommerce")).toBe("connected");
await clientManager.disconnectServer("brightdata-ecommerce");
});
});
describe("SDK Feature: getServerCapabilities", () => {
test("returns server capabilities with tools", async () => {
if (!process.env.BRIGHTDATA_API_TOKEN) {
throw new Error("BRIGHTDATA_API_TOKEN environment variable is required");
}
const clientManager = new MCPClientManager();
await clientManager.connectToServer("brightdata-ecommerce", BRIGHTDATA_CONFIG);
const capabilities = clientManager.getServerCapabilities("brightdata-ecommerce");
expect(capabilities).toBeDefined();
expect(typeof capabilities).toBe("object");
expect(capabilities?.tools).toBeDefined();
await clientManager.disconnectServer("brightdata-ecommerce");
});
});
describe("SDK Features with shared connection", () => {
let clientManager: MCPClientManager;
beforeAll(async () => {
if (!process.env.BRIGHTDATA_API_TOKEN) {
throw new Error("BRIGHTDATA_API_TOKEN environment variable is required");
}
clientManager = new MCPClientManager();
await clientManager.connectToServer("brightdata-ecommerce", BRIGHTDATA_CONFIG);
});
afterAll(async () => {
if (clientManager) {
await clientManager.disconnectServer("brightdata-ecommerce");
}
});
test("SDK Feature: getServerSummaries - lists all servers with id, status, config", () => {
const summaries = clientManager.getServerSummaries();
expect(summaries).toBeDefined();
expect(Array.isArray(summaries)).toBe(true);
expect(summaries.length).toBeGreaterThan(0);
const brightdataSummary = summaries.find((s) => s.id === "brightdata-ecommerce");
expect(brightdataSummary).toBeDefined();
expect(brightdataSummary?.status).toBe("connected");
expect(brightdataSummary?.config).toBeDefined();
});
test("SDK Feature: pingServer - verifies server is responsive", async () => {
await expect(
clientManager.pingServer("brightdata-ecommerce")
).resolves.toEqual({});
});
test("SDK Feature: listTools - returns available ecommerce tools", async () => {
const tools = await clientManager.listTools("brightdata-ecommerce");
expect(tools).toBeDefined();
expect(tools.tools).toBeDefined();
expect(Array.isArray(tools.tools)).toBe(true);
expect(tools.tools.length).toBeGreaterThan(0);
// Verify ecommerce tools are present
const toolNames = tools.tools.map((tool) => tool.name);
expect(toolNames).toContain("web_data_amazon_product_search");
expect(toolNames).toContain("web_data_amazon_product");
expect(toolNames).toContain("web_data_amazon_product_reviews");
expect(toolNames).toContain("web_data_walmart_product");
expect(toolNames).toContain("web_data_walmart_seller");
expect(toolNames).toContain("web_data_ebay_product");
expect(toolNames).toContain("web_data_homedepot_products");
expect(toolNames).toContain("web_data_zara_products");
expect(toolNames).toContain("web_data_etsy_products");
expect(toolNames).toContain("web_data_bestbuy_products");
expect(toolNames).toContain("web_data_google_shopping");
// Verify tool structure
const amazonTool = tools.tools.find((t) => t.name === "web_data_amazon_product_search");
expect(amazonTool).toHaveProperty("name");
expect(amazonTool).toHaveProperty("description");
expect(amazonTool).toHaveProperty("inputSchema");
});
test("SDK Feature: executeTool - runs web_data_amazon_product_search tool", async () => {
const result = await clientManager.executeTool(
"brightdata-ecommerce",
"web_data_amazon_product_search",
{
keyword: "headphones",
url: "https://www.amazon.com",
},
);
// Verify SDK returns proper MCP response structure
expect("content" in result).toBe(true);
if (!("content" in result)) {
throw new Error("Expected result to have content property");
}
const content = (
result as { content: Array<{ type: string; text: string }> }
).content;
expect(Array.isArray(content)).toBe(true);
expect(content.length).toBeGreaterThan(0);
const firstContent = content[0];
expect(firstContent).toHaveProperty("type");
expect(firstContent.type).toBe("text");
expect(firstContent).toHaveProperty("text");
expect(typeof firstContent.text).toBe("string");
expect(firstContent.text.length).toBeGreaterThan(0);
// Verify tool executed successfully (no error)
const hasError = (result as { isError?: boolean }).isError;
expect(hasError).not.toBe(true);
});
});