mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 05:23:08 +00:00
- Register n8n_autofix_workflow handler in MCP server - Export n8nAutofixWorkflowDoc in tool documentation indices - Use normalizeNodeType utility in workflow validator for consistent type handling - Add defensive null checks in template sanitizer to prevent runtime errors - Update workflow validator test to handle new error message formats These changes complete the webhook autofixer integration, ensuring the tool is properly exposed through the MCP server and documentation system. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
#!/usr/bin/env node
|
|
import { createDatabaseAdapter } from '../database/database-adapter';
|
|
import { logger } from '../utils/logger';
|
|
import { TemplateSanitizer } from '../utils/template-sanitizer';
|
|
|
|
async function sanitizeTemplates() {
|
|
console.log('🧹 Sanitizing workflow templates in database...\n');
|
|
|
|
const db = await createDatabaseAdapter('./data/nodes.db');
|
|
const sanitizer = new TemplateSanitizer();
|
|
|
|
try {
|
|
// Get all templates
|
|
const templates = db.prepare('SELECT id, name, workflow_json FROM templates').all() as any[];
|
|
console.log(`Found ${templates.length} templates to check\n`);
|
|
|
|
let sanitizedCount = 0;
|
|
const problematicTemplates: any[] = [];
|
|
|
|
for (const template of templates) {
|
|
if (!template.workflow_json) {
|
|
continue; // Skip templates without workflow data
|
|
}
|
|
|
|
let originalWorkflow;
|
|
try {
|
|
originalWorkflow = JSON.parse(template.workflow_json);
|
|
} catch (e) {
|
|
console.log(`⚠️ Skipping template ${template.id}: Invalid JSON`);
|
|
continue;
|
|
}
|
|
|
|
const { sanitized: sanitizedWorkflow, wasModified } = sanitizer.sanitizeWorkflow(originalWorkflow);
|
|
|
|
if (wasModified) {
|
|
// Get detected tokens for reporting
|
|
const detectedTokens = sanitizer.detectTokens(originalWorkflow);
|
|
|
|
// Update the template with sanitized version
|
|
const stmt = db.prepare('UPDATE templates SET workflow_json = ? WHERE id = ?');
|
|
stmt.run(JSON.stringify(sanitizedWorkflow), template.id);
|
|
|
|
sanitizedCount++;
|
|
problematicTemplates.push({
|
|
id: template.id,
|
|
name: template.name,
|
|
tokens: detectedTokens
|
|
});
|
|
|
|
console.log(`✅ Sanitized template ${template.id}: ${template.name}`);
|
|
detectedTokens.forEach(token => {
|
|
console.log(` - Found: ${token.substring(0, 20)}...`);
|
|
});
|
|
}
|
|
}
|
|
|
|
console.log(`\n📊 Summary:`);
|
|
console.log(` Total templates: ${templates.length}`);
|
|
console.log(` Sanitized: ${sanitizedCount}`);
|
|
|
|
if (problematicTemplates.length > 0) {
|
|
console.log(`\n⚠️ Templates that contained API tokens:`);
|
|
problematicTemplates.forEach(t => {
|
|
console.log(` - ${t.id}: ${t.name}`);
|
|
});
|
|
}
|
|
|
|
console.log('\n✨ Sanitization complete!');
|
|
} catch (error) {
|
|
console.error('❌ Error sanitizing templates:', error);
|
|
process.exit(1);
|
|
} finally {
|
|
db.close();
|
|
}
|
|
}
|
|
|
|
// Run if called directly
|
|
if (require.main === module) {
|
|
sanitizeTemplates().catch(console.error);
|
|
} |