UNPKG

stellar-mcp-cli

Version:

CLI tool that transforms any Soroban Smart Contract into an AI-ready Model Context Protocol (MCP) server

97 lines (86 loc) 3.29 kB
// install.js import { platform, homedir } from 'os'; import { chmodSync, copyFileSync, mkdirSync, existsSync, unlinkSync } from 'fs'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; // Get the directory where the script is located const __dirname = dirname(fileURLToPath(import.meta.url)); const os = platform(); const BIN_PATH = { darwin: 'soroban-mcp-macos', linux: 'soroban-mcp-linux', win32: 'soroban-mcp-win.exe', }[os]; if (!BIN_PATH) { console.error(`Unsupported OS: ${os}. This package currently supports macOS, Linux, and Windows.`); process.exit(1); } // Ensure bin directory exists const binDir = join(__dirname, 'bin'); try { if (!existsSync(binDir)) { console.log('Creating bin directory...'); mkdirSync(binDir, { recursive: true }); } } catch (error) { console.error('Failed to create bin directory:', error.message); process.exit(1); } const source = join(binDir, BIN_PATH); const target = join(binDir, 'soroban'); // Ensure source binary exists if (!existsSync(source)) { console.error('Error: Binary not found!'); console.error(`Expected binary at: ${source}`); console.error(`This could be because:`); console.error(`1. You're using an unsupported platform (current: ${os})`); console.error(`2. The package was not installed correctly`); console.error(`\nPlease try:`); console.error(`1. Uninstalling and reinstalling the package: npm uninstall -g stellar-mcp-cli && npm install -g stellar-mcp-cli`); console.error(`2. If the error persists, please report this issue at: https://github.com/JoseCToscano/stellar-cli/issues`); process.exit(1); } // Create .soroban directory structure (commonly used by Soroban tools) const sorobanDir = join(homedir(), '.soroban'); const cacheDir = join(sorobanDir, 'cache'); const configDir = join(sorobanDir, 'config'); // Create directories with error handling [sorobanDir, cacheDir, configDir].forEach(dir => { try { if (!existsSync(dir)) { console.log(`Creating directory: ${dir}`); mkdirSync(dir, { recursive: true }); } } catch (error) { console.error(`Failed to create directory ${dir}:`, error.message); process.exit(1); } }); // Clean up old binary if it exists try { if (existsSync(target)) { console.log('Removing old binary...'); unlinkSync(target); } } catch (error) { console.error('Failed to remove old binary:', error.message); // Don't exit on cleanup failure, try to continue console.log('Continuing with installation...'); } // Copy and set permissions with error handling try { copyFileSync(source, target); // Set executable permissions if (os !== 'win32') { chmodSync(target, 0o755); chmodSync(source, 0o755); // Also ensure source binary is executable } console.log(`✔ Successfully installed binary: ${BIN_PATH}`); console.log('You can now use the "stellar-mcp-cli" command.'); } catch (error) { console.error('Failed to install binary:', error.message); console.error('\nThis could be due to permission issues. Try:'); console.error('1. Running with sudo: sudo npm install -g stellar-mcp-cli'); console.error('2. Fixing npm permissions: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally'); process.exit(1); }