UNPKG

claudeus-wp-mcp

Version:

The most comprehensive WordPress MCP server - 145 production-ready tools for complete WordPress management with AI

50 lines 2.03 kB
import fs from 'fs/promises'; // Custom logger that ensures we only write to stderr const log = { info: (...args) => console.error('\x1b[32m%s\x1b[0m', '[SUCCESS]', ...args), error: (...args) => console.error('[ERROR]', ...args), debug: (...args) => console.error('[DEBUG]', ...args), warn: (...args) => console.error('[WARN]', ...args) }; export async function loadSiteConfig() { const configPath = process.env.WP_SITES_PATH; if (!configPath) { throw new Error("WP_SITES_PATH environment variable is required"); } try { const configData = await fs.readFile(configPath, 'utf8'); const config = JSON.parse(configData); // Validate and normalize the config const normalizedConfig = {}; for (const [alias, site] of Object.entries(config)) { if (!site.URL || !site.USER || !site.PASS) { log.error(`Invalid configuration for site ${alias}: missing required fields`); continue; } try { const url = site.URL.startsWith('http') ? site.URL : `http://${site.URL}`; new URL(url); normalizedConfig[alias.toLowerCase()] = { url: url.replace(/\/$/, ''), username: site.USER, auth: site.PASS, authType: (site.authType || 'basic') }; } catch (error) { throw new Error(`Invalid site URL: ${site.URL} - ${error instanceof Error ? error.message : 'Unknown error'}`); } } if (Object.keys(normalizedConfig).length === 0) { throw new Error('No valid site configurations found'); } return normalizedConfig; } catch (error) { if (error instanceof Error && 'code' in error && error.code === 'ENOENT') { throw new Error(`Config file not found at: ${configPath}`); } throw error; } } //# sourceMappingURL=site-config.js.map