-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathinstall-macos.sh
More file actions
executable file
·193 lines (174 loc) · 5.98 KB
/
Copy pathinstall-macos.sh
File metadata and controls
executable file
·193 lines (174 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/sh
# ha-mcp installer for macOS
# Usage: curl -LsSf https://raw.githubusercontent.com/homeassistant-ai/ha-mcp/master/scripts/install-macos.sh | sh
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
printf "\n"
printf "${BLUE}============================================${NC}\n"
printf "${BLUE} ha-mcp Installer for macOS${NC}\n"
printf "${BLUE}============================================${NC}\n"
printf "\n"
# Configuration
CONFIG_DIR="$HOME/Library/Application Support/Claude"
CONFIG_FILE="$CONFIG_DIR/claude_desktop_config.json"
DEMO_URL="https://ha-mcp-demo-server.qc-h.net"
DEMO_TOKEN="demo"
# Step 1: Check/install uv
printf "${YELLOW}Step 1: Checking for uv...${NC}\n"
if command -v uv > /dev/null 2>&1 || command -v uvx > /dev/null 2>&1; then
printf "${GREEN} uv is already installed${NC}\n"
else
printf " Installing uv...\n"
curl -LsSf https://astral.sh/uv/install.sh | sh
# Source the new path
export PATH="$HOME/.local/bin:$PATH"
if command -v uvx > /dev/null 2>&1; then
printf "${GREEN} uv installed successfully${NC}\n"
else
printf "${RED} Failed to install uv. Please install manually:${NC}\n"
printf " brew install uv\n"
printf " OR\n"
printf " curl -LsSf https://astral.sh/uv/install.sh | sh\n"
exit 1
fi
fi
# Get full path to uvx (Claude Desktop doesn't inherit shell PATH)
UVX_PATH=""
if command -v uvx > /dev/null 2>&1; then
UVX_PATH=$(command -v uvx)
elif [ -x "$HOME/.local/bin/uvx" ]; then
UVX_PATH="$HOME/.local/bin/uvx"
elif [ -x "/usr/local/bin/uvx" ]; then
UVX_PATH="/usr/local/bin/uvx"
elif [ -x "/opt/homebrew/bin/uvx" ]; then
UVX_PATH="/opt/homebrew/bin/uvx"
else
printf "${RED} Could not find uvx. Please check your installation.${NC}\n"
exit 1
fi
printf " Using uvx at: ${BLUE}%s${NC}\n" "$UVX_PATH"
printf "\n"
# Step 2: Configure Claude Desktop
printf "${YELLOW}Step 2: Configuring Claude Desktop...${NC}\n"
CLAUDE_NOT_INSTALLED=false
if [ ! -d "$CONFIG_DIR" ]; then
CLAUDE_NOT_INSTALLED=true
printf " Claude Desktop not yet installed - creating config for later\n"
fi
# Create config directory if needed
mkdir -p "$CONFIG_DIR"
# The MCP server config to add (using full path for Claude Desktop compatibility)
HA_MCP_CONFIG='{
"command": "'"$UVX_PATH"'",
"args": ["ha-mcp@latest"],
"env": {
"HOMEASSISTANT_URL": "'"$DEMO_URL"'",
"HOMEASSISTANT_TOKEN": "'"$DEMO_TOKEN"'"
}
}'
# Check if config file exists and handle accordingly
if [ -f "$CONFIG_FILE" ]; then
# Backup existing config
BACKUP_FILE="${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
cp "$CONFIG_FILE" "$BACKUP_FILE"
printf " Backed up existing config to:\n"
printf " ${BLUE}%s${NC}\n" "$BACKUP_FILE"
# Check if ha-mcp is already configured
if grep -q '"Home Assistant"' "$CONFIG_FILE" 2>/dev/null; then
printf "${YELLOW} Home Assistant MCP already configured.${NC}\n"
printf " Updating configuration...\n"
fi
# Use Python to merge the config (available on all Macs)
python3 << EOF
import json
import sys
config_file = "$CONFIG_FILE"
demo_url = "$DEMO_URL"
demo_token = "$DEMO_TOKEN"
uvx_path = "$UVX_PATH"
try:
with open(config_file, 'r') as f:
content = f.read().strip()
if content:
config = json.loads(content)
else:
config = {}
except (json.JSONDecodeError, FileNotFoundError):
config = {}
# Ensure mcpServers exists
if 'mcpServers' not in config:
config['mcpServers'] = {}
# Add/update Home Assistant config (using full path for Claude Desktop compatibility)
config['mcpServers']['Home Assistant'] = {
"command": uvx_path,
"args": ["--refresh", "ha-mcp@latest"],
"env": {
"HOMEASSISTANT_URL": demo_url,
"HOMEASSISTANT_TOKEN": demo_token
}
}
with open(config_file, 'w') as f:
json.dump(config, f, indent=2)
print(" Configuration updated successfully")
EOF
else
# Create new config file (using full path for Claude Desktop compatibility)
cat > "$CONFIG_FILE" << EOF
{
"mcpServers": {
"Home Assistant": {
"command": "$UVX_PATH",
"args": ["--refresh", "ha-mcp@latest"],
"env": {
"HOMEASSISTANT_URL": "$DEMO_URL",
"HOMEASSISTANT_TOKEN": "$DEMO_TOKEN"
}
}
}
}
EOF
printf " Created new configuration file\n"
fi
printf "${GREEN} Claude Desktop configured${NC}\n"
printf "\n"
# Step 3: Pre-download dependencies
printf "${YELLOW}Step 3: Pre-downloading ha-mcp...${NC}\n"
printf " This speeds up Claude Desktop startup...\n"
"$UVX_PATH" --refresh ha-mcp@latest --version > /dev/null 2>&1 || true
printf "${GREEN} Dependencies cached${NC}\n"
printf "\n"
# Success message
printf "${GREEN}============================================${NC}\n"
printf "${GREEN} Installation Complete!${NC}\n"
printf "${GREEN}============================================${NC}\n"
printf "\n"
printf "${YELLOW}Next steps:${NC}\n"
printf "\n"
if [ "$CLAUDE_NOT_INSTALLED" = true ]; then
printf " 1. Download Claude Desktop: ${BLUE}https://claude.ai/download${NC}\n"
printf " 2. Create a free account at claude.ai (if you haven't)\n"
printf " 3. Open Claude Desktop and ask: \"Can you see my Home Assistant?\"\n"
else
printf " 1. Quit Claude Desktop: Claude menu > Quit Claude\n"
printf " 2. Reopen and ask: \"Can you see my Home Assistant?\"\n"
fi
printf "\n"
printf "${YELLOW}Note:${NC} If Claude Desktop was already running, you must restart it\n"
printf " to load the new configuration.\n"
printf "\n"
printf "${BLUE}Demo environment:${NC}\n"
printf " Web UI: %s\n" "$DEMO_URL"
printf " Login: mcp / mcp\n"
printf " (Resets weekly - changes won't persist)\n"
printf "\n"
printf "${YELLOW}To use YOUR Home Assistant:${NC}\n"
printf " Edit: %s\n" "$CONFIG_FILE"
printf " Replace HOMEASSISTANT_URL with your HA URL\n"
printf " Replace HOMEASSISTANT_TOKEN with your token\n"
printf " (Generate token in HA: Profile > Security > Long-lived tokens)\n"
printf "\n"