import { MCPServer } from 'mcp-framework';
import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';
import WorkflowValidatorTool from './tools/WorkflowValidatorTool.js';
import N8nApiTool from './tools/N8nApiTool.js';
import NextJSIntegrationTool from './tools/NextJSIntegrationTool.js';
import WorkflowManagerTool from './tools/WorkflowManagerTool.js';
// Charger les variables d'environnement
dotenv.config();
// Créer des équivalents à __dirname et __filename pour les modules ES
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Configuration du serveur MCP
const PORT = process.env.PORT || 3000;
// Initialiser les outils
const workflowValidatorTool = new WorkflowValidatorTool();
const n8nApiTool = new N8nApiTool();
const nextJSIntegrationTool = new NextJSIntegrationTool();
const workflowManagerTool = new WorkflowManagerTool();
// Afficher les informations sur les outils
console.log('Outils initialisés :');
console.log(`- ${workflowValidatorTool.name}: ${workflowValidatorTool.description}`);
console.log(`- ${n8nApiTool.name}: ${n8nApiTool.description}`);
console.log(`- ${nextJSIntegrationTool.name}: ${nextJSIntegrationTool.description}`);
console.log(`- ${workflowManagerTool.name}: ${workflowManagerTool.description}`);
// Exposer les outils via une propriété globale (hack pour contourner l'auto-découverte)
(global as any).MCPTools = {
[workflowValidatorTool.name]: workflowValidatorTool,
[n8nApiTool.name]: n8nApiTool,
[nextJSIntegrationTool.name]: nextJSIntegrationTool,
[workflowManagerTool.name]: workflowManagerTool
};
// Afficher les outils exposés
console.log('Outils exposés via MCPTools :');
console.log(Object.keys((global as any).MCPTools));
// Créer et configurer le serveur MCP
const server = new MCPServer({
name: 'n8n-mcp-server',
transport: {
type: 'sse',
options: {
port: Number(PORT)
}
}
});
// Démarrer le serveur
server.start()
.then(() => {
console.log(`Serveur MCP n8n démarré sur le port ${PORT}`);
console.log(`URL: http://localhost:${PORT}`);
// Afficher les outils disponibles
console.log('Outils disponibles:');
console.log(` - ${workflowValidatorTool.name}: ${workflowValidatorTool.description}`);
console.log(` - ${n8nApiTool.name}: ${n8nApiTool.description}`);
console.log(` - ${nextJSIntegrationTool.name}: ${nextJSIntegrationTool.description}`);
console.log(` - ${workflowManagerTool.name}: ${workflowManagerTool.description}`);
})
.catch((error) => {
console.error('Erreur lors du démarrage du serveur MCP:', error);
});