UNPKG

local-memory-mcp

Version:

Local Memory MCP Server - AI-powered persistent memory system for Claude Desktop and other MCP-compatible tools

120 lines (105 loc) 3.37 kB
#!/usr/bin/env node /** * @local-memory/server * * Local Memory MCP Server - AI-powered persistent memory system * * This is the main entry point for the @local-memory/server npm package. * It provides a unified interface to the Local Memory binary across platforms. * * @author Local Memory <contact@localmemory.co> * @license SEE LICENSE IN https://localmemory.co/terms */ const { spawn } = require('child_process'); const path = require('path'); const fs = require('fs'); const os = require('os'); /** * Get the platform-specific binary name */ function getBinaryName() { const platform = os.platform(); const arch = os.arch(); switch (platform) { case 'darwin': return arch === 'arm64' ? 'local-memory-macos-arm' : 'local-memory-macos-intel'; case 'linux': return 'local-memory-linux'; case 'win32': return 'local-memory-windows.exe'; default: throw new Error(`Unsupported platform: ${platform}-${arch}`); } } /** * Get the path to the local-memory binary */ function getBinaryPath() { const binaryName = getBinaryName(); const binaryPath = path.join(__dirname, 'bin', binaryName); if (!fs.existsSync(binaryPath)) { console.error(`Error: Local Memory binary not found at ${binaryPath}`); console.error(''); console.error('This may indicate an installation issue. Please try:'); console.error('1. Reinstall the package: npm uninstall @local-memory/server && npm install @local-memory/server'); console.error('2. Check your platform support at: https://localmemory.co/docs/installation'); console.error('3. If issues persist, contact support: https://localmemory.co/support'); process.exit(1); } return binaryPath; } /** * Main execution function */ function main() { try { const binaryPath = getBinaryPath(); const args = process.argv.slice(2); // Execute the local-memory binary with all arguments const child = spawn(binaryPath, args, { stdio: 'inherit', cwd: process.cwd() }); // Handle process termination child.on('exit', (code, signal) => { if (signal) { process.exit(128 + os.constants.signals[signal]); } else { process.exit(code || 0); } }); // Handle errors child.on('error', (error) => { if (error.code === 'ENOENT') { console.error('Error: Local Memory binary not found or not executable.'); console.error(''); console.error('Please ensure the binary has proper permissions:'); console.error(`chmod +x "${binaryPath}"`); console.error(''); console.error('If you\'re on macOS, you may need to allow the binary in System Preferences > Security & Privacy'); console.error('Or run: xattr -rd com.apple.quarantine "${binaryPath}"'); } else { console.error(`Error executing Local Memory: ${error.message}`); } process.exit(1); }); // Handle termination signals ['SIGINT', 'SIGTERM'].forEach(signal => { process.on(signal, () => { child.kill(signal); }); }); } catch (error) { console.error(`Error: ${error.message}`); process.exit(1); } } // Only run main if this file is executed directly if (require.main === module) { main(); } module.exports = { getBinaryPath, getBinaryName, main };