n8n-mcp
Version:
Integration between n8n workflow automation and Model Context Protocol (MCP)
60 lines • 3.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const n8n_api_1 = require("../config/n8n-api");
const tools_1 = require("../mcp/tools");
const tools_n8n_manager_1 = require("../mcp/tools-n8n-manager");
async function testLazyConfigLoading() {
console.log('=== Testing Lazy Configuration Loading ===\n');
console.log('Test 1: Initial state (no env vars)');
delete process.env.N8N_API_URL;
delete process.env.N8N_API_KEY;
let isConfigured = (0, n8n_api_1.isN8nApiConfigured)();
let config = (0, n8n_api_1.getN8nApiConfig)();
console.log(`- Is configured: ${isConfigured}`);
console.log(`- Config: ${config ? 'Present' : 'Null'}`);
console.log(`- Expected tools: ${tools_1.n8nDocumentationToolsFinal.length} (documentation only)\n`);
console.log('Test 2: After setting environment variables');
process.env.N8N_API_URL = 'https://example.n8n.cloud';
process.env.N8N_API_KEY = 'test-api-key';
await new Promise(resolve => setTimeout(resolve, 100));
isConfigured = (0, n8n_api_1.isN8nApiConfigured)();
config = (0, n8n_api_1.getN8nApiConfig)();
console.log(`- Is configured: ${isConfigured}`);
console.log(`- Config: ${config ? 'Present' : 'Null'}`);
console.log(`- Config URL: ${config?.baseUrl || 'N/A'}`);
console.log(`- Expected tools: ${tools_1.n8nDocumentationToolsFinal.length + tools_n8n_manager_1.n8nManagementTools.length} (documentation + management)\n`);
console.log('Test 3: Simulating MCP server tool listing');
const tools = [...tools_1.n8nDocumentationToolsFinal];
if ((0, n8n_api_1.isN8nApiConfigured)()) {
tools.push(...tools_n8n_manager_1.n8nManagementTools);
console.log(`- Management tools added: ${tools_n8n_manager_1.n8nManagementTools.length}`);
}
console.log(`- Total tools available: ${tools.length}`);
console.log(`- Documentation tools: ${tools_1.n8nDocumentationToolsFinal.length}`);
console.log(`- Management tools: ${(0, n8n_api_1.isN8nApiConfigured)() ? tools_n8n_manager_1.n8nManagementTools.length : 0}\n`);
console.log('Test 4: After removing environment variables');
delete process.env.N8N_API_URL;
delete process.env.N8N_API_KEY;
await new Promise(resolve => setTimeout(resolve, 5100));
isConfigured = (0, n8n_api_1.isN8nApiConfigured)();
config = (0, n8n_api_1.getN8nApiConfig)();
console.log(`- Is configured: ${isConfigured}`);
console.log(`- Config: ${config ? 'Present' : 'Null'}`);
console.log(`- Expected tools: ${tools_1.n8nDocumentationToolsFinal.length} (documentation only)\n`);
console.log('Test 5: Testing cache behavior');
process.env.N8N_API_URL = 'https://example2.n8n.cloud';
process.env.N8N_API_KEY = 'test-api-key-2';
await new Promise(resolve => setTimeout(resolve, 5100));
const config1 = (0, n8n_api_1.getN8nApiConfig)();
console.log(`- First call URL: ${config1?.baseUrl}`);
const config2 = (0, n8n_api_1.getN8nApiConfig)();
console.log(`- Second call URL: ${config2?.baseUrl}`);
console.log(`- URLs match: ${config1?.baseUrl === config2?.baseUrl}\n`);
console.log('=== All tests completed ===');
}
testLazyConfigLoading().catch(error => {
console.error('Test failed:', error);
process.exit(1);
});
//# sourceMappingURL=test-lazy-config.js.map