UNPKG

mcp-prompt-optimizer

Version:

Professional cloud-based MCP server for AI-powered prompt optimization with intelligent context detection, team collaboration, enterprise-grade features, startup validation, and robust API key management. Universal compatibility with Claude Desktop, Curso

100 lines (84 loc) • 3.55 kB
#!/usr/bin/env node /** * Clear Cache Utility for MCP Prompt Optimizer * Clears validation cache and provides fresh start */ const CloudApiKeyManager = require('./api-key-manager'); const fs = require('fs').promises; const path = require('path'); const os = require('os'); async function clearCache() { console.log('šŸ—‘ļø MCP Prompt Optimizer - Clear Cache\n'); const cacheFile = path.join(os.homedir(), '.mcp-cloud-api-cache.json'); let cacheCleared = false; try { // Check if cache file exists await fs.access(cacheFile); // Read cache info before clearing try { const cacheContent = await fs.readFile(cacheFile, 'utf8'); const cacheData = JSON.parse(cacheContent); const cacheAge = Date.now() - cacheData.timestamp; const ageHours = Math.floor(cacheAge / (1000 * 60 * 60)); const ageMinutes = Math.floor((cacheAge % (1000 * 60 * 60)) / (1000 * 60)); console.log('šŸ“„ Found cache file:'); console.log(` Location: ${cacheFile}`); console.log(` Age: ${ageHours}h ${ageMinutes}m`); if (cacheData.data && cacheData.data.tier) { console.log(` Cached tier: ${cacheData.data.tier}`); } } catch (parseError) { console.log('šŸ“„ Found cache file (invalid format)'); } // Clear the cache await fs.unlink(cacheFile); cacheCleared = true; console.log('\nāœ… Cache cleared successfully'); } catch (error) { if (error.code === 'ENOENT') { console.log('šŸ“„ No cache file found - nothing to clear'); } else { console.warn(`āš ļø Error accessing cache: ${error.message}`); } } // Also try to clear any additional cache files const additionalCaches = [ path.join(os.homedir(), '.mcp-prompt-optimizer-cache.json'), path.join(os.homedir(), '.optimizer-cache.json'), path.join(os.homedir(), '.mcp-cache.json') ]; for (const cacheFile of additionalCaches) { try { await fs.access(cacheFile); await fs.unlink(cacheFile); console.log(`āœ… Cleared additional cache: ${path.basename(cacheFile)}`); cacheCleared = true; } catch (error) { // File doesn't exist, that's fine } } if (cacheCleared) { console.log('\nšŸš€ Cache cleared - next validation will be fresh'); console.log('\nšŸ“ What this means:'); console.log(' - API key will be re-validated with backend'); console.log(' - Fresh quota information will be fetched'); console.log(' - Any cached errors will be cleared'); console.log('\nšŸ”§ Next Steps:'); console.log(' 1. Test your API key: mcp-prompt-optimizer validate-key'); console.log(' 2. Check status: mcp-prompt-optimizer check-status'); console.log(' 3. Start using: Configure in Claude Desktop'); } else { console.log('\n✨ No cache found - your setup is already clean'); } // Offer to validate immediately console.log('\nšŸ’” Want to validate your API key now?'); console.log(' Run: mcp-prompt-optimizer validate-key'); } // Run if called directly if (require.main === module) { clearCache().catch(error => { console.error(`āŒ Error clearing cache: ${error.message}`); process.exit(1); }); } module.exports = clearCache;