mcp-prompt-optimizer 1.3.2 โ†’ 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,13 +2,18 @@
2
2
 
3
3
  /**
4
4
  * Validate Key Utility for MCP Prompt Optimizer
5
- * Focused validation without full status display
5
+ * Enhanced with production resilience and development mode support
6
+ * ALIGNED with backend expectations and enhanced error handling
6
7
  */
7
8
 
8
9
  const CloudApiKeyManager = require('./api-key-manager');
10
+ const packageJson = require('../package.json');
9
11
 
10
12
  async function validateKey() {
11
- console.log('๐Ÿ”‘ MCP Prompt Optimizer - API Key Validation\n');
13
+ const developmentMode = process.env.NODE_ENV === 'development' || process.env.OPTIMIZER_DEV_MODE === 'true';
14
+ const modeText = developmentMode ? ' (Development Mode)' : '';
15
+
16
+ console.log(`๐Ÿ”‘ MCP Prompt Optimizer v${packageJson.version} - API Key Validation${modeText}\n`);
12
17
 
13
18
  try {
14
19
  // Get API key from environment
@@ -21,82 +26,194 @@ async function validateKey() {
21
26
  console.log(' export OPTIMIZER_API_KEY=sk-opt-your-key-here');
22
27
  console.log('\n๐Ÿ†“ Get your API key:');
23
28
  console.log(' https://promptoptimizer-blog.vercel.app/pricing');
29
+ console.log('\n๐Ÿ’ฐ Free trial: 5 optimizations with full feature access');
30
+
31
+ if (developmentMode) {
32
+ console.log('\n๐Ÿงช Development Mode Options:');
33
+ console.log(' export OPTIMIZER_API_KEY=sk-dev-test-key');
34
+ console.log(' export OPTIMIZER_API_KEY=sk-local-test-key');
35
+ console.log(' Features: Mock optimization, offline operation, no backend required');
36
+ }
37
+
24
38
  process.exit(1);
25
39
  }
26
40
 
27
41
  console.log(`๐Ÿ”‘ Testing API key: ${apiKey.substring(0, 16)}...`);
28
42
 
29
43
  // Validate format first
30
- if (!apiKey.startsWith('sk-opt-') && !apiKey.startsWith('sk-team-')) {
44
+ const manager = new CloudApiKeyManager(apiKey, { developmentMode });
45
+ const formatCheck = manager.validateApiKeyFormat(apiKey);
46
+
47
+ if (!formatCheck.valid) {
31
48
  console.error('โŒ Invalid API key format');
32
49
  console.log('\nโœ… Valid formats:');
33
50
  console.log(' - Individual: sk-opt-...');
34
51
  console.log(' - Team: sk-team-...');
52
+ console.log(' - Development: sk-local-...');
53
+ console.log(' - Testing: sk-dev-...');
35
54
  console.log('\n๐Ÿ”ง Get a properly formatted key at:');
36
55
  console.log(' https://promptoptimizer-blog.vercel.app/pricing');
37
56
  process.exit(1);
38
57
  }
39
58
 
40
- // Create manager and validate
41
- const manager = new CloudApiKeyManager(apiKey);
59
+ console.log(`โœ… API key format valid: ${formatCheck.keyType}`);
42
60
 
61
+ // Enhanced validation with development mode support
43
62
  console.log('โณ Connecting to backend...');
44
- const validation = await manager.validateAndPrepare();
45
-
46
- console.log('โœ… API Key Validation: SUCCESS\n');
63
+ console.log(`๐Ÿ“ก Backend URL: ${manager.backendUrl}`);
47
64
 
48
- console.log('๐Ÿ“Š Key Details:');
49
- console.log(` Tier: ${validation.tier}`);
50
- console.log(` Type: ${apiKey.startsWith('sk-team-') ? 'Team' : 'Individual'}`);
51
-
52
- if (validation.quotaStatus.unlimited) {
53
- console.log(' Quota: Unlimited optimizations โœจ');
54
- } else {
55
- console.log(` Quota: ${validation.quotaStatus.remaining}/${validation.quotaStatus.limit} remaining`);
65
+ if (developmentMode || formatCheck.keyType === 'development' || formatCheck.keyType === 'testing') {
66
+ console.log('๐Ÿงช Development/testing mode detected - using mock validation');
56
67
  }
57
-
58
- console.log('\nโœจ Available Features:');
59
- const features = validation.features || {};
60
- console.log(' โœ… Professional AI optimization');
61
- console.log(' โœ… AI context detection');
62
- console.log(' โœ… Template management');
63
- console.log(' โœ… Cloud processing');
64
68
 
65
- if (validation.tier !== 'explorer') {
66
- console.log(' โœ… Team collaboration');
67
- console.log(' โœ… Optimization insights');
68
- }
69
+ try {
70
+ const validation = await manager.validateAndPrepare();
71
+
72
+ console.log('โœ… API Key Validation: SUCCESS\n');
73
+
74
+ // Enhanced status reporting
75
+ console.log('๐Ÿ“Š Key Details:');
76
+ console.log(` Tier: ${validation.tier.charAt(0).toUpperCase() + validation.tier.slice(1)}`);
77
+ console.log(` Type: ${apiKey.startsWith('sk-team-') ? 'Team' :
78
+ apiKey.startsWith('sk-local-') ? 'Development' :
79
+ apiKey.startsWith('sk-dev-') ? 'Testing' : 'Individual'}`);
80
+
81
+ // Mode indicators
82
+ const modes = [];
83
+ if (validation.mode.development) modes.push('Development');
84
+ if (validation.mode.mock) modes.push('Mock');
85
+ if (validation.mode.fallback) modes.push('Fallback');
86
+ if (validation.mode.offline) modes.push('Offline');
87
+
88
+ if (modes.length > 0) {
89
+ console.log(` Mode: ${modes.join(', ')}`);
90
+ }
91
+
92
+ // Quota information
93
+ if (validation.quotaStatus.unlimited) {
94
+ console.log(' Quota: Unlimited optimizations โœจ');
95
+ } else {
96
+ console.log(` Quota: ${validation.quotaStatus.remaining}/${validation.quotaStatus.limit} remaining`);
97
+ const usagePercent = ((validation.quotaStatus.limit - validation.quotaStatus.remaining) / validation.quotaStatus.limit) * 100;
98
+ console.log(` Usage: ${usagePercent.toFixed(1)}%`);
99
+ }
69
100
 
70
- console.log('\n๐Ÿš€ Your API key is ready to use!');
71
- console.log('\n๐Ÿ“– Next Steps:');
72
- console.log(' 1. Add to Claude Desktop config:');
73
- console.log(' "env": { "OPTIMIZER_API_KEY": "' + apiKey + '" }');
74
- console.log(' 2. Start optimizing: Use the optimize_prompt tool');
75
- console.log(' 3. Check status: mcp-prompt-optimizer check-status');
101
+ console.log('\nโœจ Available Features (All Plans):');
102
+ console.log(' โœ… Professional AI optimization with context detection');
103
+ console.log(' โœ… AI context detection (image gen, LLM interaction, technical)');
104
+ console.log(' โœ… Template auto-save and search');
105
+ console.log(' โœ… Optimization insights and analytics');
106
+ console.log(' โœ… Cloud processing with latest AI models');
107
+ console.log(' โœ… Universal MCP compatibility');
108
+ console.log(' โœ… Network resilience and fallback modes');
109
+
110
+ if (validation.mode.development || validation.mode.mock) {
111
+ console.log(' ๐Ÿงช Development mode features');
112
+ console.log(' ๐Ÿ”„ Mock optimization (no backend required)');
113
+ console.log(' ๐Ÿ“ด Offline operation capability');
114
+ }
115
+
116
+ if (apiKey.startsWith('sk-team-')) {
117
+ console.log(' โœ… Team collaboration features');
118
+ console.log(' โœ… Shared quotas and templates');
119
+ }
76
120
 
121
+ console.log('\n๐Ÿš€ Your API key is ready to use!');
122
+ console.log('\n๐Ÿ“– Next Steps:');
123
+ console.log(' 1. Add to Claude Desktop config:');
124
+ console.log(' "env": { "OPTIMIZER_API_KEY": "' + apiKey + '" }');
125
+ console.log(' 2. Start optimizing: Use the optimize_prompt tool');
126
+ console.log(' 3. Check status: mcp-prompt-optimizer check-status');
127
+ console.log(' 4. Test integration: mcp-prompt-optimizer test');
128
+
129
+ console.log('\n๐ŸŽฏ Professional Cloud Features:');
130
+ console.log(' ๐Ÿง  Intelligent AI context detection');
131
+ console.log(' ๐Ÿ“ Automatic template management');
132
+ console.log(' ๐Ÿ“Š Real-time optimization insights');
133
+ console.log(' โ˜๏ธ Always up-to-date cloud processing');
134
+ console.log(' ๐Ÿ”„ Network resilience and fallback support');
135
+
136
+ if (validation.mode.fallback) {
137
+ console.log('\nโš ๏ธ Fallback Mode Active:');
138
+ console.log(' Backend temporarily unavailable, using cached validation');
139
+ console.log(' Limited functionality - try again when network is restored');
140
+ }
141
+
142
+ if (validation.mode.mock || validation.mode.development) {
143
+ console.log('\n๐Ÿงช Development Mode Benefits:');
144
+ console.log(' ๐Ÿ”ง No backend dependency required');
145
+ console.log(' ๐Ÿš€ Instant optimization responses');
146
+ console.log(' ๐Ÿ“ด Perfect for offline development');
147
+ console.log(' ๐Ÿงช Safe testing environment');
148
+ }
149
+
150
+ } catch (error) {
151
+ console.error(`โŒ Validation Failed: ${error.message}\n`);
152
+
153
+ if (error.message.includes('Network error') || error.message.includes('timeout') || error.message.includes('DNS')) {
154
+ console.log('๐ŸŒ Connection Issue:');
155
+ console.log(' - Check your internet connection');
156
+ console.log(' - Verify firewall/proxy settings');
157
+ console.log(' - Backend may be temporarily unavailable');
158
+ console.log(' - Try again in a moment');
159
+
160
+ if (!developmentMode) {
161
+ console.log('\n๐Ÿงช Try Development Mode:');
162
+ console.log(' export OPTIMIZER_DEV_MODE=true');
163
+ console.log(' export OPTIMIZER_API_KEY=sk-dev-test-key');
164
+ console.log(' mcp-prompt-optimizer validate-key');
165
+ }
166
+ } else if (error.message.includes('401') || error.message.includes('Invalid') || error.message.includes('unauthorized')) {
167
+ console.log('๐Ÿ”‘ API Key Issue:');
168
+ console.log(' - Verify your subscription is active');
169
+ console.log(' - Check key format (sk-opt-*, sk-team-*, sk-dev-*, or sk-local-)');
170
+ console.log(' - Key may be expired or deactivated');
171
+ console.log(' - Get a new key: https://promptoptimizer-blog.vercel.app/pricing');
172
+ } else if (error.message.includes('quota') || error.message.includes('429')) {
173
+ console.log('๐Ÿ“Š Quota Issue:');
174
+ console.log(' - Your monthly quota is exhausted');
175
+ console.log(' - Upgrade: https://promptoptimizer-blog.vercel.app/pricing');
176
+ console.log(' - Check usage: mcp-prompt-optimizer check-status');
177
+ } else if (error.message.includes('500')) {
178
+ console.log('โš ๏ธ Server Issue:');
179
+ console.log(' - Backend server error');
180
+ console.log(' - Try again in a few minutes');
181
+ console.log(' - If persistent, contact support');
182
+ } else {
183
+ console.log('๐Ÿ”ง General Troubleshooting:');
184
+ console.log(' 1. Clear cache: mcp-prompt-optimizer clear-cache');
185
+ console.log(' 2. Run diagnostic: mcp-prompt-optimizer diagnose');
186
+ console.log(' 3. Test integration: mcp-prompt-optimizer test');
187
+ console.log(' 4. Check dashboard: https://promptoptimizer-blog.vercel.app/dashboard');
188
+ console.log(' 5. Contact support: support@promptoptimizer.help');
189
+
190
+ if (!developmentMode) {
191
+ console.log(' 6. Try development mode: export OPTIMIZER_DEV_MODE=true');
192
+ }
193
+ }
194
+
195
+ // Suggest network health check
196
+ console.log('\n๐Ÿ” Network Health Analysis:');
197
+ console.log(' Run: mcp-prompt-optimizer diagnose');
198
+ console.log(' This will analyze network connectivity and provide detailed troubleshooting');
199
+
200
+ process.exit(1);
201
+ }
202
+
77
203
  } catch (error) {
78
- console.error(`โŒ Validation Failed: ${error.message}\n`);
204
+ console.error(`โŒ Unexpected error: ${error.message}`);
205
+ console.log('\n๐Ÿ› ๏ธ Emergency Troubleshooting:');
206
+ console.log(' 1. Ensure Node.js version >= 16.0.0');
207
+ console.log(' 2. Reinstall dependencies: npm install');
208
+ console.log(' 3. Clear all caches: mcp-prompt-optimizer clear-cache');
209
+ console.log(' 4. Run diagnostics: mcp-prompt-optimizer diagnose');
210
+ console.log(' 5. Contact support: support@promptoptimizer.help');
79
211
 
80
- if (error.message.includes('Network error')) {
81
- console.log('๐ŸŒ Connection Issue:');
82
- console.log(' - Check your internet connection');
83
- console.log(' - Verify firewall/proxy settings');
84
- console.log(' - Try again in a moment');
85
- } else if (error.message.includes('401') || error.message.includes('Invalid')) {
86
- console.log('๐Ÿ”‘ API Key Issue:');
87
- console.log(' - Verify your subscription is active');
88
- console.log(' - Check key format (sk-opt-* or sk-team-*)');
89
- console.log(' - Get a new key: https://promptoptimizer-blog.vercel.app/pricing');
90
- } else if (error.message.includes('quota')) {
91
- console.log('๐Ÿ“Š Quota Issue:');
92
- console.log(' - Your monthly quota is exhausted');
93
- console.log(' - Upgrade: https://promptoptimizer-blog.vercel.app/pricing');
94
- console.log(' - Check usage: mcp-prompt-optimizer check-status');
95
- } else {
96
- console.log('๐Ÿ”ง Troubleshooting:');
97
- console.log(' 1. Clear cache: mcp-prompt-optimizer clear-cache');
98
- console.log(' 2. Check dashboard: https://promptoptimizer-blog.vercel.app/dashboard');
99
- console.log(' 3. Contact support: support@promptoptimizer.help');
212
+ if (!developmentMode) {
213
+ console.log('\n๐Ÿงช Try Development Mode for Offline Testing:');
214
+ console.log(' export OPTIMIZER_DEV_MODE=true');
215
+ console.log(' export OPTIMIZER_API_KEY=sk-dev-test-key');
216
+ console.log(' mcp-prompt-optimizer validate-key');
100
217
  }
101
218
 
102
219
  process.exit(1);