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.
- package/dist/index.js +71 -64
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Debug logging
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
16
|
+
debug('MCP SDK imports completed successfully');
|
|
10
17
|
// Import extracted modules
|
|
11
|
-
|
|
18
|
+
debug('Loading tool definitions...');
|
|
12
19
|
import { TOOLS, SERVER_INFO, CAPABILITIES, TOOL_NAMES } from './tool-definitions.js';
|
|
13
|
-
|
|
20
|
+
debug('Loading system utils...');
|
|
14
21
|
import { withErrorHandling } from './system-utils.js';
|
|
15
|
-
|
|
22
|
+
debug('Loading browser manager...');
|
|
16
23
|
import { closeBrowser, forceKillAllBraveProcesses } from './browser-manager.js';
|
|
17
|
-
|
|
24
|
+
debug('Loading core infrastructure...');
|
|
18
25
|
import { setupProcessCleanup } from './core-infrastructure.js';
|
|
19
26
|
// Import handlers
|
|
20
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
45
|
+
debug('Creating MCP server instance...');
|
|
39
46
|
const server = new Server(SERVER_INFO, { capabilities: CAPABILITIES });
|
|
40
|
-
|
|
47
|
+
debug('MCP server instance created successfully');
|
|
41
48
|
// Register initialize handler (CRITICAL - missing handler can cause crash)
|
|
42
|
-
|
|
49
|
+
debug('Registering initialize handler...');
|
|
43
50
|
server.setRequestHandler(InitializeRequestSchema, async (request) => {
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
68
|
+
debug('1 second after initialize response - server still alive');
|
|
62
69
|
}, 1000);
|
|
63
70
|
setTimeout(() => {
|
|
64
|
-
|
|
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
|
-
|
|
76
|
+
debug('Registering tools handler...');
|
|
70
77
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
71
|
-
|
|
78
|
+
debug('Tools list requested');
|
|
72
79
|
return { tools: TOOLS };
|
|
73
80
|
});
|
|
74
81
|
// Register resource handlers (placeholder)
|
|
75
|
-
|
|
82
|
+
debug('Registering resources handler...');
|
|
76
83
|
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
77
|
-
|
|
84
|
+
debug('Resources list requested');
|
|
78
85
|
return { resources: [] };
|
|
79
86
|
});
|
|
80
87
|
// Register prompt handlers (placeholder)
|
|
81
|
-
|
|
88
|
+
debug('Registering prompts handler...');
|
|
82
89
|
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
83
|
-
|
|
90
|
+
debug('Prompts list requested');
|
|
84
91
|
return { prompts: [] };
|
|
85
92
|
});
|
|
86
93
|
// Main tool call handler
|
|
87
|
-
|
|
94
|
+
debug('Registering tool call handler...');
|
|
88
95
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
89
96
|
const { name, arguments: args } = request.params;
|
|
90
|
-
|
|
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
|
-
|
|
264
|
+
debug('Main function starting...');
|
|
258
265
|
// Setup process cleanup handlers
|
|
259
|
-
|
|
266
|
+
debug('Setting up process cleanup handlers...');
|
|
260
267
|
setupProcessCleanup(async () => {
|
|
261
|
-
|
|
268
|
+
debug('Process cleanup triggered');
|
|
262
269
|
await closeBrowser();
|
|
263
270
|
await forceKillAllBraveProcesses();
|
|
264
271
|
});
|
|
265
272
|
// Create and start the server transport
|
|
266
|
-
|
|
273
|
+
debug('Creating StdioServerTransport...');
|
|
267
274
|
const transport = new StdioServerTransport();
|
|
268
|
-
|
|
275
|
+
debug('StdioServerTransport created successfully');
|
|
269
276
|
await withErrorHandling(async () => {
|
|
270
|
-
|
|
277
|
+
debug('Attempting to connect server to transport...');
|
|
271
278
|
await server.connect(transport);
|
|
272
|
-
|
|
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
|
-
|
|
284
|
+
debug('Server is now ready and waiting for requests...');
|
|
278
285
|
// Keep the process alive by maintaining the connection
|
|
279
|
-
|
|
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
|
-
|
|
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
|
-
|
|
293
|
+
debug('Process exiting - clearing heartbeat');
|
|
287
294
|
clearInterval(heartbeat);
|
|
288
295
|
});
|
|
289
296
|
}, 'Failed to start MCP server');
|
|
290
|
-
|
|
297
|
+
debug('Main function completed - server should be running');
|
|
291
298
|
}
|
|
292
299
|
// Enhanced error handling with debug info
|
|
293
|
-
|
|
300
|
+
debug('Setting up error handlers...');
|
|
294
301
|
process.on('uncaughtException', (error) => {
|
|
295
|
-
|
|
302
|
+
debug(`Uncaught exception at ${new Date().toISOString()}`);
|
|
296
303
|
console.error('❌ Uncaught exception:', error);
|
|
297
|
-
|
|
304
|
+
debug(`Stack trace:`, error.stack);
|
|
298
305
|
process.exit(1);
|
|
299
306
|
});
|
|
300
307
|
process.on('unhandledRejection', (reason, promise) => {
|
|
301
|
-
|
|
308
|
+
debug(`Unhandled rejection at ${new Date().toISOString()}`);
|
|
302
309
|
console.error('❌ Unhandled rejection:', reason);
|
|
303
|
-
|
|
310
|
+
debug(`Promise:`, promise);
|
|
304
311
|
process.exit(1);
|
|
305
312
|
});
|
|
306
313
|
// Process lifecycle debugging
|
|
307
314
|
process.on('exit', (code) => {
|
|
308
|
-
|
|
315
|
+
debug(`Process exiting with code: ${code} at ${new Date().toISOString()}`);
|
|
309
316
|
});
|
|
310
317
|
process.on('beforeExit', (code) => {
|
|
311
|
-
|
|
318
|
+
debug(`Before exit event with code: ${code} at ${new Date().toISOString()}`);
|
|
312
319
|
});
|
|
313
320
|
process.on('SIGTERM', () => {
|
|
314
|
-
|
|
321
|
+
debug(`SIGTERM received at ${new Date().toISOString()}`);
|
|
315
322
|
});
|
|
316
323
|
process.on('SIGINT', () => {
|
|
317
|
-
|
|
324
|
+
debug(`SIGINT received at ${new Date().toISOString()}`);
|
|
318
325
|
});
|
|
319
|
-
|
|
326
|
+
debug('All error handlers registered');
|
|
320
327
|
// Start the server
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
|
|
337
|
+
debug(`Enhanced main detection result: ${isMain}`);
|
|
331
338
|
if (isMain) {
|
|
332
|
-
|
|
339
|
+
debug('Module is main - starting server...');
|
|
333
340
|
main().catch((error) => {
|
|
334
|
-
|
|
341
|
+
debug(`Main function failed at ${new Date().toISOString()}`);
|
|
335
342
|
console.error('❌ Failed to start server:', error);
|
|
336
|
-
|
|
343
|
+
debug(`Error stack:`, error.stack);
|
|
337
344
|
process.exit(1);
|
|
338
345
|
});
|
|
339
346
|
}
|
|
340
347
|
else {
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
351
|
+
debug(`Forced main function failed at ${new Date().toISOString()}`);
|
|
345
352
|
console.error('❌ Failed to start server:', error);
|
|
346
|
-
|
|
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.
|
|
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.
|
|
42
|
+
"brave-real-browser": "^2.1.4",
|
|
43
43
|
"dotenv": "latest",
|
|
44
44
|
"turndown": "latest"
|
|
45
45
|
},
|