UNPKG

pms-analysis-reports-mcp-server

Version:

PMS analysis reports server handling maintenance reports, equipment analysis, compliance tracking, and performance metrics with ERP access for data extraction

83 lines 3.64 kB
import dotenv from 'dotenv'; import path from 'path'; import fs from 'fs'; // Function to sync environment variables from siya-desktop-config.json function syncEnvironmentFromConfig() { try { // Dynamically find siya-desktop-config.json const possiblePaths = [ process.env.SIYA_CONFIG_PATH, path.join(process.env.HOME || process.env.USERPROFILE || '', '.siya', 'config', 'siya-desktop-config.json'), path.join(process.cwd(), '..', '..', '..', '.siya', 'config', 'siya-desktop-config.json'), '/Users/sulagna.b/.siya/config/siya-desktop-config.json' // fallback ]; let configPath; for (const possiblePath of possiblePaths) { if (possiblePath && fs.existsSync(possiblePath)) { configPath = possiblePath; break; } } if (configPath) { const configContent = fs.readFileSync(configPath, 'utf8'); const config = JSON.parse(configContent); // Get the pms_analysis_reports_tools environment variables const pmsConfig = config.mcpServers?.['pms_analysis_reports_tools']; if (pmsConfig?.env) { // Set environment variables from config (override existing values) Object.entries(pmsConfig.env).forEach(([key, value]) => { process.env[key] = value; }); console.log(`✅ Synced ${Object.keys(pmsConfig.env).length} environment variables from ${configPath}`); } } else { console.log('ℹ️ siya-desktop-config.json not found, using environment variables only'); } } catch (error) { console.warn('⚠️ Could not sync environment variables from siya-desktop-config.json:', error.message); } } // Load environment-specific .env file first (lower priority) const NODE_ENV = process.env.NODE_ENV || 'development'; const envPath = path.resolve(process.cwd(), `.env.${NODE_ENV}`); const defaultEnvPath = path.resolve(process.cwd(), '.env'); if (fs.existsSync(envPath)) { dotenv.config({ path: envPath }); } else { dotenv.config({ path: defaultEnvPath }); } // Sync environment variables from siya-desktop-config.json (higher priority - overrides .env) syncEnvironmentFromConfig(); // Parse and validate configuration function createConfig() { const config = { environment: NODE_ENV, companyName: '', }; // Set service name for logging process.env.SERVICE_NAME = 'pms-mcp-server'; // Set company name from environment or default config.companyName = process.env.COMPANY_NAME || process.env.companyName || 'Synergy'; // Process all environment variables Object.keys(process.env).forEach(envKey => { const camelCaseKey = envKey.match(/^[a-z][a-zA-Z0-9]*$/) ? envKey : envKey.toLowerCase().replace(/[_-]([a-z])/g, (_, letter) => letter.toUpperCase()); config[camelCaseKey] = process.env[envKey]; }); // Log important configuration values console.log(`🏢 Company: ${config.companyName}`); console.log(`🌍 Environment: ${config.environment}`); console.log(`🔗 MongoDB URI configured: ${!!config.mongodbEtlDevDataUri}`); console.log(`🗄️ Database name: ${config.mongodbEtlDevDataDbName}`); // Validate required fields if (!config.companyName) { throw new Error('Company name is mandatory. Please provide it via companyName environment variable.'); } return config; } export const config = createConfig(); //# sourceMappingURL=index.js.map