#!/bin/bash # Home Assistant MCP Server Validation Script # Checks that everything is set up correctly set -e echo "================================================" echo "Home Assistant MCP Server - Setup Validation" echo "================================================" echo "" ERRORS=0 WARNINGS=0 # Helper functions check_pass() { echo "✅ $1" } check_fail() { echo "❌ $1" ERRORS=$((ERRORS + 1)) } check_warn() { echo "⚠️ $1" WARNINGS=$((WARNINGS + 1)) } # 1. Check Node.js echo "Checking Node.js installation..." if command -v node &> /dev/null; then NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) if [ "$NODE_VERSION" -ge 18 ]; then check_pass "Node.js version $(node -v) is installed" else check_fail "Node.js version too old: $(node -v). Need 18 or higher." fi else check_fail "Node.js is not installed" fi echo "" # 2. Check npm echo "Checking npm installation..." if command -v npm &> /dev/null; then check_pass "npm version $(npm -v) is installed" else check_fail "npm is not installed" fi echo "" # 3. Check dependencies echo "Checking project dependencies..." if [ -f "package.json" ]; then check_pass "package.json exists" if [ -d "node_modules" ]; then check_pass "node_modules directory exists" # Check key dependencies if [ -d "node_modules/@modelcontextprotocol" ]; then check_pass "MCP SDK is installed" else check_fail "MCP SDK is not installed. Run: npm install" fi if [ -d "node_modules/axios" ]; then check_pass "axios is installed" else check_fail "axios is not installed. Run: npm install" fi if [ -d "node_modules/zod" ]; then check_pass "zod is installed" else check_fail "zod is not installed. Run: npm install" fi else check_fail "node_modules not found. Run: npm install" fi else check_fail "package.json not found" fi echo "" # 4. Check TypeScript configuration echo "Checking TypeScript configuration..." if [ -f "tsconfig.json" ]; then check_pass "tsconfig.json exists" else check_fail "tsconfig.json not found" fi echo "" # 5. Check source files echo "Checking source files..." if [ -d "src" ]; then check_pass "src directory exists" if [ -f "src/index.ts" ]; then check_pass "src/index.ts exists" else check_fail "src/index.ts not found" fi if [ -f "src/ha-client.ts" ]; then check_pass "src/ha-client.ts exists" else check_fail "src/ha-client.ts not found" fi if [ -f "src/types.ts" ]; then check_pass "src/types.ts exists" else check_fail "src/types.ts not found" fi else check_fail "src directory not found" fi echo "" # 6. Check build echo "Checking build output..." if [ -d "build" ]; then check_pass "build directory exists" if [ -f "build/index.js" ]; then check_pass "build/index.js exists" else check_warn "build/index.js not found. Run: npm run build" fi else check_warn "build directory not found. Run: npm run build" fi echo "" # 7. Check environment configuration echo "Checking environment configuration..." if [ -f ".env" ]; then check_pass ".env file exists" # Source .env and check variables source .env if [ -n "$HA_BASE_URL" ]; then check_pass "HA_BASE_URL is set: $HA_BASE_URL" # Validate URL format if [[ $HA_BASE_URL =~ ^https?:// ]]; then check_pass "HA_BASE_URL has valid protocol" else check_fail "HA_BASE_URL must start with http:// or https://" fi else check_fail "HA_BASE_URL is not set in .env" fi if [ -n "$HA_ACCESS_TOKEN" ]; then TOKEN_LENGTH=${#HA_ACCESS_TOKEN} if [ $TOKEN_LENGTH -gt 50 ]; then check_pass "HA_ACCESS_TOKEN is set (${TOKEN_LENGTH} characters)" else check_warn "HA_ACCESS_TOKEN seems too short (${TOKEN_LENGTH} characters)" fi else check_fail "HA_ACCESS_TOKEN is not set in .env" fi else check_fail ".env file not found. Copy .env.example to .env and configure it." fi echo "" # 8. Check documentation echo "Checking documentation..." DOC_COUNT=0 [ -f "README.md" ] && DOC_COUNT=$((DOC_COUNT + 1)) [ -f "QUICK_START.md" ] && DOC_COUNT=$((DOC_COUNT + 1)) [ -f "ARCHITECTURE.md" ] && DOC_COUNT=$((DOC_COUNT + 1)) [ -f "EXAMPLES.md" ] && DOC_COUNT=$((DOC_COUNT + 1)) if [ $DOC_COUNT -eq 4 ]; then check_pass "All documentation files present" else check_warn "Some documentation files missing ($DOC_COUNT/4 found)" fi echo "" # 9. Test Home Assistant connection if [ -f ".env" ]; then echo "Testing Home Assistant connection..." source .env if [ -n "$HA_BASE_URL" ] && [ -n "$HA_ACCESS_TOKEN" ]; then # Test connection HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: Bearer $HA_ACCESS_TOKEN" \ "$HA_BASE_URL/api/" 2>/dev/null || echo "000") if [ "$HTTP_CODE" = "200" ]; then check_pass "Successfully connected to Home Assistant" # Get HA version HA_VERSION=$(curl -s -H "Authorization: Bearer $HA_ACCESS_TOKEN" \ "$HA_BASE_URL/api/config" 2>/dev/null | grep -o '"version":"[^"]*"' | cut -d'"' -f4 || echo "unknown") echo " Home Assistant version: $HA_VERSION" elif [ "$HTTP_CODE" = "401" ]; then check_fail "Connection failed: Invalid access token (401 Unauthorized)" elif [ "$HTTP_CODE" = "000" ]; then check_fail "Connection failed: Cannot reach Home Assistant at $HA_BASE_URL" echo " Check that Home Assistant is running and the URL is correct" else check_fail "Connection failed: HTTP $HTTP_CODE" fi else check_warn "Skipping connection test (missing credentials)" fi else check_warn "Skipping connection test (.env not found)" fi echo "" # 10. Summary echo "================================================" echo "Validation Summary" echo "================================================" if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then echo "🎉 All checks passed! Your setup is ready." echo "" echo "Next steps:" echo " 1. Run the server: npm start" echo " 2. Configure Claude Desktop (see README.md)" echo " 3. Test with an LLM client" EXIT_CODE=0 elif [ $ERRORS -eq 0 ]; then echo "⚠️ Setup is functional with $WARNINGS warning(s)." echo "" echo "You can proceed, but consider addressing the warnings above." EXIT_CODE=0 else echo "❌ Found $ERRORS error(s) and $WARNINGS warning(s)." echo "" echo "Please fix the errors above before proceeding." echo "" echo "Common fixes:" echo " - Run: npm install" echo " - Run: npm run build" echo " - Create and configure .env file" echo " - Check Home Assistant is running" EXIT_CODE=1 fi echo "" exit $EXIT_CODE