#!/bin/bash
#
# Chatlog MCP Server - Installation Script
# This script installs and configures the Chatlog MCP Server
#
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print colored output
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Print banner
print_banner() {
echo -e "${BLUE}"
cat << 'EOF'
╔══════════════════════════════════════════════════════════════╗
║ ║
║ Chatlog MCP Server Installer ║
║ ║
║ A Model Context Protocol server for chat log analysis ║
║ ║
╚══════════════════════════════════════════════════════════════╝
EOF
echo -e "${NC}"
}
# Check system requirements
check_requirements() {
print_info "Checking system requirements..."
# Check Python
if command_exists python3; then
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
print_success "Python $PYTHON_VERSION found"
else
print_error "Python 3 is not installed. Please install Python 3.10 or higher."
exit 1
fi
# Check pip
if command_exists pip3 || command_exists pip; then
print_success "pip found"
else
print_error "pip is not installed. Please install pip."
exit 1
fi
# Check git (optional)
if command_exists git; then
print_success "git found (optional)"
else
print_warning "git not found (optional)"
fi
}
# Install package
install_package() {
print_info "Installing Chatlog MCP Server..."
# Determine pip command
if command_exists pip3; then
PIP_CMD="pip3"
else
PIP_CMD="pip"
fi
# Install package
if [ -f "setup.py" ]; then
print_info "Installing from local source..."
$PIP_CMD install -e .
else
print_info "Installing from PyPI..."
$PIP_CMD install chatlog-mcp-server
fi
if [ $? -eq 0 ]; then
print_success "Package installed successfully"
else
print_error "Installation failed"
exit 1
fi
}
# Create configuration
create_config() {
print_info "Creating MCP configuration..."
CONFIG_DIR="$HOME/.config/claude"
CONFIG_FILE="$CONFIG_DIR/mcp-servers.json"
# Create config directory if it doesn't exist
if [ ! -d "$CONFIG_DIR" ]; then
mkdir -p "$CONFIG_DIR"
print_success "Created config directory: $CONFIG_DIR"
fi
# Create or merge configuration
if [ -f "$CONFIG_FILE" ]; then
print_warning "Configuration file already exists at $CONFIG_FILE"
read -p "Do you want to backup and replace it? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
cp "$CONFIG_FILE" "$CONFIG_FILE.backup.$(date +%Y%m%d_%H%M%S)"
print_success "Backup created"
else
print_info "Keeping existing configuration"
return
fi
fi
# Create configuration
cat > "$CONFIG_FILE" << 'EOF'
{
"mcpServers": {
"chatlog": {
"command": "chatlog-mcp",
"args": [],
"env": {
"PYTHONIOENCODING": "utf-8"
}
}
}
}
EOF
print_success "Configuration created at $CONFIG_FILE"
}
# Verify installation
verify_installation() {
print_info "Verifying installation..."
# Test if command is available
if command_exists chatlog-mcp; then
print_success "chatlog-mcp command is available"
else
print_warning "chatlog-mcp command not found in PATH"
print_info "You may need to add it to your PATH or use: python -m chatlog_mcp.cli"
fi
# Test help command
if chatlog-mcp --help > /dev/null 2>&1; then
print_success "Server starts successfully"
else
print_warning "Could not start server (this is normal if no HTTP API is running)"
fi
}
# Print next steps
print_next_steps() {
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ║${NC}"
echo -e "${GREEN}║ Installation Complete! ║${NC}"
echo -e "${GREEN}║ ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo "Next steps:"
echo ""
echo -e "${BLUE}1.${NC} Start Claude Code with MCP configuration:"
echo " claude --mcp-config ~/.config/claude/mcp-servers.json"
echo ""
echo -e "${BLUE}2.${NC} Or add to your shell profile (~/.bashrc or ~/.zshrc):"
echo " export CLAUDE_MCP_CONFIG=~/.config/claude/mcp-servers.json"
echo ""
echo -e "${BLUE}3.${NC} Verify the installation:"
echo " chatlog-mcp --version"
echo ""
echo -e "${BLUE}4.${NC} Run the server:"
echo " chatlog-mcp"
echo ""
echo -e "${YELLOW}Note:${NC} Make sure your HTTP API server is running on the specified URL"
echo " (default: http://127.0.0.1:5030)"
echo ""
echo -e "${BLUE}Documentation:${NC} https://github.com/anthropics/chatlog-mcp-server"
echo -e "${BLUE}Support:${NC} support@anthropic.com"
echo ""
}
# Main installation flow
main() {
print_banner
# Parse command line arguments
SKIP_DEPS=false
for arg in "$@"; do
case $arg in
--skip-deps)
SKIP_DEPS=true
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --skip-deps Skip dependency checks"
echo " --help, -h Show this help message"
exit 0
;;
esac
done
# Run installation steps
if [ "$SKIP_DEPS" = false ]; then
check_requirements
fi
install_package
create_config
verify_installation
print_next_steps
print_success "Installation completed successfully!"
}
# Run main function
main "$@"