#!/usr/bin/env tsx import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; /** * Script to migrate MCP server configuration from wrong location to correct location */ async function migrateMCPConfig(): Promise { const wrongPath = path.join(os.homedir(), 'mcp-servers.json'); const correctDir = path.join(os.homedir(), '.config', 'hashgraph-online'); const correctPath = path.join(correctDir, 'mcp-servers.json'); console.log('šŸ” Checking for MCP config file...'); console.log(`Wrong location: ${wrongPath}`); console.log(`Correct location: ${correctPath}`); if (!fs.existsSync(wrongPath)) { console.log('āœ… No config file found at wrong location'); return; } console.log('šŸ“ Found config file at wrong location, migrating...'); try { const configData = fs.readFileSync(wrongPath, 'utf8'); let parsed; try { parsed = JSON.parse(configData); console.log(`āœ… JSON is valid, contains ${parsed.length} server configurations`); } catch (parseError) { console.error('āŒ JSON is corrupted:', parseError); console.log('šŸ”§ Attempting to fix JSON...'); let fixedData = configData.trim(); if (!fixedData.endsWith('}]')) { console.log('Adding missing closing brackets...'); fixedData += '}]'; } try { parsed = JSON.parse(fixedData); console.log('āœ… JSON fixed successfully'); } catch (fixError) { console.error('āŒ Could not fix JSON:', fixError); return; } } if (!fs.existsSync(correctDir)) { console.log('šŸ“ Creating config directory...'); fs.mkdirSync(correctDir, { recursive: true }); } const formattedData = JSON.stringify(parsed, null, 2) + '\n'; fs.writeFileSync(correctPath, formattedData, 'utf8'); console.log('āœ… Config file migrated to correct location'); try { const verifyData = fs.readFileSync(correctPath, 'utf8'); const verifyParsed = JSON.parse(verifyData.trim()); console.log(`āœ… Migration verified, ${verifyParsed.length} configurations in new location`); } catch (verifyError) { console.error('āŒ Migration verification failed:', verifyError); return; } console.log('\nšŸ—‘ļø Migration successful!'); console.log(`Old file still exists at: ${wrongPath}`); console.log(`New file created at: ${correctPath}`); console.log('\nYou can safely delete the old file if everything is working correctly.'); console.log(`To delete: rm "${wrongPath}"`); } catch (error) { console.error('āŒ Migration failed:', error); } } migrateMCPConfig().catch(console.error); export { migrateMCPConfig };