()
| 35 | |
| 36 | // 创建或更新 MCP 配置 |
| 37 | function updateMcpConfig() { |
| 38 | try { |
| 39 | const configDir = getCursorConfigPath(); |
| 40 | const configFile = path.join(configDir, 'mcp_settings.json'); |
| 41 | |
| 42 | // 确保配置目录存在 |
| 43 | if (!fs.existsSync(configDir)) { |
| 44 | fs.mkdirSync(configDir, { recursive: true }); |
| 45 | console.log(`✅ Created Cursor config directory: ${configDir}`); |
| 46 | } |
| 47 | |
| 48 | // 读取现有配置或创建新配置 |
| 49 | let config = { mcpServers: {} }; |
| 50 | if (fs.existsSync(configFile)) { |
| 51 | try { |
| 52 | const existingConfig = fs.readFileSync(configFile, 'utf8'); |
| 53 | config = JSON.parse(existingConfig); |
| 54 | console.log('📝 Found existing MCP configuration'); |
| 55 | } catch (err) { |
| 56 | console.warn('⚠️ Existing config file is invalid, creating new one'); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // 确保 mcpServers 对象存在 |
| 61 | if (!config.mcpServers) { |
| 62 | config.mcpServers = {}; |
| 63 | } |
| 64 | |
| 65 | // 添加或更新 iCSS MCP Server 配置 |
| 66 | const packagePath = getPackagePath(); |
| 67 | const serverPath = path.join(packagePath, 'server.js'); |
| 68 | |
| 69 | config.mcpServers.icss = { |
| 70 | command: "node", |
| 71 | args: [serverPath], |
| 72 | env: {} |
| 73 | }; |
| 74 | |
| 75 | // 写入配置文件 |
| 76 | fs.writeFileSync(configFile, JSON.stringify(config, null, 2)); |
| 77 | console.log(`✅ Updated MCP configuration: ${configFile}`); |
| 78 | |
| 79 | return configFile; |
| 80 | |
| 81 | } catch (error) { |
| 82 | console.error('❌ Failed to update MCP configuration:', error.message); |
| 83 | throw error; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // 验证安装 |
| 88 | function verifyInstallation() { |
no test coverage detected