mcp-booster
Version:
Servidor MCP com CoConuT (Continuous Chain of Thought) para uso com Cursor IDE - Pacote Global NPM
259 lines (258 loc) • 10.8 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeInitCommand = executeInitCommand;
exports.runInitCommand = runInitCommand;
exports.validateSystemRequirements = validateSystemRequirements;
const path = __importStar(require("path"));
const cli_parser_1 = require("./cli-parser");
const os_detector_1 = require("./os-detector");
const mcp_config_1 = require("./mcp-config");
const cursor_rules_1 = require("./cursor-rules");
/**
* Shows support information when errors occur
*/
function showSupportInfo() {
console.log('');
console.log('🆘 Precisa de ajuda?');
console.log(' Nossa equipe de suporte está pronta para ajudar!');
console.log(' 📧 Entre em contato: https://llmbooster.com/suporte');
console.log(' ⏰ Horário de atendimento: Segunda a Sexta, 9h às 18h');
console.log('');
}
/**
* Determines which systemPrompt file to use based on the operating system
* Now always returns the base systemPrompt.md - Windows content will be added dynamically
*/
function getSystemPromptPath() {
const fs = require('fs');
const defaultPromptPath = path.join(__dirname, '../../../systemPrompt.md');
if (process.env.DEBUG) {
console.log(`🔍 [DEBUG] Using base system prompt: ${path.basename(defaultPromptPath)}`);
}
return defaultPromptPath;
}
/**
* Gets the path to Windows auxiliary content file
*/
function getWindowsAuxPromptPath() {
return path.join(__dirname, '../../../systemPrompt-AuxWindows.md');
}
/**
* Shows system information for debugging
*/
function showSystemInfo() {
const systemInfo = (0, os_detector_1.getCursorSystemInfo)();
const currentOS = (0, os_detector_1.detectOS)();
const systemPromptPath = getSystemPromptPath();
console.log('\n🔍 System Information:');
console.log(` Platform: ${systemInfo.platform}`);
console.log(` Detected OS: ${currentOS}`);
console.log(` Architecture: ${systemInfo.arch}`);
console.log(` Node.js: ${systemInfo.nodeVersion}`);
console.log(` Cursor Installed: ${systemInfo.cursorInstalled ? '✅ Yes' : '❌ No'}`);
console.log(` Global MCP Path: ${systemInfo.paths.globalPath}`);
console.log(` Local Cursor Rules Path: ${systemInfo.paths.localPath}`);
console.log(` System Prompt: ${path.basename(systemPromptPath)}`);
}
/**
* Main init command function
*/
async function executeInitCommand(argv) {
console.log('🚀 MCP-Booster - Installation\n');
try {
// Parse arguments
const parseResult = (0, cli_parser_1.parseCliArguments)(argv);
// Check if help should be shown
if (parseResult.showHelp) {
console.log((0, cli_parser_1.getHelpMessage)());
return {
success: true,
message: 'Help displayed successfully'
};
}
// Check for parsing errors
if (!parseResult.success || !parseResult.args) {
console.error(`❌ ${parseResult.error}`);
if (parseResult.showHelp) {
console.log((0, cli_parser_1.getHelpMessage)());
}
else {
showSupportInfo();
}
return {
success: false,
message: parseResult.error || 'Error parsing arguments',
error: parseResult.error
};
}
const { ide, apiKey } = parseResult.args;
const sanitizedApiKey = (0, cli_parser_1.sanitizeApiKey)(apiKey);
// System detection
const systemInfo = (0, os_detector_1.getCursorSystemInfo)();
// Show system information if needed
if (process.env.DEBUG) {
showSystemInfo();
}
// Cursor verification (silent)
if (!systemInfo.cursorInstalled && process.env.DEBUG) {
console.warn('⚠️ Cursor not detected, but continuing...');
}
// Always use global configuration for MCP
const mcpConfigPath = systemInfo.paths.globalPath;
try {
// Ensure global directory exists
(0, os_detector_1.ensureCursorDirectories)(true);
// MCP configuration installation
const installResult = (0, mcp_config_1.installMcpBoosterConfig)(mcpConfigPath, sanitizedApiKey);
// Local Cursor Rules creation
// Use base systemPrompt and add Windows content if needed
const systemPromptPath = getSystemPromptPath();
const windowsAuxPromptPath = getWindowsAuxPromptPath();
const cursorRulesConfig = {
projectPath: process.cwd(),
systemPromptPath: systemPromptPath,
windowsAuxPromptPath: windowsAuxPromptPath
};
const cursorRulesResult = await (0, cursor_rules_1.createCursorRules)(cursorRulesConfig);
if (installResult.success) {
// Simplified success output
console.log('✅ Installation completed!\n');
console.log('📦 What was installed:');
console.log(' • MCP-Booster Server (global)');
if (cursorRulesResult.success) {
const currentOS = (0, os_detector_1.detectOS)();
const promptFileName = path.basename(systemPromptPath);
console.log(' • Cursor Rules (current project)');
console.log(` ↳ OS: ${currentOS} → Using: ${promptFileName}`);
// Mostrar detalhes do arquivo criado se disponível
if (cursorRulesResult.details && cursorRulesResult.details.fileSize) {
console.log(` ↳ File: ${cursorRulesResult.filePath}`);
console.log(` ↳ Size: ${cursorRulesResult.details.fileSize} bytes`);
console.log(` ↳ Permissions: ${cursorRulesResult.details.permissions || 'Unknown'}`);
}
}
else {
console.log(' • Cursor Rules (failed - see details below)');
console.log('');
console.error('❌ Cursor Rules Creation Failed:');
console.error(` Error: ${cursorRulesResult.error || 'Unknown error'}`);
console.error(` Message: ${cursorRulesResult.message}`);
if (cursorRulesResult.filePath) {
console.error(` Target Path: ${cursorRulesResult.filePath}`);
}
console.log('');
showSupportInfo();
}
console.log('\n🔄 Next step:');
console.log(' Use Cursor IDE in Agent mode');
return {
success: true,
message: 'Installation completed successfully',
details: {
platform: systemInfo.platform,
mcpConfigPath: installResult.configPath || mcpConfigPath,
cursorInstalled: systemInfo.cursorInstalled,
cursorRulesPath: cursorRulesResult.filePath
}
};
}
else {
console.error(`❌ Installation failed: ${installResult.message}`);
showSupportInfo();
return {
success: false,
message: installResult.message,
error: installResult.error
};
}
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.error(`❌ Error during installation: ${errorMessage}`);
showSupportInfo();
return {
success: false,
message: 'Error during installation',
error: errorMessage
};
}
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.error(`❌ Unexpected error: ${errorMessage}`);
showSupportInfo();
return {
success: false,
message: 'Unexpected error during execution',
error: errorMessage
};
}
}
/**
* Convenience function to execute init command with error handling
*/
async function runInitCommand(argv) {
try {
const result = await executeInitCommand(argv);
if (!result.success) {
process.exit(1);
}
}
catch (error) {
console.error('❌ Fatal error:', error instanceof Error ? error.message : String(error));
showSupportInfo();
process.exit(1);
}
}
/**
* Validates if system requirements are met
*/
function validateSystemRequirements() {
const issues = [];
// Check Node.js
const nodeVersion = process.version;
const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]);
if (majorVersion < 16) {
issues.push(`Node.js version ${nodeVersion} is too old. Requires Node.js 16 or higher.`);
}
// Check if in a project directory
const hasPackageJson = require('fs').existsSync(path.join(process.cwd(), 'package.json'));
// Note: systemPrompt.md is now bundled with the package, not required in user's directory
return {
valid: issues.length === 0,
issues
};
}