feat: add n8n_generate_workflow tool for hosted workflow generation

Add new MCP tool that enables AI-powered workflow generation from natural
language descriptions. Uses handler delegation pattern — hosting environments
inject a GenerateWorkflowHandler via EngineOptions, self-hosted instances
receive a hosted-only informational response.

Handler flows through N8NMCPEngine → SingleSessionHTTPServer →
N8NDocumentationMCPServer with helpers for createWorkflow, validateWorkflow,
autofixWorkflow, and getWorkflow.

Includes full tool documentation, tests, and corrected tools overview count.

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2026-03-31 12:32:31 +02:00
parent 3417c6701c
commit 198e773bb3
81 changed files with 784 additions and 177 deletions

View File

@@ -45,7 +45,7 @@ function logSecurityEvent(event, details) {
logger_1.logger.info(`[SECURITY] ${event}`, logEntry);
}
class SingleSessionHTTPServer {
constructor() {
constructor(options) {
this.transports = {};
this.servers = {};
this.sessionMetadata = {};
@@ -53,9 +53,10 @@ class SingleSessionHTTPServer {
this.contextSwitchLocks = new Map();
this.session = null;
this.consoleManager = new console_manager_1.ConsoleManager();
this.sessionTimeout = parseInt(process.env.SESSION_TIMEOUT_MINUTES || '5', 10) * 60 * 1000;
this.sessionTimeout = parseInt(process.env.SESSION_TIMEOUT_MINUTES || '30', 10) * 60 * 1000;
this.authToken = null;
this.cleanupTimer = null;
this.generateWorkflowHandler = options?.generateWorkflowHandler;
this.validateEnvironment();
this.startSessionCleanup();
}
@@ -340,7 +341,9 @@ class SingleSessionHTTPServer {
else {
sessionIdToUse = sessionId || (0, uuid_1.v4)();
}
const server = new server_1.N8NDocumentationMCPServer(instanceContext);
const server = new server_1.N8NDocumentationMCPServer(instanceContext, undefined, {
generateWorkflowHandler: this.generateWorkflowHandler,
});
transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
sessionIdGenerator: () => sessionIdToUse,
onsessioninitialized: (initializedSessionId) => {
@@ -504,7 +507,9 @@ class SingleSessionHTTPServer {
}
try {
logger_1.logger.info('Creating new N8NDocumentationMCPServer for SSE...');
const server = new server_1.N8NDocumentationMCPServer();
const server = new server_1.N8NDocumentationMCPServer(undefined, undefined, {
generateWorkflowHandler: this.generateWorkflowHandler,
});
const sessionId = (0, uuid_1.v4)();
logger_1.logger.info('Creating SSEServerTransport...');
const transport = new sse_js_1.SSEServerTransport('/mcp', res);