# MCP Memory System - One-Click Local Installation
# Fully self-hosted memory system for AI assistants
param(
[switch]$Force = $false,
[switch]$Verbose = $false
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
Write-Host "๐ง MCP Memory System - Local Installation" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
# Check if Docker is installed and running
function Test-Docker {
Write-Host "๐ณ Checking Docker..." -NoNewline
try {
$null = docker --version 2>$null
$null = docker info 2>$null
Write-Host " โ
" -ForegroundColor Green
return $true
}
catch {
Write-Host " โ" -ForegroundColor Red
Write-Host "Docker is not installed or not running. Please install Docker Desktop and start it." -ForegroundColor Red
Write-Host "Download: https://www.docker.com/products/docker-desktop" -ForegroundColor Yellow
return $false
}
}
# Create environment file
function New-EnvironmentFile {
Write-Host "โ๏ธ Creating environment configuration..." -NoNewline
$envContent = @"
# MCP Memory System Configuration
LLM_PROVIDER=basic
OLLAMA_HOST=http://localhost:11434
OLLAMA_MODEL=phi3:mini
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_COLLECTION_NAME=memories
HOST=0.0.0.0
PORT=3000
"@
$envContent | Out-File -FilePath ".env" -Encoding UTF8
Write-Host " โ
" -ForegroundColor Green
}
# Build MCP server image
function Build-MCPImage {
Write-Host "๐๏ธ Building MCP server image..." -NoNewline
try {
docker build -f Dockerfile.simple -t mem0mcp-simple:latest . *>$null
Write-Host " โ
" -ForegroundColor Green
}
catch {
Write-Host " โ" -ForegroundColor Red
throw "Failed to build MCP server image"
}
}
# Start infrastructure services
function Start-Infrastructure {
Write-Host "๐ Starting infrastructure services..." -NoNewline
try {
docker-compose -f docker-compose.local.yml up -d postgres ollama *>$null
Write-Host " โ
" -ForegroundColor Green
}
catch {
Write-Host " โ" -ForegroundColor Red
throw "Failed to start infrastructure services"
}
}
# Wait for services to be healthy
function Wait-ForServices {
Write-Host "โณ Waiting for services to start..."
# Wait for PostgreSQL
Write-Host " ๐ PostgreSQL..." -NoNewline
$maxAttempts = 30
$attempt = 0
do {
$attempt++
Start-Sleep -Seconds 2
$pgStatus = docker inspect --format='{{.State.Health.Status}}' mem0-postgres 2>$null
} while ($pgStatus -ne "healthy" -and $attempt -lt $maxAttempts)
if ($pgStatus -eq "healthy") {
Write-Host " โ
" -ForegroundColor Green
} else {
Write-Host " โ" -ForegroundColor Red
throw "PostgreSQL failed to start"
}
# Wait for Ollama
Write-Host " ๐ค Ollama..." -NoNewline
$attempt = 0
do {
$attempt++
Start-Sleep -Seconds 2
$ollamaStatus = docker inspect --format='{{.State.Health.Status}}' mem0-ollama 2>$null
} while ($ollamaStatus -ne "healthy" -and $attempt -lt $maxAttempts)
if ($ollamaStatus -eq "healthy") {
Write-Host " โ
" -ForegroundColor Green
} else {
Write-Host " โ" -ForegroundColor Red
throw "Ollama failed to start"
}
}
# Download AI models
function Install-Models {
Write-Host "๐ฆ Downloading AI models (this may take 5-10 minutes)..."
# Download phi3:mini
Write-Host " ๐ง phi3:mini (2.2GB)..." -NoNewline
try {
docker exec mem0-ollama ollama pull phi3:mini *>$null
Write-Host " โ
" -ForegroundColor Green
}
catch {
Write-Host " โ" -ForegroundColor Red
throw "Failed to download phi3:mini model"
}
# Download nomic-embed-text
Write-Host " ๐ค nomic-embed-text (274MB)..." -NoNewline
try {
docker exec mem0-ollama ollama pull nomic-embed-text *>$null
Write-Host " โ
" -ForegroundColor Green
}
catch {
Write-Host " โ" -ForegroundColor Red
throw "Failed to download nomic-embed-text model"
}
}
# Update Claude Desktop configuration
function Update-ClaudeConfig {
Write-Host "๐ง Updating Claude Desktop configuration..." -NoNewline
$claudeConfigPath = "$env:USERPROFILE\.claude.json"
if (Test-Path $claudeConfigPath) {
try {
$config = Get-Content $claudeConfigPath -Raw | ConvertFrom-Json
# Ensure projects structure exists
if (-not $config.projects) {
$config | Add-Member -Type NoteProperty -Name "projects" -Value @{}
}
$projectPath = (Get-Location).Path
# Initialize project if it doesn't exist
if (-not $config.projects.$projectPath) {
$config.projects | Add-Member -Type NoteProperty -Name $projectPath -Value @{
allowedTools = @()
mcpServers = @{}
}
}
# Add mem0-local MCP server configuration
$config.projects.$projectPath.mcpServers | Add-Member -Type NoteProperty -Name "mem0-local" -Value @{
command = "docker"
args = @(
"run", "-i", "--rm", "--network", "host",
"-e", "POSTGRES_HOST=localhost",
"-e", "POSTGRES_PORT=5432",
"-e", "POSTGRES_DB=postgres",
"-e", "POSTGRES_USER=postgres",
"-e", "POSTGRES_PASSWORD=postgres",
"-e", "POSTGRES_COLLECTION_NAME=memories",
"-e", "LLM_PROVIDER=basic",
"-e", "OLLAMA_HOST=http://localhost:11434",
"-e", "OLLAMA_MODEL=phi3:mini",
"mem0mcp-simple:latest"
)
} -Force
# Save updated configuration
$config | ConvertTo-Json -Depth 10 | Out-File -FilePath $claudeConfigPath -Encoding UTF8
Write-Host " โ
" -ForegroundColor Green
}
catch {
Write-Host " โ" -ForegroundColor Red
Write-Host "Failed to update Claude configuration: $($_.Exception.Message)" -ForegroundColor Red
return $false
}
}
else {
Write-Host " โ ๏ธ" -ForegroundColor Yellow
Write-Host "Claude configuration file not found at $claudeConfigPath" -ForegroundColor Yellow
return $false
}
return $true
}
# Test the installation
function Test-Installation {
Write-Host "๐งช Testing installation..." -NoNewline
try {
# Test MCP server
$testResult = echo '{"jsonrpc": "2.0", "method": "initialize", "id": 1, "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0"}}}' | docker run -i --rm --network host -e POSTGRES_HOST=localhost -e POSTGRES_PORT=5432 -e POSTGRES_DB=postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e LLM_PROVIDER=basic -e OLLAMA_HOST=http://localhost:11434 mem0mcp-simple:latest 2>$null
if ($testResult -match '"serverInfo"') {
Write-Host " โ
" -ForegroundColor Green
return $true
} else {
Write-Host " โ" -ForegroundColor Red
return $false
}
}
catch {
Write-Host " โ" -ForegroundColor Red
return $false
}
}
# Cleanup function
function Stop-Services {
if ($Force) {
Write-Host "๐งน Stopping existing services..." -NoNewline
try {
docker-compose -f docker-compose.local.yml down -v *>$null
Write-Host " โ
" -ForegroundColor Green
}
catch {
# Ignore errors during cleanup
}
}
}
# Main installation function
function Start-Installation {
try {
Write-Host ""
# Cleanup if forced
if ($Force) {
Stop-Services
}
# Check prerequisites
if (-not (Test-Docker)) {
return
}
# Create configuration
New-EnvironmentFile
# Build and start services
Build-MCPImage
Start-Infrastructure
Wait-ForServices
Install-Models
# Configure Claude Desktop
$configUpdated = Update-ClaudeConfig
# Test installation
$testPassed = Test-Installation
Write-Host ""
Write-Host "๐ Installation Complete!" -ForegroundColor Green
Write-Host "=========================" -ForegroundColor Green
Write-Host ""
Write-Host "โ
PostgreSQL with pgvector: Running on port 5432" -ForegroundColor Green
Write-Host "โ
Ollama with AI models: Running on port 11434" -ForegroundColor Green
Write-Host "โ
MCP Server: Built and ready" -ForegroundColor Green
if ($configUpdated) {
Write-Host "โ
Claude Desktop: Configured" -ForegroundColor Green
} else {
Write-Host "โ ๏ธ Claude Desktop: Manual configuration needed" -ForegroundColor Yellow
}
if ($testPassed) {
Write-Host "โ
System Test: Passed" -ForegroundColor Green
} else {
Write-Host "โ ๏ธ System Test: Check manually" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "๐ Next Steps:" -ForegroundColor Cyan
Write-Host "1. Restart Claude Desktop" -ForegroundColor White
Write-Host "2. Test with: /mcp (should show 'mem0-local')" -ForegroundColor White
Write-Host "3. Try: 'Remember that I'm testing the MCP memory system'" -ForegroundColor White
Write-Host "4. Verify: 'What do you remember about me?'" -ForegroundColor White
Write-Host ""
Write-Host "๐ง Troubleshooting:" -ForegroundColor Cyan
Write-Host "- Check services: docker ps" -ForegroundColor White
Write-Host "- View logs: docker-compose -f docker-compose.local.yml logs" -ForegroundColor White
Write-Host "- Restart: docker-compose -f docker-compose.local.yml restart" -ForegroundColor White
}
catch {
Write-Host ""
Write-Host "โ Installation failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Please check the error above and try again." -ForegroundColor Red
}
}
# Run installation
Start-Installation