mcp-prompt-optimizer 3.6.0 → 3.7.1
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/index.js +166 -52
- 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
|
-
|
|
1468
|
-
output
|
|
1469
|
-
output += `**
|
|
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 time — applied 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,8 +1479,14 @@ 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`;
|
|
1485
|
-
|
|
1482
|
+
output += `**AI Context:** ${result.metadata?.context_detection?.ai_context || result.metadata?.ai_context || context.detectedContext}\n`;
|
|
1483
|
+
if (result.metadata?.routing_score != null) {
|
|
1484
|
+
output += `**Routing Score:** ${result.metadata.routing_score.toFixed(3)} (${result.metadata?.routing_tier || 'unknown'})\n`;
|
|
1485
|
+
}
|
|
1486
|
+
if (!result.rules_based && !result.fallback_mode && result.metadata?.model_used) {
|
|
1487
|
+
output += `**Model:** ${result.metadata.model_used}\n`;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1486
1490
|
if (result.template_saved) {
|
|
1487
1491
|
output += `\n📁 **Template Auto-Save**\n✅ Automatically saved as template (ID: \`${result.template_id}\`)\n*Confidence threshold: >70% required for auto-save*\n`;
|
|
1488
1492
|
}
|
|
@@ -1541,6 +1545,21 @@ class MCPPromptOptimizer {
|
|
|
1541
1545
|
}
|
|
1542
1546
|
|
|
1543
1547
|
if (!result.fallback_mode) {
|
|
1548
|
+
if (result.quota_used != null) {
|
|
1549
|
+
if (result.quota_limit == null) {
|
|
1550
|
+
// Unlimited plan — show status only, no upsell
|
|
1551
|
+
output += `\n📊 **Usage:** ${result.quota_used} optimizations — ✓ Unlimited plan\n`;
|
|
1552
|
+
} else {
|
|
1553
|
+
const remaining = result.quota_limit - result.quota_used;
|
|
1554
|
+
if (result.quota_used >= result.quota_limit) {
|
|
1555
|
+
output += `\n📊 **Usage:** ${result.quota_used}/${result.quota_limit} — quota reached. **[Upgrade for more →](https://promptoptimizer.xyz/pricing)**\n`;
|
|
1556
|
+
} else if (remaining <= 2) {
|
|
1557
|
+
output += `\n📊 **Usage:** ${result.quota_used}/${result.quota_limit} LLM optimizations (${remaining} left) — [Upgrade for more](https://promptoptimizer.xyz/pricing)\n`;
|
|
1558
|
+
} else {
|
|
1559
|
+
output += `\n📊 **Usage:** ${result.quota_used}/${result.quota_limit} LLM optimizations this month — [Upgrade for more](https://promptoptimizer.xyz/pricing)\n`;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1544
1563
|
output += `\n🔗 **Quick Actions**\n- Dashboard: https://promptoptimizer.xyz/dashboard\n- Analytics: https://promptoptimizer.xyz/analytics\n`;
|
|
1545
1564
|
} else {
|
|
1546
1565
|
const confPct = Math.round((result.confidence_score || 0) * 100);
|
|
@@ -1805,67 +1824,162 @@ async function runConnectWizard() {
|
|
|
1805
1824
|
const path = require('path');
|
|
1806
1825
|
const os = require('os');
|
|
1807
1826
|
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1827
|
+
// Known MCP client config locations keyed by [client, platform]
|
|
1828
|
+
const CLIENT_CONFIGS = [
|
|
1829
|
+
{
|
|
1830
|
+
name: 'Claude Desktop',
|
|
1831
|
+
paths: {
|
|
1832
|
+
win32: path.join(os.homedir(), 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json'),
|
|
1833
|
+
darwin: path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'),
|
|
1834
|
+
linux: path.join(os.homedir(), '.config', 'Claude', 'claude_desktop_config.json'),
|
|
1835
|
+
},
|
|
1836
|
+
serverKey: 'mcp-prompt-optimizer',
|
|
1837
|
+
},
|
|
1838
|
+
{
|
|
1839
|
+
name: 'Cursor',
|
|
1840
|
+
paths: {
|
|
1841
|
+
win32: path.join(os.homedir(), '.cursor', 'mcp.json'),
|
|
1842
|
+
darwin: path.join(os.homedir(), '.cursor', 'mcp.json'),
|
|
1843
|
+
linux: path.join(os.homedir(), '.cursor', 'mcp.json'),
|
|
1844
|
+
},
|
|
1845
|
+
serverKey: 'mcp-prompt-optimizer',
|
|
1846
|
+
},
|
|
1847
|
+
{
|
|
1848
|
+
name: 'VS Code Cline / Roo',
|
|
1849
|
+
paths: {
|
|
1850
|
+
win32: path.join(os.homedir(), 'AppData', 'Roaming', 'Code', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
|
|
1851
|
+
darwin: path.join(os.homedir(), 'Library', 'Application Support', 'Code', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
|
|
1852
|
+
linux: path.join(os.homedir(), '.config', 'Code', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
|
|
1853
|
+
},
|
|
1854
|
+
serverKey: 'mcp-prompt-optimizer',
|
|
1855
|
+
},
|
|
1856
|
+
{
|
|
1857
|
+
name: 'Continue.dev',
|
|
1858
|
+
paths: {
|
|
1859
|
+
win32: path.join(os.homedir(), '.continue', 'config.json'),
|
|
1860
|
+
darwin: path.join(os.homedir(), '.continue', 'config.json'),
|
|
1861
|
+
linux: path.join(os.homedir(), '.continue', 'config.json'),
|
|
1862
|
+
},
|
|
1863
|
+
serverKey: 'mcp-prompt-optimizer',
|
|
1864
|
+
},
|
|
1865
|
+
];
|
|
1866
|
+
|
|
1867
|
+
function safeWriteConfig(filePath, newConfig) {
|
|
1868
|
+
const backupPath = filePath + '.bak';
|
|
1869
|
+
// Backup
|
|
1870
|
+
if (fs.existsSync(filePath)) {
|
|
1871
|
+
fs.copyFileSync(filePath, backupPath);
|
|
1872
|
+
}
|
|
1873
|
+
try {
|
|
1874
|
+
const serialized = JSON.stringify(newConfig, null, 2);
|
|
1875
|
+
fs.writeFileSync(filePath, serialized, 'utf8');
|
|
1876
|
+
// Verify round-trip
|
|
1877
|
+
JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
1878
|
+
} catch (e) {
|
|
1879
|
+
// Restore backup on any failure
|
|
1880
|
+
if (fs.existsSync(backupPath)) {
|
|
1881
|
+
fs.copyFileSync(backupPath, filePath);
|
|
1882
|
+
}
|
|
1883
|
+
throw e;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
function patchConfig(config, serverKey, apiKey) {
|
|
1888
|
+
if (!config.mcpServers) config.mcpServers = {};
|
|
1889
|
+
if (config.mcpServers[serverKey]) {
|
|
1890
|
+
if (!config.mcpServers[serverKey].env) config.mcpServers[serverKey].env = {};
|
|
1891
|
+
config.mcpServers[serverKey].env.OPTIMIZER_API_KEY = apiKey;
|
|
1892
|
+
} else {
|
|
1893
|
+
config.mcpServers[serverKey] = {
|
|
1894
|
+
command: 'npx',
|
|
1895
|
+
args: ['-y', 'mcp-prompt-optimizer'],
|
|
1896
|
+
env: { OPTIMIZER_API_KEY: apiKey },
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
return config;
|
|
1900
|
+
}
|
|
1814
1901
|
|
|
1815
1902
|
console.log('\n🔌 Prompt Optimizer — Connect Wizard\n');
|
|
1816
1903
|
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1904
|
+
// Detect which clients are installed
|
|
1905
|
+
const platform = process.platform;
|
|
1906
|
+
const found = CLIENT_CONFIGS
|
|
1907
|
+
.map(c => ({ ...c, configPath: c.paths[platform] || c.paths.linux }))
|
|
1908
|
+
.filter(c => fs.existsSync(c.configPath));
|
|
1909
|
+
|
|
1910
|
+
if (found.length === 0) {
|
|
1911
|
+
console.log('❌ No supported MCP client config found. Supported clients:');
|
|
1912
|
+
CLIENT_CONFIGS.forEach(c => {
|
|
1913
|
+
const p = c.paths[platform] || c.paths.linux;
|
|
1914
|
+
console.log(` ${c.name}: ${p}`);
|
|
1915
|
+
});
|
|
1916
|
+
console.log('\nOpen your MCP client first to create its config file, then re-run this command.');
|
|
1821
1917
|
process.exit(1);
|
|
1822
1918
|
}
|
|
1823
1919
|
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1920
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1921
|
+
|
|
1922
|
+
function askApiKey(cb) {
|
|
1923
|
+
rl.question('Paste your API key (get one free at https://promptoptimizer.xyz/dashboard): ', (key) => {
|
|
1924
|
+
cb((key || '').trim());
|
|
1925
|
+
});
|
|
1830
1926
|
}
|
|
1831
|
-
if (!config.mcpServers) config.mcpServers = {};
|
|
1832
1927
|
|
|
1833
|
-
|
|
1834
|
-
|
|
1928
|
+
function askClient(clients, cb) {
|
|
1929
|
+
console.log('Multiple MCP clients detected. Which one should be configured?');
|
|
1930
|
+
clients.forEach((c, i) => console.log(` ${i + 1}) ${c.name}`));
|
|
1931
|
+
rl.question('Enter number (or press Enter for all): ', (ans) => {
|
|
1932
|
+
const n = parseInt(ans, 10);
|
|
1933
|
+
if (!ans.trim()) {
|
|
1934
|
+
cb(clients);
|
|
1935
|
+
} else if (n >= 1 && n <= clients.length) {
|
|
1936
|
+
cb([clients[n - 1]]);
|
|
1937
|
+
} else {
|
|
1938
|
+
console.log('Invalid selection, configuring all.');
|
|
1939
|
+
cb(clients);
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
function applyToClients(clients, apiKey) {
|
|
1835
1945
|
rl.close();
|
|
1836
|
-
|
|
1946
|
+
let ok = 0;
|
|
1947
|
+
for (const client of clients) {
|
|
1948
|
+
let config;
|
|
1949
|
+
try {
|
|
1950
|
+
config = JSON.parse(fs.readFileSync(client.configPath, 'utf8'));
|
|
1951
|
+
} catch (e) {
|
|
1952
|
+
console.log(`❌ Could not read ${client.name} config: ${e.message}`);
|
|
1953
|
+
continue;
|
|
1954
|
+
}
|
|
1955
|
+
try {
|
|
1956
|
+
const patched = patchConfig(config, client.serverKey, apiKey);
|
|
1957
|
+
safeWriteConfig(client.configPath, patched);
|
|
1958
|
+
console.log(`✅ ${client.name} — configured (${client.configPath})`);
|
|
1959
|
+
ok++;
|
|
1960
|
+
} catch (e) {
|
|
1961
|
+
console.log(`❌ Could not write ${client.name} config: ${e.message}`);
|
|
1962
|
+
console.log(' Try running as administrator, or edit the file manually.');
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
if (ok > 0) {
|
|
1966
|
+
console.log('\n👉 Restart your MCP client(s) to activate LLM optimization.');
|
|
1967
|
+
console.log(' Free plan: 7 LLM optimizations/month.');
|
|
1968
|
+
console.log(' Upgrade at https://promptoptimizer.xyz/pricing\n');
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1837
1971
|
|
|
1972
|
+
askApiKey((apiKey) => {
|
|
1838
1973
|
if (!apiKey.startsWith('sk-')) {
|
|
1974
|
+
rl.close();
|
|
1839
1975
|
console.log('\n❌ Invalid key — must start with "sk-". Get one at https://promptoptimizer.xyz/dashboard');
|
|
1840
1976
|
process.exit(1);
|
|
1841
1977
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
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.`);
|
|
1978
|
+
if (found.length === 1) {
|
|
1979
|
+
applyToClients(found, apiKey);
|
|
1848
1980
|
} else {
|
|
1849
|
-
|
|
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.`);
|
|
1981
|
+
askClient(found, (chosen) => applyToClients(chosen, apiKey));
|
|
1855
1982
|
}
|
|
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
1983
|
});
|
|
1870
1984
|
}
|
|
1871
1985
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-prompt-optimizer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.1",
|
|
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": {
|