mcp-prompt-optimizer 3.6.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 (2) hide show
  1. package/index.js +159 -51
  2. package/package.json +1 -1
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.6.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": {