n8n-nodes-smart-browser-automation 1.1.4 → 1.1.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.
|
@@ -49,17 +49,25 @@ class BrowserSessionManager {
|
|
|
49
49
|
}
|
|
50
50
|
try {
|
|
51
51
|
await this.mcpClient.connect(this.transport);
|
|
52
|
+
// Stability delay for SSE connections to ensure pipe is fully open
|
|
53
|
+
// Remote servers often need a moment to register the session before accepting POST calls
|
|
54
|
+
if (isUrl) {
|
|
55
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
56
|
+
console.log(`[MCP] SSE Connected to ${mcpEndpoint}. Waiting for session stabilization...`);
|
|
57
|
+
}
|
|
58
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
59
|
+
}
|
|
52
60
|
}
|
|
53
61
|
catch (error) {
|
|
54
62
|
this.isInitialized = false;
|
|
55
63
|
const transportType = isUrl ? 'SSE' : 'Stdio';
|
|
56
64
|
throw new Error(`Failed to connect to MCP server via ${transportType} at ${mcpEndpoint}. Error: ${error.message}`);
|
|
57
65
|
}
|
|
66
|
+
this.isInitialized = true;
|
|
67
|
+
this.config = { mcpEndpoint, cdpEndpoint };
|
|
58
68
|
// Fetch available tools from MCP server
|
|
59
69
|
const toolsResponse = await this.mcpClient.listTools();
|
|
60
|
-
this.tools = toolsResponse.tools
|
|
61
|
-
this.config = { mcpEndpoint, cdpEndpoint };
|
|
62
|
-
this.isInitialized = true;
|
|
70
|
+
this.tools = toolsResponse.tools;
|
|
63
71
|
return this.tools;
|
|
64
72
|
}
|
|
65
73
|
async callTool(toolName, toolArgs) {
|
|
@@ -67,9 +75,8 @@ class BrowserSessionManager {
|
|
|
67
75
|
throw new Error('MCP client not initialized. Please configure credentials first.');
|
|
68
76
|
}
|
|
69
77
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
78
|
+
// Log exact payload to debug truncation issues reported by users
|
|
79
|
+
console.log(`[MCP] Calling tool "${toolName}" with args:`, JSON.stringify(toolArgs || {}));
|
|
73
80
|
const result = await this.mcpClient.callTool({
|
|
74
81
|
name: toolName,
|
|
75
82
|
arguments: toolArgs || {}
|
|
@@ -77,7 +84,7 @@ class BrowserSessionManager {
|
|
|
77
84
|
return result;
|
|
78
85
|
}
|
|
79
86
|
catch (error) {
|
|
80
|
-
console.error(`MCP Tool Call Error (${toolName}):`, error);
|
|
87
|
+
console.error(`[MCP] Tool Call Error (${toolName}):`, error);
|
|
81
88
|
throw new Error(`MCP Tool Error: ${error.message}${error.data ? ' - ' + JSON.stringify(error.data) : ''}`);
|
|
82
89
|
}
|
|
83
90
|
}
|
|
@@ -293,28 +293,30 @@ class SmartBrowserAutomation {
|
|
|
293
293
|
console.log(`Initializing AI session with CDP: ${cdpUrl}`);
|
|
294
294
|
}
|
|
295
295
|
const tools = await sessionManager.initialize(credentials.mcpEndpoint, true, cdpUrl);
|
|
296
|
+
let connectionStatus = 'Skipped (No CDP URL provided)';
|
|
297
|
+
let connectionResult = null;
|
|
296
298
|
// New logic: Auto-call browser_connect_cdp tool if a URL is provided
|
|
297
299
|
if (options.cdpUrl) {
|
|
298
300
|
if (verbose) {
|
|
299
301
|
console.log(`Auto-calling 'browser_connect_cdp' with endpoint: ${options.cdpUrl}`);
|
|
300
302
|
}
|
|
301
303
|
try {
|
|
302
|
-
await sessionManager.callTool('browser_connect_cdp', { endpoint: options.cdpUrl });
|
|
304
|
+
connectionResult = await sessionManager.callTool('browser_connect_cdp', { endpoint: options.cdpUrl });
|
|
305
|
+
connectionStatus = 'Successfully connected';
|
|
303
306
|
}
|
|
304
307
|
catch (error) {
|
|
308
|
+
connectionStatus = `Failed to connect: ${error.message}`;
|
|
305
309
|
console.warn(`Failed to auto-connect browser via tool: ${error.message}`);
|
|
306
|
-
// We don't throw here to allow the AI to potentially fix it or show the error
|
|
307
310
|
}
|
|
308
311
|
}
|
|
309
312
|
returnData.push({
|
|
310
313
|
json: {
|
|
311
314
|
success: true,
|
|
312
|
-
message: `MCP session initialized
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
})),
|
|
315
|
+
message: `MCP session initialized at ${credentials.mcpEndpoint}`,
|
|
316
|
+
browserConnection: connectionStatus,
|
|
317
|
+
browserResponse: connectionResult,
|
|
318
|
+
totalToolsAvailable: tools.length,
|
|
319
|
+
// We omit the full tools list here to keep the n8n UI clean
|
|
318
320
|
},
|
|
319
321
|
pairedItem: i,
|
|
320
322
|
});
|
|
@@ -65,6 +65,7 @@ async function createDynamicBrowserTools(credentials) {
|
|
|
65
65
|
properties: mcpSchemaToN8nProperties(mcpTool.inputSchema),
|
|
66
66
|
async execute(toolInput) {
|
|
67
67
|
try {
|
|
68
|
+
console.log(`[AI Agent] Executing tool: ${toolName}`);
|
|
68
69
|
const result = await sessionManager.callTool(toolName, toolInput);
|
|
69
70
|
return result;
|
|
70
71
|
}
|