UNPKG

ai-flashmob-mcp

Version:

MCP server for AI-powered flashcard generation

106 lines (93 loc) 2.91 kB
/** * Configuration for Flashcard Generator MCP Server */ export const config = { // Default API settings api: { baseUrl: process.env.API_BASE_URL || 'https://api.ai-flashmob.com', timeout: 30000, // 30 seconds retries: 3 }, // MCP server settings server: { name: 'flashcard-generator', version: '1.0.0', description: 'AI-powered flashcard generation from text and images' }, // Request limits limits: { textMinLength: 10, textMaxLength: 4000, maxCards: 10, minCards: 1, imageMaxSize: 10 * 1024 * 1024, // 10MB in bytes requestTimeout: 30000 // 30 seconds }, // Authentication settings auth: { signatureAlgorithm: 'sha256', timestampToleranceMs: 5 * 60 * 1000, // 5 minutes secretKeyLength: 64 // 64 hex characters }, // Logging configuration logging: { level: process.env.LOG_LEVEL || 'info', enableRequestLogging: process.env.ENABLE_REQUEST_LOGGING === 'true', enableErrorLogging: true }, // Rate limiting (client-side awareness) rateLimits: { requestsPerMinute: 60, requestsPer15Minutes: 100, burstLimit: 10 } }; /** * Validates the current configuration * @throws {Error} If configuration is invalid */ export function validateConfig() { // Validate API base URL try { new URL(config.api.baseUrl); } catch (error) { throw new Error(`Invalid API_BASE_URL: ${config.api.baseUrl}`); } // Validate required environment variables const requiredEnvVars = ['PUBLIC_USER_ID', 'SECRET_KEY']; const missingVars = requiredEnvVars.filter(varName => !process.env[varName]); if (missingVars.length > 0) { throw new Error(`Missing required environment variables: ${missingVars.join(', ')}`); } // Validate credential formats const publicUserId = process.env.PUBLIC_USER_ID; const secretKey = process.env.SECRET_KEY; // Validate UUID format for public user ID const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; if (!uuidRegex.test(publicUserId)) { throw new Error('PUBLIC_USER_ID must be a valid UUID format'); } // Validate secret key format if (secretKey.length !== config.auth.secretKeyLength || !/^[a-f0-9]+$/i.test(secretKey)) { throw new Error(`SECRET_KEY must be a ${config.auth.secretKeyLength}-character hexadecimal string`); } } /** * Gets the complete configuration with environment variables * @returns {Object} Complete configuration object */ export function getConfig() { return { ...config, credentials: { publicUserId: process.env.PUBLIC_USER_ID, secretKey: process.env.SECRET_KEY, // Note: Never log or expose the secret key }, environment: { nodeEnv: process.env.NODE_ENV || 'development', logLevel: process.env.LOG_LEVEL || 'info', enableRequestLogging: process.env.ENABLE_REQUEST_LOGGING === 'true' } }; }