UNPKG

@utaba/ucm-mcp-server

Version:

Universal Context Manager MCP Server - AI Productivity Platform

90 lines 3.41 kB
// Source: Independent MCP Server configuration management // This class centralizes ALL MCP Server configuration and environment variables export class McpConfig { config; constructor(options = {}) { const authToken = options.authToken || this.getEnvVar('UCM_AUTH_TOKEN', ''); const authorId = this.extractAuthorIdFromToken(authToken); this.config = { ucmApiUrl: options.ucmApiUrl || this.getEnvVar('UCM_API_URL', 'https://ucm.utaba.ai'), port: options.port || parseInt(this.getEnvVar('MCP_PORT', '3001')), authToken: authToken, authorId: options.authorId || authorId, logLevel: options.logLevel || this.getEnvVar('MCP_LOG_LEVEL', 'ERROR'), requestTimeout: options.requestTimeout || parseInt(this.getEnvVar('MCP_REQUEST_TIMEOUT', '300000')), trustedAuthors: options.trustedAuthors || this.parseTrustedAuthors(this.getEnvVar('MCP_TRUSTED_AUTHORS', '')) }; this.validateConfig(); } extractAuthorIdFromToken(authToken) { if (!authToken || authToken.trim() === '') { return undefined; } const parts = authToken.split(':'); if (parts.length >= 2 && parts[0].trim() !== '') { return parts[0].trim(); } return undefined; } getEnvVar(name, defaultValue) { const value = process.env[name]; if (value !== undefined) { return value; } if (defaultValue !== undefined) { return defaultValue; } throw new Error(`Required environment variable ${name} is not set`); } parseTrustedAuthors(authorsString) { if (!authorsString || authorsString.trim() === '') { return []; } const authors = authorsString.split(',').map(author => author.trim()).filter(Boolean); const validAuthorPattern = /^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$/; for (const author of authors) { if (!validAuthorPattern.test(author)) { throw new Error(`Invalid trusted author format: "${author}". Authors must be alphanumeric with optional hyphens (no consecutive hyphens).`); } } return authors; } validateConfig() { if (!this.config.ucmApiUrl.startsWith('http')) { throw new Error('UCM API URL must be a valid HTTP/HTTPS URL'); } if (this.config.port < 1 || this.config.port > 65535) { throw new Error('Port must be between 1 and 65535'); } if (!['DEBUG', 'INFO', 'WARN', 'ERROR'].includes(this.config.logLevel)) { throw new Error('Log level must be one of: DEBUG, INFO, WARN, ERROR'); } } // Getters for configuration values get ucmApiUrl() { return this.config.ucmApiUrl; } get port() { return this.config.port; } get authToken() { return this.config.authToken; } get logLevel() { return this.config.logLevel; } get requestTimeout() { return this.config.requestTimeout; } get trustedAuthors() { return this.config.trustedAuthors; } get authorId() { return this.config.authorId; } // Get full configuration object (for testing and debugging) getFullConfig() { return { ...this.config }; } } //# sourceMappingURL=McpConfig.js.map