@danainnovations/cortex-mcp 1.0.75 → 1.0.77

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/dist/cli.js CHANGED
@@ -1543,31 +1543,53 @@ function configureClaudeDesktop(_serverUrl, apiKey, _mcps) {
1543
1543
  if (!existsSync(dir)) {
1544
1544
  mkdirSync(dir, { recursive: true });
1545
1545
  }
1546
- let config = {};
1547
- if (existsSync(configPath)) {
1548
- try {
1549
- config = JSON.parse(readFileSync(configPath, "utf-8"));
1550
- } catch {
1551
- }
1552
- }
1553
- if (!config.mcpServers || typeof config.mcpServers !== "object") {
1554
- config.mcpServers = {};
1555
- }
1556
- const servers = config.mcpServers;
1557
- for (const key of Object.keys(servers)) {
1558
- if (key.startsWith("cortex-") || key === "cortex") {
1559
- delete servers[key];
1560
- }
1561
- }
1562
1546
  const isWindows = getPlatform() === "windows";
1563
- servers["cortex"] = isWindows ? {
1547
+ const cortexEntry = isWindows ? {
1564
1548
  command: "cmd",
1565
1549
  args: ["/c", "npx", "-y", "@danainnovations/cortex-mcp@latest", "serve"]
1566
1550
  } : {
1567
1551
  command: "npx",
1568
1552
  args: ["-y", "@danainnovations/cortex-mcp@latest", "serve"]
1569
1553
  };
1570
- writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
1554
+ const maxAttempts = isWindows ? 3 : 1;
1555
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
1556
+ let config = {};
1557
+ if (existsSync(configPath)) {
1558
+ try {
1559
+ config = JSON.parse(readFileSync(configPath, "utf-8"));
1560
+ } catch {
1561
+ }
1562
+ }
1563
+ if (!config.mcpServers || typeof config.mcpServers !== "object") {
1564
+ config.mcpServers = {};
1565
+ }
1566
+ const servers = config.mcpServers;
1567
+ for (const key of Object.keys(servers)) {
1568
+ if (key.startsWith("cortex-") || key === "cortex") {
1569
+ delete servers[key];
1570
+ }
1571
+ }
1572
+ servers["cortex"] = cortexEntry;
1573
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
1574
+ if (isWindows) {
1575
+ const start = Date.now();
1576
+ while (Date.now() - start < 500) {
1577
+ }
1578
+ try {
1579
+ const verify = JSON.parse(readFileSync(configPath, "utf-8"));
1580
+ const verifyServers = verify.mcpServers;
1581
+ if (verifyServers && "cortex" in verifyServers) {
1582
+ return;
1583
+ }
1584
+ } catch {
1585
+ }
1586
+ continue;
1587
+ }
1588
+ return;
1589
+ }
1590
+ throw new Error(
1591
+ "Claude Desktop is overwriting the config file. Please close Claude Desktop completely (quit from the system tray), then re-run setup."
1592
+ );
1571
1593
  }
1572
1594
  function configureClaudeCode(serverUrl, apiKey, mcps) {
1573
1595
  for (const mcp of AVAILABLE_MCPS) {