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.
Files changed (42) hide show
  1. package/dist/browser-manager.js +0 -14
  2. package/dist/index.js +78 -122
  3. package/dist/tool-definitions.js +14 -659
  4. package/package.json +1 -1
  5. package/dist/advanced/advanced-content-extraction.js +0 -435
  6. package/dist/advanced/advanced-content-extraction.test.js +0 -8
  7. package/dist/advanced/advanced-scraping.js +0 -301
  8. package/dist/ai/ai-features.js +0 -56
  9. package/dist/ai/ai-features.test.js +0 -18
  10. package/dist/ai/ai-tools.js +0 -390
  11. package/dist/api/api-integration-system.js +0 -68
  12. package/dist/api/api-integration-system.test.js +0 -29
  13. package/dist/api/api-integration.js +0 -371
  14. package/dist/auth/session-manager.js +0 -50
  15. package/dist/auth/session-manager.test.js +0 -8
  16. package/dist/captcha/advanced-captcha-handler.js +0 -45
  17. package/dist/captcha/advanced-captcha-handler.test.js +0 -8
  18. package/dist/captcha/captcha-handler.js +0 -374
  19. package/dist/extractors/content-type-extractors.js +0 -233
  20. package/dist/extractors/multi-element-extractors.js +0 -174
  21. package/dist/extractors/smart-data-extractors.js +0 -204
  22. package/dist/extractors/smart-data-extractors.test.js +0 -91
  23. package/dist/handlers/advanced-scraping-handlers.js +0 -333
  24. package/dist/handlers/advanced-scraping-handlers.test.js +0 -218
  25. package/dist/handlers/new-features-handlers.js +0 -209
  26. package/dist/handlers/new-features-handlers.test.js +0 -21
  27. package/dist/monitoring/monitoring-system.js +0 -53
  28. package/dist/monitoring/monitoring-system.test.js +0 -26
  29. package/dist/monitoring/monitoring-tools.js +0 -372
  30. package/dist/navigation/pagination-tools.js +0 -215
  31. package/dist/processors/data-processors.js +0 -250
  32. package/dist/processors/data-processors.test.js +0 -163
  33. package/dist/processors/data-transformation.js +0 -344
  34. package/dist/processors/data-transformation.test.js +0 -288
  35. package/dist/quality/data-quality-tools.js +0 -43
  36. package/dist/quality/data-quality-tools.test.js +0 -26
  37. package/dist/search/advanced-search-tools.js +0 -52
  38. package/dist/search/advanced-search-tools.test.js +0 -11
  39. package/dist/search/search-filter-tools.js +0 -339
  40. package/dist/visual/screenshot-tools.js +0 -47
  41. package/dist/visual/screenshot-tools.test.js +0 -8
  42. package/dist/visual/visual-tools.js +0 -516
@@ -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 flag - only enable if DEBUG_MCP env var is set
3
- const DEBUG = process.env.DEBUG_MCP === 'true';
4
- const debug = (...args) => DEBUG && console.error(...args);
5
- debug(`🔍 [DEBUG] Process starting - PID: ${process.pid}, Node: ${process.version}, Platform: ${process.platform}`);
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
- debug('🔍 [DEBUG] MCP SDK imports completed successfully');
9
+ console.error('🔍 [DEBUG] MCP SDK imports completed successfully');
12
10
  // Import extracted modules
13
- debug('🔍 [DEBUG] Loading tool definitions...');
11
+ console.error('🔍 [DEBUG] Loading tool definitions...');
14
12
  import { TOOLS, SERVER_INFO, CAPABILITIES, TOOL_NAMES } from './tool-definitions.js';
15
- debug('🔍 [DEBUG] Loading system utils...');
13
+ console.error('🔍 [DEBUG] Loading system utils...');
16
14
  import { withErrorHandling } from './system-utils.js';
17
- debug('🔍 [DEBUG] Loading browser manager...');
15
+ console.error('🔍 [DEBUG] Loading browser manager...');
18
16
  import { closeBrowser, forceKillAllChromeProcesses } from './browser-manager.js';
19
- debug('🔍 [DEBUG] Loading core infrastructure...');
17
+ console.error('🔍 [DEBUG] Loading core infrastructure...');
20
18
  import { setupProcessCleanup } from './core-infrastructure.js';
21
19
  // Import handlers
22
- debug('🔍 [DEBUG] Loading handlers...');
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
- import { handleExtractTables, handleExtractLists, handleExtractJSON, handleExtractMetaTags, handleExtractSchemaOrg, handleBatchExtractElements, handleExtractProducts, handleExtractArticles, handleExtractImages, handleExtractLinks, handleExtractMedia, handleExtractDownloadableFiles, handleExtractSocialMedia, handleAutoPaginate, handleInfiniteScrollHandler, handleExtractBreadcrumbs, handleExtractPaginationInfo, handleParseSitemap, handleExtractContactInfo, handleHarvestAttributes } from './handlers/advanced-scraping-handlers.js';
29
- debug('🔍 [DEBUG] All modules loaded successfully');
30
- debug(`🔍 [DEBUG] Server info: ${JSON.stringify(SERVER_INFO)}`);
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
- debug('🔍 [DEBUG] Creating MCP server instance...');
30
+ console.error('🔍 [DEBUG] Creating MCP server instance...');
34
31
  const server = new Server(SERVER_INFO, { capabilities: CAPABILITIES });
35
- debug('🔍 [DEBUG] MCP server instance created successfully');
32
+ console.error('🔍 [DEBUG] MCP server instance created successfully');
36
33
  // Register initialize handler (CRITICAL - missing handler can cause crash)
37
- debug('🔍 [DEBUG] Registering initialize handler...');
34
+ console.error('🔍 [DEBUG] Registering initialize handler...');
38
35
  server.setRequestHandler(InitializeRequestSchema, async (request) => {
39
- debug(`🔍 [DEBUG] Initialize request received: ${JSON.stringify(request)}`);
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
- debug(`🔍 [DEBUG] Client protocol version: ${clientProtocolVersion}`);
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
- debug(`🔍 [DEBUG] Sending initialize response: ${JSON.stringify(response)}`);
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
- debug('🔍 [DEBUG] Registering tools handler...');
56
+ console.error('🔍 [DEBUG] Registering tools handler...');
53
57
  server.setRequestHandler(ListToolsRequestSchema, async () => {
54
- debug('🔍 [DEBUG] Tools list requested');
58
+ console.error('🔍 [DEBUG] Tools list requested');
55
59
  return { tools: TOOLS };
56
60
  });
57
61
  // Register resource handlers (placeholder)
58
- debug('🔍 [DEBUG] Registering resources handler...');
62
+ console.error('🔍 [DEBUG] Registering resources handler...');
59
63
  server.setRequestHandler(ListResourcesRequestSchema, async () => {
60
- debug('🔍 [DEBUG] Resources list requested');
64
+ console.error('🔍 [DEBUG] Resources list requested');
61
65
  return { resources: [] };
62
66
  });
63
67
  // Register prompt handlers (placeholder)
64
- debug('🔍 [DEBUG] Registering prompts handler...');
68
+ console.error('🔍 [DEBUG] Registering prompts handler...');
65
69
  server.setRequestHandler(ListPromptsRequestSchema, async () => {
66
- debug('🔍 [DEBUG] Prompts list requested');
70
+ console.error('🔍 [DEBUG] Prompts list requested');
67
71
  return { prompts: [] };
68
72
  });
69
73
  // Main tool call handler
70
- debug('🔍 [DEBUG] Registering tool call handler...');
74
+ console.error('🔍 [DEBUG] Registering tool call handler...');
71
75
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
72
76
  const { name, arguments: args } = request.params;
73
- debug(`🔍 [DEBUG] Tool call received: ${name} with args: ${JSON.stringify(args)}`);
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
- debug('🔍 [DEBUG] Main function starting...');
129
+ console.error('🔍 [DEBUG] Main function starting...');
172
130
  // Setup process cleanup handlers
173
- debug('🔍 [DEBUG] Setting up process cleanup handlers...');
131
+ console.error('🔍 [DEBUG] Setting up process cleanup handlers...');
174
132
  setupProcessCleanup(async () => {
175
- debug('🔍 [DEBUG] Process cleanup triggered');
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
- debug('🔍 [DEBUG] Creating StdioServerTransport...');
138
+ console.error('🔍 [DEBUG] Creating StdioServerTransport...');
181
139
  const transport = new StdioServerTransport();
182
- debug('🔍 [DEBUG] StdioServerTransport created successfully');
140
+ console.error('🔍 [DEBUG] StdioServerTransport created successfully');
183
141
  await withErrorHandling(async () => {
184
- debug('🔍 [DEBUG] Attempting to connect server to transport...');
142
+ console.error('🔍 [DEBUG] Attempting to connect server to transport...');
185
143
  await server.connect(transport);
186
- debug('🔍 [DEBUG] Server connected to transport successfully');
144
+ console.error('🔍 [DEBUG] Server connected to transport successfully');
187
145
  console.error('🚀 Brave Real Browser MCP Server started successfully');
188
- debug('📋 Available tools:', TOOLS.map(t => t.name).join(', '));
189
- debug('🔧 Workflow validation: Active');
190
- debug('💡 Content priority mode: Enabled (use get_content for better reliability)');
191
- debug('🔍 [DEBUG] Server is now ready and waiting for requests...');
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
- debug('🔍 [DEBUG] Maintaining process alive - server will wait for requests');
194
- // Add a heartbeat to confirm the process is still running (only in debug mode)
195
- if (DEBUG) {
196
- const heartbeat = setInterval(() => {
197
- debug(`🔍 [DEBUG] Heartbeat - Server alive at ${new Date().toISOString()}`);
198
- }, 30000); // Every 30 seconds
199
- // Cleanup heartbeat on process exit
200
- process.on('exit', () => {
201
- debug('🔍 [DEBUG] Process exiting - clearing heartbeat');
202
- clearInterval(heartbeat);
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
- debug('🔍 [DEBUG] Main function completed - server should be running');
162
+ console.error('🔍 [DEBUG] Main function completed - server should be running');
207
163
  }
208
164
  // Enhanced error handling with debug info
209
- debug('🔍 [DEBUG] Setting up error handlers...');
165
+ console.error('🔍 [DEBUG] Setting up error handlers...');
210
166
  process.on('uncaughtException', (error) => {
211
- debug(`🔍 [DEBUG] Uncaught exception at ${new Date().toISOString()}`);
167
+ console.error(`🔍 [DEBUG] Uncaught exception at ${new Date().toISOString()}`);
212
168
  console.error('❌ Uncaught exception:', error);
213
- debug(`🔍 [DEBUG] Stack trace:`, error.stack);
169
+ console.error(`🔍 [DEBUG] Stack trace:`, error.stack);
214
170
  process.exit(1);
215
171
  });
216
172
  process.on('unhandledRejection', (reason, promise) => {
217
- debug(`🔍 [DEBUG] Unhandled rejection at ${new Date().toISOString()}`);
173
+ console.error(`🔍 [DEBUG] Unhandled rejection at ${new Date().toISOString()}`);
218
174
  console.error('❌ Unhandled rejection:', reason);
219
- debug(`🔍 [DEBUG] Promise:`, promise);
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
- debug(`🔍 [DEBUG] Process exiting with code: ${code} at ${new Date().toISOString()}`);
180
+ console.error(`🔍 [DEBUG] Process exiting with code: ${code} at ${new Date().toISOString()}`);
225
181
  });
226
182
  process.on('beforeExit', (code) => {
227
- debug(`🔍 [DEBUG] Before exit event with code: ${code} at ${new Date().toISOString()}`);
183
+ console.error(`🔍 [DEBUG] Before exit event with code: ${code} at ${new Date().toISOString()}`);
228
184
  });
229
185
  process.on('SIGTERM', () => {
230
- debug(`🔍 [DEBUG] SIGTERM received at ${new Date().toISOString()}`);
186
+ console.error(`🔍 [DEBUG] SIGTERM received at ${new Date().toISOString()}`);
231
187
  });
232
188
  process.on('SIGINT', () => {
233
- debug(`🔍 [DEBUG] SIGINT received at ${new Date().toISOString()}`);
189
+ console.error(`🔍 [DEBUG] SIGINT received at ${new Date().toISOString()}`);
234
190
  });
235
- debug('🔍 [DEBUG] All error handlers registered');
191
+ console.error('🔍 [DEBUG] All error handlers registered');
236
192
  // Start the server
237
- debug('🔍 [DEBUG] Checking if module is main...');
238
- debug(`🔍 [DEBUG] import.meta.url: ${import.meta.url}`);
239
- debug(`🔍 [DEBUG] process.argv[1]: ${process.argv[1]}`);
240
- debug(`🔍 [DEBUG] process.argv[0]: ${process.argv[0]}`);
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
- debug(`🔍 [DEBUG] Enhanced main detection result: ${isMain}`);
202
+ console.error(`🔍 [DEBUG] Enhanced main detection result: ${isMain}`);
247
203
  if (isMain) {
248
- debug('🔍 [DEBUG] Module is main - starting server...');
204
+ console.error('🔍 [DEBUG] Module is main - starting server...');
249
205
  main().catch((error) => {
250
- debug(`🔍 [DEBUG] Main function failed at ${new Date().toISOString()}`);
206
+ console.error(`🔍 [DEBUG] Main function failed at ${new Date().toISOString()}`);
251
207
  console.error('❌ Failed to start server:', error);
252
- debug(`🔍 [DEBUG] Error stack:`, error.stack);
208
+ console.error(`🔍 [DEBUG] Error stack:`, error.stack);
253
209
  process.exit(1);
254
210
  });
255
211
  }
256
212
  else {
257
- debug('🔍 [DEBUG] Module is not main - not starting server');
258
- debug('🔍 [DEBUG] FORCE STARTING - This is likely an npx execution');
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
- debug(`🔍 [DEBUG] Forced main function failed at ${new Date().toISOString()}`);
216
+ console.error(`🔍 [DEBUG] Forced main function failed at ${new Date().toISOString()}`);
261
217
  console.error('❌ Failed to start server:', error);
262
- debug(`🔍 [DEBUG] Error stack:`, error.stack);
218
+ console.error(`🔍 [DEBUG] Error stack:`, error.stack);
263
219
  process.exit(1);
264
220
  });
265
221
  }