mcp-prompt-optimizer 3.5.0 → 3.7.0

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.
Files changed (4) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +89 -37
  3. package/index.js +159 -51
  4. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.6.0] - 2026-06-11
9
+
10
+ ### Fixed
11
+ - Free-tier API key validation now works end-to-end. Free accounts (subscription_status NULL) can create one `sk-opt-*` key and use it with the MCP server for 7 LLM optimizations/month. Previously blocked by a bug where the free-tier launch patched an unused service module while the live enforcement layer retained the old 0-key/5-quota/none-MCP config.
12
+
13
+ ### Added
14
+ - `connect` wizard: `npx mcp-prompt-optimizer connect` interactively adds your API key to Claude Desktop config. Supports macOS, Windows, and Linux config paths. Creates the server entry if absent, updates the key if the entry exists.
15
+ - Upsell block in local fallback output: when no API key is configured, the rules-based result includes a one-command signup path (`npx mcp-prompt-optimizer connect`).
16
+
17
+ ## [3.5.0] - 2026-06-02
18
+
19
+ ### Added
20
+ - LLM upsell block added to local fallback output
21
+ - `connect` subcommand (interactive Claude Desktop config wizard)
22
+
23
+ ## [3.4.1] - 2026-05-28
24
+
25
+ ### Changed
26
+ - Tier names updated from Explorer/Creator/Innovator to Free/Pro/Enterprise (D6 pricing migration)
27
+
8
28
  ## [3.4.0] - 2026-05-26
9
29
 
10
30
  ### Added
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # MCP Prompt Optimizer v3.1.3
1
+ # MCP Prompt Optimizer v3.6.0
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/mcp-prompt-optimizer)](https://www.npmjs.com/package/mcp-prompt-optimizer)
4
4
  [![License](https://img.shields.io/badge/license-Commercial-blue.svg)](LICENSE)
5
5
  [![CI](https://github.com/prompt-optimizer/mcp-prompt-optimizer/actions/workflows/ci.yml/badge.svg)](https://github.com/prompt-optimizer/mcp-prompt-optimizer/actions)
6
6
  [![Snyk Health](https://snyk.io/advisor/npm-package/mcp-prompt-optimizer/badge.svg)](https://snyk.io/advisor/npm-package/mcp-prompt-optimizer)
7
7
 
8
- 🚀 **Professional cloud-based MCP server** for AI-powered prompt optimization with intelligent context detection, template management, team collaboration, and enterprise-grade reliability. Starting at $0/month.
8
+ 🚀 **Professional cloud-based MCP server** for AI-powered prompt optimization with intelligent context detection, template management, team collaboration, and enterprise-grade reliability. Starting at $0/month.
9
9
 
10
10
 
11
11
 
@@ -24,27 +24,34 @@
24
24
 
25
25
  ## 🚀 Quick Start
26
26
 
27
- **1. Get your API key (required):**
27
+ **1. Get your API key:**
28
28
 
29
- - **🆓 Free Tier** (`sk-local-*`): 5 daily optimizations — [promptoptimizer.xyz/pricing](https://promptoptimizer.xyz/pricing)
30
- - **⭐ Paid Tiers** (`sk-opt-*`, `sk-team-*`): Higher quotas, team features, advanced capabilities
29
+ - **🆓 Free Tier** (`sk-opt-*`): 7 LLM optimizations/month, 1 API key no credit card required
30
+ - **⭐ Pro** (`sk-opt-*`): 500 optimizations/month, full model config, Context Engineer
31
+ - **🏢 Enterprise** (`sk-team-*`): Unlimited optimizations, team keys, shared quotas
32
+
33
+ Sign up and generate your key at [promptoptimizer.xyz/dashboard](https://promptoptimizer.xyz/dashboard).
31
34
 
32
35
  **2. Install:**
33
36
  ```bash
34
37
  npm install -g mcp-prompt-optimizer
35
38
  ```
36
39
 
37
- **3. Configure your MCP client:**
40
+ **3. Connect to Claude Desktop (one command):**
41
+ ```bash
42
+ npx mcp-prompt-optimizer connect
43
+ ```
44
+ This wizard reads your API key and writes the MCP server entry to Claude Desktop config automatically. Cross-platform (macOS, Windows, Linux).
38
45
 
39
- Add to `~/.claude/claude_desktop_config.json` (Claude Desktop):
46
+ **Or configure manually** — add to `~/.claude/claude_desktop_config.json`:
40
47
  ```json
41
48
  {
42
49
  "mcpServers": {
43
- "prompt-optimizer": {
50
+ "mcp-prompt-optimizer": {
44
51
  "command": "npx",
45
- "args": ["mcp-prompt-optimizer"],
52
+ "args": ["-y", "mcp-prompt-optimizer"],
46
53
  "env": {
47
- "OPTIMIZER_API_KEY": "sk-local-your-key-here"
54
+ "OPTIMIZER_API_KEY": "sk-opt-your-key-here"
48
55
  }
49
56
  }
50
57
  }
@@ -246,7 +253,7 @@ Real-time optimization status and AG-UI capabilities. Requires the feature to be
246
253
 
247
254
  ## 🤖 Context Engineer (CE) Tools
248
255
 
249
- Requires a Creator or Innovator subscription. CE tools generate agentic scaffolding artifacts (SOPs, skill packages, framework code) directly in your IDE.
256
+ Requires a Pro or Enterprise subscription. CE tools generate agentic scaffolding artifacts (SOPs, skill packages, framework code) directly in your IDE.
250
257
 
251
258
  ### `generate_agent_sop`
252
259
  Generate a structured SOP document for an AI agent from a goal description. Returns markdown SOP ready for use.
@@ -269,6 +276,29 @@ Generate a complete skill package (SOP + SKILL.md + reference + examples + helpe
269
276
  ```
270
277
  `format` is one of `knowledge_doc` (default) or `agent_spec`.
271
278
 
279
+ ### `generate_harness_bundle`
280
+ Generate a deployment-ready Agentic Harness ZIP bundle for a specific platform. Returns a confirmation when the bundle is queued for download.
281
+ ```json
282
+ {
283
+ "goal": "The workflow goal the harness is built for",
284
+ "deploy_target": "claude_code",
285
+ "sop_content": "The SOP markdown content (required if no session_id)",
286
+ "session_id": "Optional: session ID from a prior generate_skill_package call"
287
+ }
288
+ ```
289
+ `deploy_target` accepts a single string (Pro+) or an array of strings (Enterprise — multi-platform simultaneously). Supported targets include `claude_code`, `langchain`, `autogen`, `crewai`, `amazon_q`, `aider`, `continue_dev`, and more. `amazon_q`, `aider`, `continue_dev`, `crewai` require Enterprise.
290
+
291
+ ### `explore_sop_approaches`
292
+ Generate 3 parallel SOP variants (process-oriented, decision-tree, role-based) for comparison before committing to one. Returns an HTML comparison grid, a `variants` array, and a recommended variant. Enterprise required.
293
+ ```json
294
+ {
295
+ "goal": "The workflow goal to generate SOP variants for",
296
+ "context": "Optional background context",
297
+ "blend_description": "Optional: blend all 3 variants into one SOP using this description"
298
+ }
299
+ ```
300
+ IntentFrame fields (`perspective`, `out_of_scope`, `success_definition`) are also accepted to scope the generation.
301
+
272
302
  ### `transform_for_framework`
273
303
  Transform a SOP into native code for your agent framework: LangChain tool, AutoGen agent, or Claude Code skill.
274
304
  ```json
@@ -290,7 +320,7 @@ Check your Context Engineer credit balance and what workflows are available at y
290
320
  Configure custom models in the WebUI and the MCP server uses them automatically.
291
321
 
292
322
  **Step 1 — Configure in WebUI:**
293
- 1. Visit [Dashboard](https://promptoptimizer-blog.vercel.app/dashboard)
323
+ 1. Visit [Dashboard](https://promptoptimizer.xyz/dashboard)
294
324
  2. Go to Settings → User Settings
295
325
  3. Add your OpenRouter API key (from [openrouter.ai](https://openrouter.ai))
296
326
  4. Select your preferred models for optimization and evaluation
@@ -313,35 +343,36 @@ Configure custom models in the WebUI and the MCP server uses them automatically.
313
343
  | Code / technical | `anthropic/claude-3-5-sonnet` | `anthropic/claude-3-haiku` |
314
344
 
315
345
  > **Two different API keys:**
316
- > - **Service key** (`sk-opt-*`) — your MCP Prompt Optimizer subscription
346
+ > - **Service key** (`sk-opt-*` or `sk-team-*`) — your MCP Prompt Optimizer subscription
317
347
  > - **OpenRouter key** — your personal OpenRouter account for model usage costs
318
348
 
319
349
  ---
320
350
 
321
351
  ## 💰 Subscription Plans
322
352
 
323
- | Plan | Price | Optimizations/month | CE Credits | Team members |
353
+ | Plan | Price | Optimizations/month | CE Credits | API Keys |
324
354
  |---|---|---|---|---|
325
- | 🎯 Explorer | $2.99/mo | 20 | 5 | 1 |
326
- | 🎨 Creator | $29/mo | 18,000 | 30 | 2 + 1 key |
327
- | 🚀 Innovator | $99/mo | 75,000 | Unlimited | 5 + 10 keys |
328
-
329
- 🆓 **Free trial:** 5 optimizations with full feature access.
355
+ | 🆓 Free | $0 | 7 LLM | | 1 |
356
+ | Pro | $19/mo | 500 | 5 | 1 |
357
+ | 🏢 Enterprise | Custom | Unlimited | 50 | 10 (shared) |
330
358
 
331
359
  All plans include AI context detection, template management, personal model configuration, and optimization insights.
332
360
 
361
+ [Get started free →](https://promptoptimizer.xyz/dashboard)
362
+
333
363
  ---
334
364
 
335
365
  ## 🔧 CLI Commands
336
366
 
337
367
  ```bash
338
- mcp-prompt-optimizer check-status # Check API key and quota status
339
- mcp-prompt-optimizer validate-key # Validate API key with backend
340
- mcp-prompt-optimizer test # Test backend integration
341
- mcp-prompt-optimizer diagnose # Run comprehensive diagnostic
342
- mcp-prompt-optimizer clear-cache # Clear validation cache
343
- mcp-prompt-optimizer help # Show help and setup instructions
344
- mcp-prompt-optimizer version # Show version information
368
+ npx mcp-prompt-optimizer connect # Interactive wizard: add API key to Claude Desktop config
369
+ mcp-prompt-optimizer check-status # Check API key and quota status
370
+ mcp-prompt-optimizer validate-key # Validate API key with backend
371
+ mcp-prompt-optimizer test # Test backend integration
372
+ mcp-prompt-optimizer diagnose # Run comprehensive diagnostic
373
+ mcp-prompt-optimizer clear-cache # Clear validation cache
374
+ mcp-prompt-optimizer help # Show help and setup instructions
375
+ mcp-prompt-optimizer version # Show version information
345
376
  ```
346
377
 
347
378
  ---
@@ -355,7 +386,7 @@ mcp-prompt-optimizer version # Show version information
355
386
  - Role-based access control
356
387
 
357
388
  ### Individual API Keys (`sk-opt-*`)
358
- - Personal quotas and billing
389
+ - Personal quotas and billing — available on Free and Pro tiers
359
390
  - Individual template libraries
360
391
  - Account self-management
361
392
 
@@ -377,9 +408,9 @@ mcp-prompt-optimizer version # Show version information
377
408
  ```json
378
409
  {
379
410
  "mcpServers": {
380
- "prompt-optimizer": {
411
+ "mcp-prompt-optimizer": {
381
412
  "command": "npx",
382
- "args": ["mcp-prompt-optimizer"],
413
+ "args": ["-y", "mcp-prompt-optimizer"],
383
414
  "env": { "OPTIMIZER_API_KEY": "sk-opt-your-key-here" }
384
415
  }
385
416
  }
@@ -391,9 +422,9 @@ Add to `~/.cursor/mcp.json`:
391
422
  ```json
392
423
  {
393
424
  "mcpServers": {
394
- "prompt-optimizer": {
425
+ "mcp-prompt-optimizer": {
395
426
  "command": "npx",
396
- "args": ["mcp-prompt-optimizer"],
427
+ "args": ["-y", "mcp-prompt-optimizer"],
397
428
  "env": { "OPTIMIZER_API_KEY": "sk-opt-your-key-here" }
398
429
  }
399
430
  }
@@ -407,6 +438,29 @@ Windsurf, Cline, VS Code, Zed, Replit, JetBrains IDEs, and Neovim are all suppor
407
438
 
408
439
  ## 📦 Changelog
409
440
 
441
+ ### v3.6.0
442
+ - **Free tier MCP access** — Free users can now create an API key (`sk-opt-*`) and use the MCP server for 7 LLM optimizations/month at no cost. Previously, key creation was blocked in the live service due to a bug introduced when the free-tier launch landed in an unused module. Keys with `subscription_status: NULL` (all free accounts) now validate correctly.
443
+ - **`connect` wizard** — `npx mcp-prompt-optimizer connect` interactively writes your API key to Claude Desktop config on macOS, Windows, and Linux. Replaces manual JSON editing for new users.
444
+ - **Upsell block** — Local rules fallback output now includes a concise upgrade prompt with a one-command onboarding path when no API key is configured.
445
+
446
+ ### v3.5.0
447
+ - LLM upsell block added to local fallback output
448
+ - `connect` subcommand added (interactive Claude Desktop config wizard)
449
+
450
+ ### v3.4.1
451
+ - Tier names migrated from Explorer/Creator/Innovator to Free/Pro/Enterprise (D6 pricing)
452
+
453
+ ### v3.4.0
454
+ - `explore_sop_approaches` tool: generates 3 parallel SOP variants (process-oriented, decision-tree, role-based) for comparison before committing. Optionally accepts `blend_description` to blend variants directly. Enterprise tier required.
455
+
456
+ ### v3.3.0
457
+ - `generate_harness_bundle` tool: generates deployment-ready ZIP harness for 14+ platforms. Single deploy target (Pro+) or multi-platform array (Enterprise).
458
+ - Intent frame fields (`perspective`, `out_of_scope`, `success_definition`) added to `generate_agent_sop` for scoped SOP generation.
459
+
460
+ ### v3.2.x
461
+ - `transform_for_framework` tool: converts SOP to native LangChain tool, AutoGen agent, or Claude Code skill
462
+ - CE harness HTML review layer with interactive DAG visualization
463
+
410
464
  ### v3.0.3
411
465
  - **Rules fallback output rewritten** — local optimization now produces user-facing prose prompts instead of raw XML scaffolding. The output is directly usable as a prompt without modification.
412
466
  - **All 18 local templates reworded** — template principles are now phrased as user request guidance rather than AI-assistant directives, producing more natural and actionable structured prompts.
@@ -429,9 +483,9 @@ Windsurf, Cline, VS Code, Zed, Replit, JetBrains IDEs, and Neovim are all suppor
429
483
 
430
484
  ## 🛠️ Support & Resources
431
485
 
432
- - 📖 **Documentation:** [promptoptimizer-blog.vercel.app/docs](https://promptoptimizer-blog.vercel.app/docs)
433
- - 📊 **Dashboard & model config:** [promptoptimizer-blog.vercel.app/dashboard](https://promptoptimizer-blog.vercel.app/dashboard)
434
- - 🚀 **Pricing & API Keys**: [promptoptimizer.xyz/local-license](https://promptoptimizer.xyz/local-license)
486
+ - 📖 **Documentation:** [promptoptimizer.xyz/docs](https://promptoptimizer.xyz/docs)
487
+ - 📊 **Dashboard & model config:** [promptoptimizer.xyz/dashboard](https://promptoptimizer.xyz/dashboard)
488
+ - 🚀 **Pricing & API Keys**: [promptoptimizer.xyz/pricing](https://promptoptimizer.xyz/pricing)
435
489
  - 🐛 **Issues:** [GitHub Issues](https://github.com/prompt-optimizer/mcp-prompt-optimizer/issues)
436
490
  - 📄 **License:** [Commercial License](LICENSE)
437
491
  - 🔒 **Security:** [Security Policy](SECURITY.md)
@@ -440,8 +494,6 @@ Windsurf, Cline, VS Code, Zed, Replit, JetBrains IDEs, and Neovim are all suppor
440
494
  - 📝 **Changelog:** [Release History](CHANGELOG.md)
441
495
  - 📧 **Email support:** support@promptoptimizer.xyz
442
496
 
443
-
444
497
  ---
445
498
 
446
- *Get started with 5 free optimizations at [promptoptimizer.xyz/pricing](https://promptoptimizer.xyz/pricing)*
447
- at [promptoptimizer.xyz/pricing](https://promptoptimizer.xyz/pricing)*
499
+ *Start free at [promptoptimizer.xyz](https://promptoptimizer.xyz) — 7 LLM optimizations/month, no credit card required.*
package/index.js CHANGED
@@ -1464,11 +1464,9 @@ class MCPPromptOptimizer {
1464
1464
  output += `**Template:** \`${result.template_used || 'general'}\`\n\n`;
1465
1465
  output += `**Optimized Prompt:**\n\`\`\`\n${result.optimized_prompt}\n\`\`\`\n\n`;
1466
1466
  } else if (result.fallback_mode) {
1467
- // Legacy path should no longer be reached
1468
- output = `# ⚠️ Backend UnavailablePrompt Not Optimized\n\n`;
1469
- output += `**Issue:** ${result.error_reason}\n`;
1470
- output += `The backend could not be reached. Your original prompt is returned below unmodified.\n\n`;
1471
- output += `**Original Prompt:**\n\`\`\`\n${result.optimized_prompt}\n\`\`\`\n\n`;
1467
+ output = `# 🔧 Optimized (local rules backend slow)\n\n`;
1468
+ output += `*Backend unavailable this timeapplied local rule templates. Try again for LLM optimization.*\n\n`;
1469
+ output += `**Optimized Prompt:**\n\`\`\`\n${result.optimized_prompt}\n\`\`\`\n\n`;
1472
1470
  } else {
1473
1471
  output = `# 🎯 Optimized Prompt\n\n${result.optimized_prompt}\n\n`;
1474
1472
  if (result.confidence_score < 0.25) {
@@ -1481,7 +1479,7 @@ class MCPPromptOptimizer {
1481
1479
  } else {
1482
1480
  output += `**Confidence:** ${(result.confidence_score * 100).toFixed(1)}%\n`;
1483
1481
  }
1484
- output += `**AI Context:** ${context.detectedContext}\n`;
1482
+ output += `**AI Context:** ${result.metadata?.context_detection?.ai_context || context.detectedContext}\n`;
1485
1483
 
1486
1484
  if (result.template_saved) {
1487
1485
  output += `\n📁 **Template Auto-Save**\n✅ Automatically saved as template (ID: \`${result.template_id}\`)\n*Confidence threshold: >70% required for auto-save*\n`;
@@ -1541,6 +1539,21 @@ class MCPPromptOptimizer {
1541
1539
  }
1542
1540
 
1543
1541
  if (!result.fallback_mode) {
1542
+ if (result.quota_used != null) {
1543
+ if (result.quota_limit == null) {
1544
+ // Unlimited plan — show status only, no upsell
1545
+ output += `\n📊 **Usage:** ${result.quota_used} optimizations — ✓ Unlimited plan\n`;
1546
+ } else {
1547
+ const remaining = result.quota_limit - result.quota_used;
1548
+ if (result.quota_used >= result.quota_limit) {
1549
+ output += `\n📊 **Usage:** ${result.quota_used}/${result.quota_limit} — quota reached. **[Upgrade for more →](https://promptoptimizer.xyz/pricing)**\n`;
1550
+ } else if (remaining <= 2) {
1551
+ output += `\n📊 **Usage:** ${result.quota_used}/${result.quota_limit} LLM optimizations (${remaining} left) — [Upgrade for more](https://promptoptimizer.xyz/pricing)\n`;
1552
+ } else {
1553
+ output += `\n📊 **Usage:** ${result.quota_used}/${result.quota_limit} LLM optimizations this month — [Upgrade for more](https://promptoptimizer.xyz/pricing)\n`;
1554
+ }
1555
+ }
1556
+ }
1544
1557
  output += `\n🔗 **Quick Actions**\n- Dashboard: https://promptoptimizer.xyz/dashboard\n- Analytics: https://promptoptimizer.xyz/analytics\n`;
1545
1558
  } else {
1546
1559
  const confPct = Math.round((result.confidence_score || 0) * 100);
@@ -1805,67 +1818,162 @@ async function runConnectWizard() {
1805
1818
  const path = require('path');
1806
1819
  const os = require('os');
1807
1820
 
1808
- const configPaths = {
1809
- win32: path.join(os.homedir(), 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json'),
1810
- darwin: path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'),
1811
- linux: path.join(os.homedir(), '.config', 'Claude', 'claude_desktop_config.json'),
1812
- };
1813
- const configPath = configPaths[process.platform] || configPaths.linux;
1821
+ // Known MCP client config locations keyed by [client, platform]
1822
+ const CLIENT_CONFIGS = [
1823
+ {
1824
+ name: 'Claude Desktop',
1825
+ paths: {
1826
+ win32: path.join(os.homedir(), 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json'),
1827
+ darwin: path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'),
1828
+ linux: path.join(os.homedir(), '.config', 'Claude', 'claude_desktop_config.json'),
1829
+ },
1830
+ serverKey: 'mcp-prompt-optimizer',
1831
+ },
1832
+ {
1833
+ name: 'Cursor',
1834
+ paths: {
1835
+ win32: path.join(os.homedir(), '.cursor', 'mcp.json'),
1836
+ darwin: path.join(os.homedir(), '.cursor', 'mcp.json'),
1837
+ linux: path.join(os.homedir(), '.cursor', 'mcp.json'),
1838
+ },
1839
+ serverKey: 'mcp-prompt-optimizer',
1840
+ },
1841
+ {
1842
+ name: 'VS Code Cline / Roo',
1843
+ paths: {
1844
+ win32: path.join(os.homedir(), 'AppData', 'Roaming', 'Code', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
1845
+ darwin: path.join(os.homedir(), 'Library', 'Application Support', 'Code', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
1846
+ linux: path.join(os.homedir(), '.config', 'Code', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
1847
+ },
1848
+ serverKey: 'mcp-prompt-optimizer',
1849
+ },
1850
+ {
1851
+ name: 'Continue.dev',
1852
+ paths: {
1853
+ win32: path.join(os.homedir(), '.continue', 'config.json'),
1854
+ darwin: path.join(os.homedir(), '.continue', 'config.json'),
1855
+ linux: path.join(os.homedir(), '.continue', 'config.json'),
1856
+ },
1857
+ serverKey: 'mcp-prompt-optimizer',
1858
+ },
1859
+ ];
1860
+
1861
+ function safeWriteConfig(filePath, newConfig) {
1862
+ const backupPath = filePath + '.bak';
1863
+ // Backup
1864
+ if (fs.existsSync(filePath)) {
1865
+ fs.copyFileSync(filePath, backupPath);
1866
+ }
1867
+ try {
1868
+ const serialized = JSON.stringify(newConfig, null, 2);
1869
+ fs.writeFileSync(filePath, serialized, 'utf8');
1870
+ // Verify round-trip
1871
+ JSON.parse(fs.readFileSync(filePath, 'utf8'));
1872
+ } catch (e) {
1873
+ // Restore backup on any failure
1874
+ if (fs.existsSync(backupPath)) {
1875
+ fs.copyFileSync(backupPath, filePath);
1876
+ }
1877
+ throw e;
1878
+ }
1879
+ }
1880
+
1881
+ function patchConfig(config, serverKey, apiKey) {
1882
+ if (!config.mcpServers) config.mcpServers = {};
1883
+ if (config.mcpServers[serverKey]) {
1884
+ if (!config.mcpServers[serverKey].env) config.mcpServers[serverKey].env = {};
1885
+ config.mcpServers[serverKey].env.OPTIMIZER_API_KEY = apiKey;
1886
+ } else {
1887
+ config.mcpServers[serverKey] = {
1888
+ command: 'npx',
1889
+ args: ['-y', 'mcp-prompt-optimizer'],
1890
+ env: { OPTIMIZER_API_KEY: apiKey },
1891
+ };
1892
+ }
1893
+ return config;
1894
+ }
1814
1895
 
1815
1896
  console.log('\n🔌 Prompt Optimizer — Connect Wizard\n');
1816
1897
 
1817
- if (!fs.existsSync(configPath)) {
1818
- console.log('❌ Claude Desktop config not found at:');
1819
- console.log(` ${configPath}`);
1820
- console.log('\nOpen Claude Desktop first to create the config file, then re-run this command.');
1898
+ // Detect which clients are installed
1899
+ const platform = process.platform;
1900
+ const found = CLIENT_CONFIGS
1901
+ .map(c => ({ ...c, configPath: c.paths[platform] || c.paths.linux }))
1902
+ .filter(c => fs.existsSync(c.configPath));
1903
+
1904
+ if (found.length === 0) {
1905
+ console.log('❌ No supported MCP client config found. Supported clients:');
1906
+ CLIENT_CONFIGS.forEach(c => {
1907
+ const p = c.paths[platform] || c.paths.linux;
1908
+ console.log(` ${c.name}: ${p}`);
1909
+ });
1910
+ console.log('\nOpen your MCP client first to create its config file, then re-run this command.');
1821
1911
  process.exit(1);
1822
1912
  }
1823
1913
 
1824
- let config;
1825
- try {
1826
- config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
1827
- } catch (e) {
1828
- console.log(`❌ Could not read config: ${e.message}`);
1829
- process.exit(1);
1914
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
1915
+
1916
+ function askApiKey(cb) {
1917
+ rl.question('Paste your API key (get one free at https://promptoptimizer.xyz/dashboard): ', (key) => {
1918
+ cb((key || '').trim());
1919
+ });
1830
1920
  }
1831
- if (!config.mcpServers) config.mcpServers = {};
1832
1921
 
1833
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
1834
- rl.question('Paste your API key (get one free at https://promptoptimizer.xyz/dashboard): ', (apiKey) => {
1922
+ function askClient(clients, cb) {
1923
+ console.log('Multiple MCP clients detected. Which one should be configured?');
1924
+ clients.forEach((c, i) => console.log(` ${i + 1}) ${c.name}`));
1925
+ rl.question('Enter number (or press Enter for all): ', (ans) => {
1926
+ const n = parseInt(ans, 10);
1927
+ if (!ans.trim()) {
1928
+ cb(clients);
1929
+ } else if (n >= 1 && n <= clients.length) {
1930
+ cb([clients[n - 1]]);
1931
+ } else {
1932
+ console.log('Invalid selection, configuring all.');
1933
+ cb(clients);
1934
+ }
1935
+ });
1936
+ }
1937
+
1938
+ function applyToClients(clients, apiKey) {
1835
1939
  rl.close();
1836
- apiKey = (apiKey || '').trim();
1940
+ let ok = 0;
1941
+ for (const client of clients) {
1942
+ let config;
1943
+ try {
1944
+ config = JSON.parse(fs.readFileSync(client.configPath, 'utf8'));
1945
+ } catch (e) {
1946
+ console.log(`❌ Could not read ${client.name} config: ${e.message}`);
1947
+ continue;
1948
+ }
1949
+ try {
1950
+ const patched = patchConfig(config, client.serverKey, apiKey);
1951
+ safeWriteConfig(client.configPath, patched);
1952
+ console.log(`✅ ${client.name} — configured (${client.configPath})`);
1953
+ ok++;
1954
+ } catch (e) {
1955
+ console.log(`❌ Could not write ${client.name} config: ${e.message}`);
1956
+ console.log(' Try running as administrator, or edit the file manually.');
1957
+ }
1958
+ }
1959
+ if (ok > 0) {
1960
+ console.log('\n👉 Restart your MCP client(s) to activate LLM optimization.');
1961
+ console.log(' Free plan: 7 LLM optimizations/month.');
1962
+ console.log(' Upgrade at https://promptoptimizer.xyz/pricing\n');
1963
+ }
1964
+ }
1837
1965
 
1966
+ askApiKey((apiKey) => {
1838
1967
  if (!apiKey.startsWith('sk-')) {
1968
+ rl.close();
1839
1969
  console.log('\n❌ Invalid key — must start with "sk-". Get one at https://promptoptimizer.xyz/dashboard');
1840
1970
  process.exit(1);
1841
1971
  }
1842
-
1843
- const serverName = 'mcp-prompt-optimizer';
1844
- if (config.mcpServers[serverName]) {
1845
- if (!config.mcpServers[serverName].env) config.mcpServers[serverName].env = {};
1846
- config.mcpServers[serverName].env.OPTIMIZER_API_KEY = apiKey;
1847
- console.log(`\n✅ Updated "${serverName}" entry with your API key.`);
1972
+ if (found.length === 1) {
1973
+ applyToClients(found, apiKey);
1848
1974
  } else {
1849
- config.mcpServers[serverName] = {
1850
- command: 'npx',
1851
- args: ['-y', 'mcp-prompt-optimizer'],
1852
- env: { OPTIMIZER_API_KEY: apiKey },
1853
- };
1854
- console.log(`\n✅ Added "${serverName}" to Claude Desktop config.`);
1975
+ askClient(found, (chosen) => applyToClients(chosen, apiKey));
1855
1976
  }
1856
-
1857
- try {
1858
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8');
1859
- } catch (e) {
1860
- console.log(`\n❌ Could not write config: ${e.message}`);
1861
- console.log('Try running as administrator, or edit the file manually.');
1862
- process.exit(1);
1863
- }
1864
-
1865
- console.log(` Config: ${configPath}`);
1866
- console.log('\n👉 Restart Claude Desktop to activate LLM optimization.');
1867
- console.log(' Free plan: 7 LLM optimizations/month.');
1868
- console.log(' Upgrade at https://promptoptimizer.xyz/pricing\n');
1869
1977
  });
1870
1978
  }
1871
1979
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-prompt-optimizer",
3
- "version": "3.5.0",
3
+ "version": "3.7.0",
4
4
  "description": "Professional cloud-based MCP server for AI-powered prompt optimization with intelligent context detection, Bayesian optimization, AG-UI real-time optimization, template auto-save, optimization insights, personal model configuration via WebUI, team collaboration, enterprise-grade features, production resilience, and startup validation. Universal compatibility with Claude Desktop, Cursor, Windsurf, and 17+ MCP clients.",
5
5
  "main": "index.js",
6
6
  "bin": {