brave-real-browser-mcp-server 2.19.2 → 2.19.4

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 (2) hide show
  1. package/dist/index.js +71 -64
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,23 +1,30 @@
1
1
  #!/usr/bin/env node
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(' ')}`);
2
+ // Debug logging - only enabled if DEBUG=true environment variable is set
3
+ const DEBUG_ENABLED = process.env.DEBUG === 'true';
4
+ const debug = (...args) => {
5
+ if (DEBUG_ENABLED) {
6
+ console.error('🔍 [DEBUG]', ...args);
7
+ }
8
+ };
9
+ // Debug logging setup - Log process start (only if DEBUG=true)
10
+ debug(`Process starting - PID: ${process.pid}, Node: ${process.version}, Platform: ${process.platform}`);
11
+ debug(`Working directory: ${process.cwd()}`);
12
+ debug(`Command args: ${process.argv.join(' ')}`);
6
13
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
14
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
15
  import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ListPromptsRequestSchema, InitializeRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
9
- console.error('🔍 [DEBUG] MCP SDK imports completed successfully');
16
+ debug('MCP SDK imports completed successfully');
10
17
  // Import extracted modules
11
- console.error('🔍 [DEBUG] Loading tool definitions...');
18
+ debug('Loading tool definitions...');
12
19
  import { TOOLS, SERVER_INFO, CAPABILITIES, TOOL_NAMES } from './tool-definitions.js';
13
- console.error('🔍 [DEBUG] Loading system utils...');
20
+ debug('Loading system utils...');
14
21
  import { withErrorHandling } from './system-utils.js';
15
- console.error('🔍 [DEBUG] Loading browser manager...');
22
+ debug('Loading browser manager...');
16
23
  import { closeBrowser, forceKillAllBraveProcesses } from './browser-manager.js';
17
- console.error('🔍 [DEBUG] Loading core infrastructure...');
24
+ debug('Loading core infrastructure...');
18
25
  import { setupProcessCleanup } from './core-infrastructure.js';
19
26
  // Import handlers
20
- console.error('🔍 [DEBUG] Loading handlers...');
27
+ debug('Loading handlers...');
21
28
  import { handleBrowserInit, handleBrowserClose } from './handlers/browser-handlers.js';
22
29
  import { handleNavigate, handleWait } from './handlers/navigation-handlers.js';
23
30
  import { handleClick, handleType, handleSolveCaptcha, handleRandomScroll } from './handlers/interaction-handlers.js';
@@ -31,63 +38,63 @@ handleM3u8Parser, handleSubtitleExtractor, handleCookieManager,
31
38
  handleFileDownloader, handleBulkDownloader, } from './handlers/advanced-tools.js';
32
39
  // State for video recording
33
40
  const recorderState = new Map();
34
- console.error('🔍 [DEBUG] All modules loaded successfully');
35
- console.error(`🔍 [DEBUG] Server info: ${JSON.stringify(SERVER_INFO)}`);
36
- console.error(`🔍 [DEBUG] Available tools: ${TOOLS.length} tools loaded`);
41
+ debug('All modules loaded successfully');
42
+ debug(`Server info: ${JSON.stringify(SERVER_INFO)}`);
43
+ debug(`Available tools: ${TOOLS.length} tools loaded`);
37
44
  // Initialize MCP server
38
- console.error('🔍 [DEBUG] Creating MCP server instance...');
45
+ debug('Creating MCP server instance...');
39
46
  const server = new Server(SERVER_INFO, { capabilities: CAPABILITIES });
40
- console.error('🔍 [DEBUG] MCP server instance created successfully');
47
+ debug('MCP server instance created successfully');
41
48
  // Register initialize handler (CRITICAL - missing handler can cause crash)
42
- console.error('🔍 [DEBUG] Registering initialize handler...');
49
+ debug('Registering initialize handler...');
43
50
  server.setRequestHandler(InitializeRequestSchema, async (request) => {
44
- console.error(`🔍 [DEBUG] Initialize request received: ${JSON.stringify(request)}`);
51
+ debug(`Initialize request received: ${JSON.stringify(request)}`);
45
52
  // Use the client's protocol version to ensure compatibility
46
53
  const clientProtocolVersion = request.params.protocolVersion;
47
- console.error(`🔍 [DEBUG] Client protocol version: ${clientProtocolVersion}`);
54
+ debug(`Client protocol version: ${clientProtocolVersion}`);
48
55
  // Log client info for debugging (LLM handles its own token limits)
49
56
  const clientInfo = request.params.clientInfo;
50
57
  if (clientInfo) {
51
- console.error(`🔍 [DEBUG] Client info: ${JSON.stringify(clientInfo)}`);
58
+ debug(`Client info: ${JSON.stringify(clientInfo)}`);
52
59
  }
53
60
  const response = {
54
61
  protocolVersion: clientProtocolVersion, // Match client version for compatibility
55
62
  capabilities: CAPABILITIES,
56
63
  serverInfo: SERVER_INFO,
57
64
  };
58
- console.error(`🔍 [DEBUG] Sending initialize response: ${JSON.stringify(response)}`);
65
+ debug(`Sending initialize response: ${JSON.stringify(response)}`);
59
66
  // Add a small delay to see if there are any immediate errors after response
60
67
  setTimeout(() => {
61
- console.error(`🔍 [DEBUG] 1 second after initialize response - server still alive`);
68
+ debug('1 second after initialize response - server still alive');
62
69
  }, 1000);
63
70
  setTimeout(() => {
64
- console.error(`🔍 [DEBUG] 5 seconds after initialize response - server still alive`);
71
+ debug('5 seconds after initialize response - server still alive');
65
72
  }, 5000);
66
73
  return response;
67
74
  });
68
75
  // Register tool handlers
69
- console.error('🔍 [DEBUG] Registering tools handler...');
76
+ debug('Registering tools handler...');
70
77
  server.setRequestHandler(ListToolsRequestSchema, async () => {
71
- console.error('🔍 [DEBUG] Tools list requested');
78
+ debug('Tools list requested');
72
79
  return { tools: TOOLS };
73
80
  });
74
81
  // Register resource handlers (placeholder)
75
- console.error('🔍 [DEBUG] Registering resources handler...');
82
+ debug('Registering resources handler...');
76
83
  server.setRequestHandler(ListResourcesRequestSchema, async () => {
77
- console.error('🔍 [DEBUG] Resources list requested');
84
+ debug('Resources list requested');
78
85
  return { resources: [] };
79
86
  });
80
87
  // Register prompt handlers (placeholder)
81
- console.error('🔍 [DEBUG] Registering prompts handler...');
88
+ debug('Registering prompts handler...');
82
89
  server.setRequestHandler(ListPromptsRequestSchema, async () => {
83
- console.error('🔍 [DEBUG] Prompts list requested');
90
+ debug('Prompts list requested');
84
91
  return { prompts: [] };
85
92
  });
86
93
  // Main tool call handler
87
- console.error('🔍 [DEBUG] Registering tool call handler...');
94
+ debug('Registering tool call handler...');
88
95
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
89
96
  const { name, arguments: args } = request.params;
90
- console.error(`🔍 [DEBUG] Tool call received: ${name} with args: ${JSON.stringify(args)}`);
97
+ debug(`Tool call received: ${name} with args: ${JSON.stringify(args)}`);
91
98
  // Get page from browser manager for advanced tools
92
99
  const { getPageInstance } = await import('./browser-manager.js');
93
100
  const page = getPageInstance();
@@ -254,96 +261,96 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
254
261
  });
255
262
  // Main function to start the server
256
263
  async function main() {
257
- console.error('🔍 [DEBUG] Main function starting...');
264
+ debug('Main function starting...');
258
265
  // Setup process cleanup handlers
259
- console.error('🔍 [DEBUG] Setting up process cleanup handlers...');
266
+ debug('Setting up process cleanup handlers...');
260
267
  setupProcessCleanup(async () => {
261
- console.error('🔍 [DEBUG] Process cleanup triggered');
268
+ debug('Process cleanup triggered');
262
269
  await closeBrowser();
263
270
  await forceKillAllBraveProcesses();
264
271
  });
265
272
  // Create and start the server transport
266
- console.error('🔍 [DEBUG] Creating StdioServerTransport...');
273
+ debug('Creating StdioServerTransport...');
267
274
  const transport = new StdioServerTransport();
268
- console.error('🔍 [DEBUG] StdioServerTransport created successfully');
275
+ debug('StdioServerTransport created successfully');
269
276
  await withErrorHandling(async () => {
270
- console.error('🔍 [DEBUG] Attempting to connect server to transport...');
277
+ debug('Attempting to connect server to transport...');
271
278
  await server.connect(transport);
272
- console.error('🔍 [DEBUG] Server connected to transport successfully');
279
+ debug('Server connected to transport successfully');
273
280
  console.error('🚀 Brave Real Browser MCP Server started successfully');
274
281
  console.error('📋 Available tools:', TOOLS.map(t => t.name).join(', '));
275
282
  console.error('🔧 Workflow validation: Active');
276
283
  console.error('💡 Content priority mode: Enabled (use get_content for better reliability)');
277
- console.error('🔍 [DEBUG] Server is now ready and waiting for requests...');
284
+ debug('Server is now ready and waiting for requests...');
278
285
  // Keep the process alive by maintaining the connection
279
- console.error('🔍 [DEBUG] Maintaining process alive - server will wait for requests');
286
+ debug('Maintaining process alive - server will wait for requests');
280
287
  // Add a heartbeat to confirm the process is still running
281
288
  const heartbeat = setInterval(() => {
282
- console.error(`🔍 [DEBUG] Heartbeat - Server alive at ${new Date().toISOString()}`);
289
+ debug(`Heartbeat - Server alive at ${new Date().toISOString()}`);
283
290
  }, 30000); // Every 30 seconds
284
291
  // Cleanup heartbeat on process exit
285
292
  process.on('exit', () => {
286
- console.error('🔍 [DEBUG] Process exiting - clearing heartbeat');
293
+ debug('Process exiting - clearing heartbeat');
287
294
  clearInterval(heartbeat);
288
295
  });
289
296
  }, 'Failed to start MCP server');
290
- console.error('🔍 [DEBUG] Main function completed - server should be running');
297
+ debug('Main function completed - server should be running');
291
298
  }
292
299
  // Enhanced error handling with debug info
293
- console.error('🔍 [DEBUG] Setting up error handlers...');
300
+ debug('Setting up error handlers...');
294
301
  process.on('uncaughtException', (error) => {
295
- console.error(`🔍 [DEBUG] Uncaught exception at ${new Date().toISOString()}`);
302
+ debug(`Uncaught exception at ${new Date().toISOString()}`);
296
303
  console.error('❌ Uncaught exception:', error);
297
- console.error(`🔍 [DEBUG] Stack trace:`, error.stack);
304
+ debug(`Stack trace:`, error.stack);
298
305
  process.exit(1);
299
306
  });
300
307
  process.on('unhandledRejection', (reason, promise) => {
301
- console.error(`🔍 [DEBUG] Unhandled rejection at ${new Date().toISOString()}`);
308
+ debug(`Unhandled rejection at ${new Date().toISOString()}`);
302
309
  console.error('❌ Unhandled rejection:', reason);
303
- console.error(`🔍 [DEBUG] Promise:`, promise);
310
+ debug(`Promise:`, promise);
304
311
  process.exit(1);
305
312
  });
306
313
  // Process lifecycle debugging
307
314
  process.on('exit', (code) => {
308
- console.error(`🔍 [DEBUG] Process exiting with code: ${code} at ${new Date().toISOString()}`);
315
+ debug(`Process exiting with code: ${code} at ${new Date().toISOString()}`);
309
316
  });
310
317
  process.on('beforeExit', (code) => {
311
- console.error(`🔍 [DEBUG] Before exit event with code: ${code} at ${new Date().toISOString()}`);
318
+ debug(`Before exit event with code: ${code} at ${new Date().toISOString()}`);
312
319
  });
313
320
  process.on('SIGTERM', () => {
314
- console.error(`🔍 [DEBUG] SIGTERM received at ${new Date().toISOString()}`);
321
+ debug(`SIGTERM received at ${new Date().toISOString()}`);
315
322
  });
316
323
  process.on('SIGINT', () => {
317
- console.error(`🔍 [DEBUG] SIGINT received at ${new Date().toISOString()}`);
324
+ debug(`SIGINT received at ${new Date().toISOString()}`);
318
325
  });
319
- console.error('🔍 [DEBUG] All error handlers registered');
326
+ debug('All error handlers registered');
320
327
  // Start the server
321
- console.error('🔍 [DEBUG] Checking if module is main...');
322
- console.error(`🔍 [DEBUG] import.meta.url: ${import.meta.url}`);
323
- console.error(`🔍 [DEBUG] process.argv[1]: ${process.argv[1]}`);
324
- console.error(`🔍 [DEBUG] process.argv[0]: ${process.argv[0]}`);
328
+ debug('Checking if module is main...');
329
+ debug(`import.meta.url: ${import.meta.url}`);
330
+ debug(`process.argv[1]: ${process.argv[1]}`);
331
+ debug(`process.argv[0]: ${process.argv[0]}`);
325
332
  // Enhanced main module detection for npx compatibility
326
333
  const isMain = import.meta.url === `file://${process.argv[1]}` ||
327
334
  process.argv[1].includes('brave-real-browser-mcp-server') ||
328
335
  process.argv[1].endsWith('.bin/brave-real-browser-mcp-server') ||
329
336
  process.argv.some(arg => arg.includes('brave-real-browser-mcp-server'));
330
- console.error(`🔍 [DEBUG] Enhanced main detection result: ${isMain}`);
337
+ debug(`Enhanced main detection result: ${isMain}`);
331
338
  if (isMain) {
332
- console.error('🔍 [DEBUG] Module is main - starting server...');
339
+ debug('Module is main - starting server...');
333
340
  main().catch((error) => {
334
- console.error(`🔍 [DEBUG] Main function failed at ${new Date().toISOString()}`);
341
+ debug(`Main function failed at ${new Date().toISOString()}`);
335
342
  console.error('❌ Failed to start server:', error);
336
- console.error(`🔍 [DEBUG] Error stack:`, error.stack);
343
+ debug(`Error stack:`, error.stack);
337
344
  process.exit(1);
338
345
  });
339
346
  }
340
347
  else {
341
- console.error('🔍 [DEBUG] Module is not main - not starting server');
342
- console.error('🔍 [DEBUG] FORCE STARTING - This is likely an npx execution');
348
+ debug('Module is not main - not starting server');
349
+ debug('FORCE STARTING - This is likely an npx execution');
343
350
  main().catch((error) => {
344
- console.error(`🔍 [DEBUG] Forced main function failed at ${new Date().toISOString()}`);
351
+ debug(`Forced main function failed at ${new Date().toISOString()}`);
345
352
  console.error('❌ Failed to start server:', error);
346
- console.error(`🔍 [DEBUG] Error stack:`, error.stack);
353
+ debug(`Error stack:`, error.stack);
347
354
  process.exit(1);
348
355
  });
349
356
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brave-real-browser-mcp-server",
3
- "version": "2.19.2",
3
+ "version": "2.19.4",
4
4
  "description": "🦁 MCP server for Brave Real Browser - NPM Workspaces Monorepo with anti-detection features",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@modelcontextprotocol/sdk": "latest",
41
41
  "@types/turndown": "latest",
42
- "brave-real-browser": "^2.1.2",
42
+ "brave-real-browser": "^2.1.4",
43
43
  "dotenv": "latest",
44
44
  "turndown": "latest"
45
45
  },