Files
ha-mcp-server/setup.sh
Felix Zösch 1761c3cdd3 Initial commit
2025-12-11 20:29:51 +01:00

90 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# Home Assistant MCP Server Setup Script
# This script helps you set up and configure the server
set -e
echo "=================================="
echo "Home Assistant MCP Server Setup"
echo "=================================="
echo ""
# Check Node.js version
echo "Checking Node.js version..."
if ! command -v node &> /dev/null; then
echo "Error: Node.js is not installed. Please install Node.js 18 or higher."
exit 1
fi
NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 18 ]; then
echo "Error: Node.js version 18 or higher is required. You have version $(node -v)"
exit 1
fi
echo "Node.js version: $(node -v)"
echo ""
# Install dependencies
echo "Installing dependencies..."
npm install
echo ""
# Create .env file if it doesn't exist
if [ ! -f .env ]; then
echo "Creating .env file..."
cp .env.example .env
echo ".env file created. Please edit it with your Home Assistant details."
echo ""
# Prompt for configuration
read -p "Enter your Home Assistant URL (e.g., http://homeassistant.local:8123): " HA_URL
read -p "Enter your Home Assistant access token: " HA_TOKEN
# Update .env file
sed -i.bak "s|HA_BASE_URL=.*|HA_BASE_URL=$HA_URL|" .env
sed -i.bak "s|HA_ACCESS_TOKEN=.*|HA_ACCESS_TOKEN=$HA_TOKEN|" .env
rm .env.bak
echo ".env file configured ✓"
else
echo ".env file already exists. Skipping configuration."
fi
echo ""
# Build the project
echo "Building TypeScript project..."
npm run build
echo "Build complete ✓"
echo ""
# Test connection to Home Assistant
echo "Testing connection to Home Assistant..."
if [ -f .env ]; then
source .env
if curl -s -f -H "Authorization: Bearer $HA_ACCESS_TOKEN" "$HA_BASE_URL/api/" > /dev/null; then
echo "Connection successful ✓"
else
echo "Warning: Could not connect to Home Assistant. Please verify:"
echo " 1. Home Assistant is running and accessible"
echo " 2. The URL in .env is correct"
echo " 3. The access token is valid"
fi
fi
echo ""
echo "=================================="
echo "Setup Complete!"
echo "=================================="
echo ""
echo "Next steps:"
echo " 1. Verify your .env configuration"
echo " 2. Run the server: npm start"
echo " 3. Or configure Claude Desktop (see README.md)"
echo ""
echo "For more information, see:"
echo " - README.md for usage instructions"
echo " - ARCHITECTURE.md for technical details"
echo " - EXAMPLES.md for usage examples"
echo ""