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.
- package/CHANGELOG.md +85 -0
- package/README.md +286 -130
- package/index.js +1092 -724
- package/lib/api-key-manager.js +538 -46
- package/lib/check-status.js +356 -111
- package/lib/clear-cache.js +113 -79
- package/lib/diagnose.js +252 -0
- package/lib/diagnose.js file.txt +252 -0
- package/lib/test-integration.js +250 -0
- package/lib/validate-key.js +171 -54
- package/package.json +224 -28
package/lib/validate-key.js
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Validate Key Utility for MCP Prompt Optimizer
|
|
5
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
console.log('โ
API Key Validation: SUCCESS\n');
|
|
63
|
+
console.log(`๐ก Backend URL: ${manager.backendUrl}`);
|
|
47
64
|
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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(`โ
|
|
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 (
|
|
81
|
-
console.log('
|
|
82
|
-
console.log('
|
|
83
|
-
console.log(' -
|
|
84
|
-
console.log(' -
|
|
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);
|