brave-real-browser-mcp-server 2.7.4 → 2.7.6
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/dist/browser-manager.js +0 -14
- package/dist/index.js +78 -122
- package/dist/tool-definitions.js +14 -659
- package/package.json +1 -1
- package/dist/advanced/advanced-content-extraction.js +0 -435
- package/dist/advanced/advanced-content-extraction.test.js +0 -8
- package/dist/advanced/advanced-scraping.js +0 -301
- package/dist/ai/ai-features.js +0 -56
- package/dist/ai/ai-features.test.js +0 -18
- package/dist/ai/ai-tools.js +0 -390
- package/dist/api/api-integration-system.js +0 -68
- package/dist/api/api-integration-system.test.js +0 -29
- package/dist/api/api-integration.js +0 -371
- package/dist/auth/session-manager.js +0 -50
- package/dist/auth/session-manager.test.js +0 -8
- package/dist/captcha/advanced-captcha-handler.js +0 -45
- package/dist/captcha/advanced-captcha-handler.test.js +0 -8
- package/dist/captcha/captcha-handler.js +0 -374
- package/dist/extractors/content-type-extractors.js +0 -233
- package/dist/extractors/multi-element-extractors.js +0 -174
- package/dist/extractors/smart-data-extractors.js +0 -204
- package/dist/extractors/smart-data-extractors.test.js +0 -91
- package/dist/handlers/advanced-scraping-handlers.js +0 -333
- package/dist/handlers/advanced-scraping-handlers.test.js +0 -218
- package/dist/handlers/new-features-handlers.js +0 -209
- package/dist/handlers/new-features-handlers.test.js +0 -21
- package/dist/monitoring/monitoring-system.js +0 -53
- package/dist/monitoring/monitoring-system.test.js +0 -26
- package/dist/monitoring/monitoring-tools.js +0 -372
- package/dist/navigation/pagination-tools.js +0 -215
- package/dist/processors/data-processors.js +0 -250
- package/dist/processors/data-processors.test.js +0 -163
- package/dist/processors/data-transformation.js +0 -344
- package/dist/processors/data-transformation.test.js +0 -288
- package/dist/quality/data-quality-tools.js +0 -43
- package/dist/quality/data-quality-tools.test.js +0 -26
- package/dist/search/advanced-search-tools.js +0 -52
- package/dist/search/advanced-search-tools.test.js +0 -11
- package/dist/search/search-filter-tools.js +0 -339
- package/dist/visual/screenshot-tools.js +0 -47
- package/dist/visual/screenshot-tools.test.js +0 -8
- package/dist/visual/visual-tools.js +0 -516
package/dist/browser-manager.js
CHANGED
|
@@ -732,17 +732,3 @@ export function getContentPriorityConfig() {
|
|
|
732
732
|
export function updateContentPriorityConfig(config) {
|
|
733
733
|
contentPriorityConfig = { ...contentPriorityConfig, ...config };
|
|
734
734
|
}
|
|
735
|
-
// Alias for getPageInstance - for compatibility with advanced scraping handlers
|
|
736
|
-
export async function getBrowserPage() {
|
|
737
|
-
if (!pageInstance) {
|
|
738
|
-
throw new Error('Browser not initialized. Call browser_init first.');
|
|
739
|
-
}
|
|
740
|
-
return pageInstance;
|
|
741
|
-
}
|
|
742
|
-
// Synchronous version for compatibility with new-features-handlers
|
|
743
|
-
export function getCurrentPage() {
|
|
744
|
-
if (!pageInstance) {
|
|
745
|
-
throw new Error('Browser not initialized. Call browser_init first.');
|
|
746
|
-
}
|
|
747
|
-
return pageInstance;
|
|
748
|
-
}
|
package/dist/index.js
CHANGED
|
@@ -1,76 +1,80 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Debug logging
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
debug(`🔍 [DEBUG] Working directory: ${process.cwd()}`);
|
|
7
|
-
debug(`🔍 [DEBUG] Command args: ${process.argv.join(' ')}`);
|
|
2
|
+
// Debug logging setup - Log process start
|
|
3
|
+
console.error(`🔍 [DEBUG] Process starting - PID: ${process.pid}, Node: ${process.version}, Platform: ${process.platform}`);
|
|
4
|
+
console.error(`🔍 [DEBUG] Working directory: ${process.cwd()}`);
|
|
5
|
+
console.error(`🔍 [DEBUG] Command args: ${process.argv.join(' ')}`);
|
|
8
6
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
9
7
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
10
8
|
import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ListPromptsRequestSchema, InitializeRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
11
|
-
|
|
9
|
+
console.error('🔍 [DEBUG] MCP SDK imports completed successfully');
|
|
12
10
|
// Import extracted modules
|
|
13
|
-
|
|
11
|
+
console.error('🔍 [DEBUG] Loading tool definitions...');
|
|
14
12
|
import { TOOLS, SERVER_INFO, CAPABILITIES, TOOL_NAMES } from './tool-definitions.js';
|
|
15
|
-
|
|
13
|
+
console.error('🔍 [DEBUG] Loading system utils...');
|
|
16
14
|
import { withErrorHandling } from './system-utils.js';
|
|
17
|
-
|
|
15
|
+
console.error('🔍 [DEBUG] Loading browser manager...');
|
|
18
16
|
import { closeBrowser, forceKillAllChromeProcesses } from './browser-manager.js';
|
|
19
|
-
|
|
17
|
+
console.error('🔍 [DEBUG] Loading core infrastructure...');
|
|
20
18
|
import { setupProcessCleanup } from './core-infrastructure.js';
|
|
21
19
|
// Import handlers
|
|
22
|
-
|
|
20
|
+
console.error('🔍 [DEBUG] Loading handlers...');
|
|
23
21
|
import { handleBrowserInit, handleBrowserClose } from './handlers/browser-handlers.js';
|
|
24
22
|
import { handleNavigate, handleWait } from './handlers/navigation-handlers.js';
|
|
25
23
|
import { handleClick, handleType, handleSolveCaptcha, handleRandomScroll } from './handlers/interaction-handlers.js';
|
|
26
24
|
import { handleGetContent, handleFindSelector } from './handlers/content-handlers.js';
|
|
27
25
|
import { handleSaveContentAsMarkdown } from './handlers/file-handlers.js';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
debug(`🔍 [DEBUG] Available tools: ${TOOLS.length} tools loaded`);
|
|
26
|
+
console.error('🔍 [DEBUG] All modules loaded successfully');
|
|
27
|
+
console.error(`🔍 [DEBUG] Server info: ${JSON.stringify(SERVER_INFO)}`);
|
|
28
|
+
console.error(`🔍 [DEBUG] Available tools: ${TOOLS.length} tools loaded`);
|
|
32
29
|
// Initialize MCP server
|
|
33
|
-
|
|
30
|
+
console.error('🔍 [DEBUG] Creating MCP server instance...');
|
|
34
31
|
const server = new Server(SERVER_INFO, { capabilities: CAPABILITIES });
|
|
35
|
-
|
|
32
|
+
console.error('🔍 [DEBUG] MCP server instance created successfully');
|
|
36
33
|
// Register initialize handler (CRITICAL - missing handler can cause crash)
|
|
37
|
-
|
|
34
|
+
console.error('🔍 [DEBUG] Registering initialize handler...');
|
|
38
35
|
server.setRequestHandler(InitializeRequestSchema, async (request) => {
|
|
39
|
-
|
|
36
|
+
console.error(`🔍 [DEBUG] Initialize request received: ${JSON.stringify(request)}`);
|
|
40
37
|
// Use the client's protocol version to ensure compatibility
|
|
41
38
|
const clientProtocolVersion = request.params.protocolVersion;
|
|
42
|
-
|
|
39
|
+
console.error(`🔍 [DEBUG] Client protocol version: ${clientProtocolVersion}`);
|
|
43
40
|
const response = {
|
|
44
41
|
protocolVersion: clientProtocolVersion, // Match client version for compatibility
|
|
45
42
|
capabilities: CAPABILITIES,
|
|
46
43
|
serverInfo: SERVER_INFO,
|
|
47
44
|
};
|
|
48
|
-
|
|
45
|
+
console.error(`🔍 [DEBUG] Sending initialize response: ${JSON.stringify(response)}`);
|
|
46
|
+
// Add a small delay to see if there are any immediate errors after response
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
console.error(`🔍 [DEBUG] 1 second after initialize response - server still alive`);
|
|
49
|
+
}, 1000);
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
console.error(`🔍 [DEBUG] 5 seconds after initialize response - server still alive`);
|
|
52
|
+
}, 5000);
|
|
49
53
|
return response;
|
|
50
54
|
});
|
|
51
55
|
// Register tool handlers
|
|
52
|
-
|
|
56
|
+
console.error('🔍 [DEBUG] Registering tools handler...');
|
|
53
57
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
54
|
-
|
|
58
|
+
console.error('🔍 [DEBUG] Tools list requested');
|
|
55
59
|
return { tools: TOOLS };
|
|
56
60
|
});
|
|
57
61
|
// Register resource handlers (placeholder)
|
|
58
|
-
|
|
62
|
+
console.error('🔍 [DEBUG] Registering resources handler...');
|
|
59
63
|
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
60
|
-
|
|
64
|
+
console.error('🔍 [DEBUG] Resources list requested');
|
|
61
65
|
return { resources: [] };
|
|
62
66
|
});
|
|
63
67
|
// Register prompt handlers (placeholder)
|
|
64
|
-
|
|
68
|
+
console.error('🔍 [DEBUG] Registering prompts handler...');
|
|
65
69
|
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
66
|
-
|
|
70
|
+
console.error('🔍 [DEBUG] Prompts list requested');
|
|
67
71
|
return { prompts: [] };
|
|
68
72
|
});
|
|
69
73
|
// Main tool call handler
|
|
70
|
-
|
|
74
|
+
console.error('🔍 [DEBUG] Registering tool call handler...');
|
|
71
75
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
72
76
|
const { name, arguments: args } = request.params;
|
|
73
|
-
|
|
77
|
+
console.error(`🔍 [DEBUG] Tool call received: ${name} with args: ${JSON.stringify(args)}`);
|
|
74
78
|
try {
|
|
75
79
|
switch (name) {
|
|
76
80
|
case TOOL_NAMES.BROWSER_INIT:
|
|
@@ -95,52 +99,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
95
99
|
return await handleFindSelector(args);
|
|
96
100
|
case TOOL_NAMES.SAVE_CONTENT_AS_MARKDOWN:
|
|
97
101
|
return await handleSaveContentAsMarkdown(args);
|
|
98
|
-
// Smart Data Extractors
|
|
99
|
-
case TOOL_NAMES.EXTRACT_TABLES:
|
|
100
|
-
return await handleExtractTables(args || {});
|
|
101
|
-
case TOOL_NAMES.EXTRACT_LISTS:
|
|
102
|
-
return await handleExtractLists(args || {});
|
|
103
|
-
case TOOL_NAMES.EXTRACT_JSON:
|
|
104
|
-
return await handleExtractJSON();
|
|
105
|
-
case TOOL_NAMES.EXTRACT_META_TAGS:
|
|
106
|
-
return await handleExtractMetaTags();
|
|
107
|
-
case TOOL_NAMES.EXTRACT_SCHEMA_ORG:
|
|
108
|
-
return await handleExtractSchemaOrg();
|
|
109
|
-
// Multi-Element Extractors
|
|
110
|
-
case TOOL_NAMES.BATCH_EXTRACT_ELEMENTS:
|
|
111
|
-
return await handleBatchExtractElements(args);
|
|
112
|
-
case TOOL_NAMES.EXTRACT_PRODUCTS:
|
|
113
|
-
return await handleExtractProducts(args);
|
|
114
|
-
case TOOL_NAMES.EXTRACT_ARTICLES:
|
|
115
|
-
return await handleExtractArticles(args);
|
|
116
|
-
// Content Type Extractors
|
|
117
|
-
case TOOL_NAMES.EXTRACT_IMAGES:
|
|
118
|
-
return await handleExtractImages(args || {});
|
|
119
|
-
case TOOL_NAMES.EXTRACT_LINKS:
|
|
120
|
-
return await handleExtractLinks(args || {});
|
|
121
|
-
case TOOL_NAMES.EXTRACT_MEDIA:
|
|
122
|
-
return await handleExtractMedia();
|
|
123
|
-
case TOOL_NAMES.EXTRACT_DOWNLOADABLE_FILES:
|
|
124
|
-
return await handleExtractDownloadableFiles();
|
|
125
|
-
case TOOL_NAMES.EXTRACT_SOCIAL_MEDIA:
|
|
126
|
-
return await handleExtractSocialMedia();
|
|
127
|
-
// Pagination & Navigation
|
|
128
|
-
case TOOL_NAMES.AUTO_PAGINATE:
|
|
129
|
-
return await handleAutoPaginate(args || {});
|
|
130
|
-
case TOOL_NAMES.INFINITE_SCROLL:
|
|
131
|
-
return await handleInfiniteScrollHandler(args || {});
|
|
132
|
-
case TOOL_NAMES.EXTRACT_BREADCRUMBS:
|
|
133
|
-
return await handleExtractBreadcrumbs();
|
|
134
|
-
// Note: EXTRACT_PAGINATION_INFO and PARSE_SITEMAP not in TOOL_NAMES, skip for now
|
|
135
|
-
case 'extract_pagination_info':
|
|
136
|
-
return await handleExtractPaginationInfo();
|
|
137
|
-
case 'parse_sitemap':
|
|
138
|
-
return await handleParseSitemap(args);
|
|
139
|
-
// Data Processing
|
|
140
|
-
case TOOL_NAMES.EXTRACT_CONTACT_INFO:
|
|
141
|
-
return await handleExtractContactInfo();
|
|
142
|
-
case TOOL_NAMES.HARVEST_ATTRIBUTES:
|
|
143
|
-
return await handleHarvestAttributes(args);
|
|
144
102
|
default:
|
|
145
103
|
throw new Error(`Unknown tool: ${name}`);
|
|
146
104
|
}
|
|
@@ -168,98 +126,96 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
168
126
|
});
|
|
169
127
|
// Main function to start the server
|
|
170
128
|
async function main() {
|
|
171
|
-
|
|
129
|
+
console.error('🔍 [DEBUG] Main function starting...');
|
|
172
130
|
// Setup process cleanup handlers
|
|
173
|
-
|
|
131
|
+
console.error('🔍 [DEBUG] Setting up process cleanup handlers...');
|
|
174
132
|
setupProcessCleanup(async () => {
|
|
175
|
-
|
|
133
|
+
console.error('🔍 [DEBUG] Process cleanup triggered');
|
|
176
134
|
await closeBrowser();
|
|
177
135
|
await forceKillAllChromeProcesses();
|
|
178
136
|
});
|
|
179
137
|
// Create and start the server transport
|
|
180
|
-
|
|
138
|
+
console.error('🔍 [DEBUG] Creating StdioServerTransport...');
|
|
181
139
|
const transport = new StdioServerTransport();
|
|
182
|
-
|
|
140
|
+
console.error('🔍 [DEBUG] StdioServerTransport created successfully');
|
|
183
141
|
await withErrorHandling(async () => {
|
|
184
|
-
|
|
142
|
+
console.error('🔍 [DEBUG] Attempting to connect server to transport...');
|
|
185
143
|
await server.connect(transport);
|
|
186
|
-
|
|
144
|
+
console.error('🔍 [DEBUG] Server connected to transport successfully');
|
|
187
145
|
console.error('🚀 Brave Real Browser MCP Server started successfully');
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
146
|
+
console.error('📋 Available tools:', TOOLS.map(t => t.name).join(', '));
|
|
147
|
+
console.error('🔧 Workflow validation: Active');
|
|
148
|
+
console.error('💡 Content priority mode: Enabled (use get_content for better reliability)');
|
|
149
|
+
console.error('🔍 [DEBUG] Server is now ready and waiting for requests...');
|
|
192
150
|
// Keep the process alive by maintaining the connection
|
|
193
|
-
|
|
194
|
-
// Add a heartbeat to confirm the process is still running
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
}
|
|
151
|
+
console.error('🔍 [DEBUG] Maintaining process alive - server will wait for requests');
|
|
152
|
+
// Add a heartbeat to confirm the process is still running
|
|
153
|
+
const heartbeat = setInterval(() => {
|
|
154
|
+
console.error(`🔍 [DEBUG] Heartbeat - Server alive at ${new Date().toISOString()}`);
|
|
155
|
+
}, 30000); // Every 30 seconds
|
|
156
|
+
// Cleanup heartbeat on process exit
|
|
157
|
+
process.on('exit', () => {
|
|
158
|
+
console.error('🔍 [DEBUG] Process exiting - clearing heartbeat');
|
|
159
|
+
clearInterval(heartbeat);
|
|
160
|
+
});
|
|
205
161
|
}, 'Failed to start MCP server');
|
|
206
|
-
|
|
162
|
+
console.error('🔍 [DEBUG] Main function completed - server should be running');
|
|
207
163
|
}
|
|
208
164
|
// Enhanced error handling with debug info
|
|
209
|
-
|
|
165
|
+
console.error('🔍 [DEBUG] Setting up error handlers...');
|
|
210
166
|
process.on('uncaughtException', (error) => {
|
|
211
|
-
|
|
167
|
+
console.error(`🔍 [DEBUG] Uncaught exception at ${new Date().toISOString()}`);
|
|
212
168
|
console.error('❌ Uncaught exception:', error);
|
|
213
|
-
|
|
169
|
+
console.error(`🔍 [DEBUG] Stack trace:`, error.stack);
|
|
214
170
|
process.exit(1);
|
|
215
171
|
});
|
|
216
172
|
process.on('unhandledRejection', (reason, promise) => {
|
|
217
|
-
|
|
173
|
+
console.error(`🔍 [DEBUG] Unhandled rejection at ${new Date().toISOString()}`);
|
|
218
174
|
console.error('❌ Unhandled rejection:', reason);
|
|
219
|
-
|
|
175
|
+
console.error(`🔍 [DEBUG] Promise:`, promise);
|
|
220
176
|
process.exit(1);
|
|
221
177
|
});
|
|
222
178
|
// Process lifecycle debugging
|
|
223
179
|
process.on('exit', (code) => {
|
|
224
|
-
|
|
180
|
+
console.error(`🔍 [DEBUG] Process exiting with code: ${code} at ${new Date().toISOString()}`);
|
|
225
181
|
});
|
|
226
182
|
process.on('beforeExit', (code) => {
|
|
227
|
-
|
|
183
|
+
console.error(`🔍 [DEBUG] Before exit event with code: ${code} at ${new Date().toISOString()}`);
|
|
228
184
|
});
|
|
229
185
|
process.on('SIGTERM', () => {
|
|
230
|
-
|
|
186
|
+
console.error(`🔍 [DEBUG] SIGTERM received at ${new Date().toISOString()}`);
|
|
231
187
|
});
|
|
232
188
|
process.on('SIGINT', () => {
|
|
233
|
-
|
|
189
|
+
console.error(`🔍 [DEBUG] SIGINT received at ${new Date().toISOString()}`);
|
|
234
190
|
});
|
|
235
|
-
|
|
191
|
+
console.error('🔍 [DEBUG] All error handlers registered');
|
|
236
192
|
// Start the server
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
193
|
+
console.error('🔍 [DEBUG] Checking if module is main...');
|
|
194
|
+
console.error(`🔍 [DEBUG] import.meta.url: ${import.meta.url}`);
|
|
195
|
+
console.error(`🔍 [DEBUG] process.argv[1]: ${process.argv[1]}`);
|
|
196
|
+
console.error(`🔍 [DEBUG] process.argv[0]: ${process.argv[0]}`);
|
|
241
197
|
// Enhanced main module detection for npx compatibility
|
|
242
198
|
const isMain = import.meta.url === `file://${process.argv[1]}` ||
|
|
243
199
|
process.argv[1].includes('brave-real-browser-mcp-server') ||
|
|
244
200
|
process.argv[1].endsWith('.bin/brave-real-browser-mcp-server') ||
|
|
245
201
|
process.argv.some(arg => arg.includes('brave-real-browser-mcp-server'));
|
|
246
|
-
|
|
202
|
+
console.error(`🔍 [DEBUG] Enhanced main detection result: ${isMain}`);
|
|
247
203
|
if (isMain) {
|
|
248
|
-
|
|
204
|
+
console.error('🔍 [DEBUG] Module is main - starting server...');
|
|
249
205
|
main().catch((error) => {
|
|
250
|
-
|
|
206
|
+
console.error(`🔍 [DEBUG] Main function failed at ${new Date().toISOString()}`);
|
|
251
207
|
console.error('❌ Failed to start server:', error);
|
|
252
|
-
|
|
208
|
+
console.error(`🔍 [DEBUG] Error stack:`, error.stack);
|
|
253
209
|
process.exit(1);
|
|
254
210
|
});
|
|
255
211
|
}
|
|
256
212
|
else {
|
|
257
|
-
|
|
258
|
-
|
|
213
|
+
console.error('🔍 [DEBUG] Module is not main - not starting server');
|
|
214
|
+
console.error('🔍 [DEBUG] FORCE STARTING - This is likely an npx execution');
|
|
259
215
|
main().catch((error) => {
|
|
260
|
-
|
|
216
|
+
console.error(`🔍 [DEBUG] Forced main function failed at ${new Date().toISOString()}`);
|
|
261
217
|
console.error('❌ Failed to start server:', error);
|
|
262
|
-
|
|
218
|
+
console.error(`🔍 [DEBUG] Error stack:`, error.stack);
|
|
263
219
|
process.exit(1);
|
|
264
220
|
});
|
|
265
221
|
}
|