#!/bin/bash
# MCP Memos Server Setup Script
set -e
echo "π Setting up MCP Memos Server..."
# Check if .env exists
if [ ! -f ".env" ]; then
echo "π Creating .env file from template..."
cp .env.example .env
echo "β
Created .env file"
echo "β οΈ Please edit .env with your Memos server details before continuing"
echo ""
echo "Required configuration:"
echo " - MEMOS_URL: Your Memos server URL"
echo " - MEMOS_API_KEY: Your Memos API key"
echo ""
read -p "Press Enter after you've configured .env..."
else
echo "β
Found existing .env file"
fi
# Check if Docker is available
if command -v docker >/dev/null 2>&1 && command -v docker-compose >/dev/null 2>&1; then
echo "π³ Docker detected"
read -p "Do you want to build and run with Docker? [Y/n]: " use_docker
use_docker=${use_docker:-y}
if [[ $use_docker =~ ^[Yy]$ ]]; then
echo "π¨ Building Docker image..."
docker-compose build
echo "β
Docker image built successfully"
echo ""
echo "To run the server:"
echo " docker-compose up -d"
echo ""
echo "To view logs:"
echo " docker-compose logs -f mcp-memos-server"
echo ""
echo "To stop the server:"
echo " docker-compose down"
echo ""
read -p "Start the server now? [Y/n]: " start_now
start_now=${start_now:-y}
if [[ $start_now =~ ^[Yy]$ ]]; then
echo "π Starting MCP Memos Server..."
docker-compose up -d
sleep 2
echo "π Checking server status..."
docker-compose logs --tail=20 mcp-memos-server
fi
exit 0
fi
fi
# Python setup
echo "π Setting up Python environment..."
# Check Python version
python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
required_version="3.11"
if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" != "$required_version" ]; then
echo "β Python 3.11+ required, but found Python $python_version"
echo "Please upgrade Python or use Docker instead"
exit 1
fi
echo "β
Python $python_version detected"
# Create virtual environment if it doesn't exist
if [ ! -d "venv" ]; then
echo "π¦ Creating virtual environment..."
python3 -m venv venv
fi
# Activate virtual environment
echo "π Activating virtual environment..."
source venv/bin/activate
# Install dependencies
echo "π Installing dependencies..."
pip install --upgrade pip
pip install -r requirements.txt
echo "β
Dependencies installed"
# Run tests
echo ""
echo "π§ͺ Running tests to verify setup..."
read -p "Run tests now? [Y/n]: " run_tests
run_tests=${run_tests:-y}
if [[ $run_tests =~ ^[Yy]$ ]]; then
python test_server.py
fi
echo ""
echo "π Setup complete!"
echo ""
echo "To run the server:"
echo " source venv/bin/activate"
echo " python server.py"
echo ""
echo "To configure with Claude Desktop, add this to your MCP config:"
echo '{'
echo ' "mcpServers": {'
echo ' "memos": {'
echo ' "command": "python",'
echo " \"args\": [\"$(pwd)/server.py\"],"
echo ' "env": {'
echo " \"MEMOS_URL\": \"$(grep MEMOS_URL .env | cut -d '=' -f2)\","
echo " \"MEMOS_API_KEY\": \"$(grep MEMOS_API_KEY .env | cut -d '=' -f2)\""
echo ' }'
echo ' }'
echo ' }'
echo '}'