Skip to main content
Glama
install.jsβ€’5.88 kB
#!/usr/bin/env node /** * Memory MCP Server - Automatic Installation Script * Configures Claude Desktop to use the memory server */ import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import { homedir, platform } from 'os'; import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); /** * Get platform-specific database path */ function getDbPath() { const plat = platform(); switch (plat) { case 'darwin': // macOS return join(homedir(), '.claude-memories', 'memory.db'); case 'win32': // Windows return join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'claude-memories', 'memory.db'); default: // Linux and others const dataHome = process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'); return join(dataHome, 'claude-memories', 'memory.db'); } } /** * Get Claude Desktop config path based on platform */ function getClaudeConfigPath() { const plat = platform(); switch (plat) { case 'darwin': // macOS return join(homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'); case 'win32': // Windows return join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'Claude', 'claude_desktop_config.json'); default: // Linux and others const configHome = process.env.XDG_CONFIG_HOME || join(homedir(), '.config'); return join(configHome, 'Claude', 'claude_desktop_config.json'); } } /** * Get platform-specific MCP server configuration */ function getMcpServerConfig(dbPath) { // Get the absolute path to the installed package // __dirname is already the package root (e.g., .../node_modules/@whenmoon-afk/memory-mcp/) const serverPath = join(__dirname, 'dist', 'index.js'); // All platforms use node directly with the server path return { command: 'node', args: [serverPath], env: { MEMORY_DB_PATH: dbPath } }; } /** * Install the memory server configuration */ function install() { console.log('🧠 Memory MCP Server - Automatic Installation\n'); const configPath = getClaudeConfigPath(); const configDir = dirname(configPath); const dbPath = getDbPath(); const dbDir = dirname(dbPath); // Show paths to user console.log('πŸ“ Paths:'); console.log(` Config: ${configPath}`); console.log(` Database: ${dbPath}\n`); // Ensure database directory exists if (!existsSync(dbDir)) { console.log(`πŸ“ Creating database directory: ${dbDir}`); try { mkdirSync(dbDir, { recursive: true }); } catch (error) { console.error(`❌ Failed to create database directory: ${error.message}`); process.exit(1); } } // Ensure config directory exists if (!existsSync(configDir)) { console.log(`πŸ“ Creating config directory: ${configDir}`); try { mkdirSync(configDir, { recursive: true }); } catch (error) { console.error(`❌ Failed to create config directory: ${error.message}`); console.log('\n⚠️ Please create the directory manually and run this installer again.'); process.exit(1); } } // Read existing config or create new one let config = { mcpServers: {} }; let isNewConfig = true; if (existsSync(configPath)) { isNewConfig = false; console.log(`πŸ“– Reading existing config: ${configPath}`); try { const configContent = readFileSync(configPath, 'utf-8'); config = JSON.parse(configContent); // Ensure mcpServers object exists if (!config.mcpServers) { config.mcpServers = {}; } // Create backup const backupPath = `${configPath}.backup`; writeFileSync(backupPath, configContent, 'utf-8'); console.log(`πŸ’Ύ Backup created: ${backupPath}`); } catch (error) { console.error(`❌ Failed to read/parse config file: ${error.message}`); console.log('\n⚠️ Your config file may be corrupted. Please fix it manually or delete it to create a new one.'); process.exit(1); } } else { console.log(`πŸ“ Creating new config file: ${configPath}`); } // Add or update memory server configuration const serverConfig = getMcpServerConfig(dbPath); const serverExists = config.mcpServers.memory !== undefined; config.mcpServers.memory = serverConfig; // Write updated config try { writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8'); if (serverExists) { console.log('βœ… Memory server configuration updated!'); } else { console.log('βœ… Memory server configuration added!'); } } catch (error) { console.error(`❌ Failed to write config file: ${error.message}`); console.log('\n⚠️ Please check file permissions and try again.'); process.exit(1); } // Display next steps console.log('\nπŸ“‹ Next Steps:'); console.log('1. Restart Claude Desktop completely (quit and reopen)'); console.log('2. The memory server will be available automatically'); console.log('3. Try asking Claude to "store a memory" or "recall memories about..."'); console.log('\nπŸ“ Configuration Locations:'); console.log(` Claude config: ${configPath}`); console.log(` Memory database: ${dbPath}`); console.log('\n✨ Installation complete! Enjoy your persistent AI memory!\n'); } // Run installer try { install(); } catch (error) { console.error('❌ Installation failed:', error.message); console.error('\nπŸ“– For manual installation instructions, see:'); console.error(' https://github.com/WhenMoon-afk/claude-memory-mcp#readme'); process.exit(1); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/WhenMoon-afk/claude-memory-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server