-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathinstall-windows.ps1
More file actions
158 lines (143 loc) · 5.86 KB
/
Copy pathinstall-windows.ps1
File metadata and controls
158 lines (143 loc) · 5.86 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
# ha-mcp installer for Windows
# Usage: irm https://raw.githubusercontent.com/homeassistant-ai/ha-mcp/master/scripts/install-windows.ps1 | iex
# Or: Invoke-WebRequest -Uri "..." -OutFile install.ps1; .\install.ps1
$ErrorActionPreference = "Stop"
# Configuration
$ConfigDir = "$env:APPDATA\Claude"
$ConfigFile = "$ConfigDir\claude_desktop_config.json"
$DemoUrl = "https://ha-mcp-demo-server.qc-h.net"
$DemoToken = "demo"
Write-Host ""
Write-Host "============================================" -ForegroundColor Blue
Write-Host " ha-mcp Installer for Windows" -ForegroundColor Blue
Write-Host "============================================" -ForegroundColor Blue
Write-Host ""
# Step 1: Check/install uv
Write-Host "Step 1: Checking for uv..." -ForegroundColor Yellow
$uvInstalled = $null
try {
$uvInstalled = Get-Command uvx -ErrorAction SilentlyContinue
} catch {}
if ($uvInstalled) {
Write-Host " uv is already installed" -ForegroundColor Green
} else {
Write-Host " Installing uv..."
try {
winget install astral-sh.uv -e --accept-source-agreements --accept-package-agreements
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host " uv installed successfully" -ForegroundColor Green
} catch {
Write-Host " Failed to install uv via winget." -ForegroundColor Red
Write-Host " Please install manually:" -ForegroundColor Red
Write-Host " winget install astral-sh.uv" -ForegroundColor Cyan
Write-Host " OR download from: https://docs.astral.sh/uv/" -ForegroundColor Cyan
exit 1
}
}
Write-Host ""
# Step 2: Configure Claude Desktop
Write-Host "Step 2: Configuring Claude Desktop..." -ForegroundColor Yellow
$ClaudeNotInstalled = $false
if (-not (Test-Path $ConfigDir)) {
$ClaudeNotInstalled = $true
Write-Host " Claude Desktop not yet installed - creating config for later" -ForegroundColor White
}
# Create config directory if needed
if (-not (Test-Path $ConfigDir)) {
New-Item -ItemType Directory -Path $ConfigDir -Force | Out-Null
}
# The MCP server config
$HaMcpConfig = @{
command = "uvx"
args = @("ha-mcp@latest")
env = @{
HOMEASSISTANT_URL = $DemoUrl
HOMEASSISTANT_TOKEN = $DemoToken
}
}
# The properly formatted JSON config
$JsonConfig = @"
{
"mcpServers": {
"Home Assistant": {
"command": "uvx",
"args": ["--refresh", "ha-mcp@latest"],
"env": {
"HOMEASSISTANT_URL": "$DemoUrl",
"HOMEASSISTANT_TOKEN": "$DemoToken"
}
}
}
}
"@
# Check if config file exists
if (Test-Path $ConfigFile) {
# Backup existing config
$BackupFile = "$ConfigFile.backup.$(Get-Date -Format 'yyyyMMdd_HHmmss')"
Copy-Item $ConfigFile $BackupFile
Write-Host " Backed up existing config to:" -ForegroundColor White
Write-Host " $BackupFile" -ForegroundColor Cyan
# Check if already configured
$content = Get-Content $ConfigFile -Raw -ErrorAction SilentlyContinue
if ($content -match '"Home Assistant"') {
Write-Host " Home Assistant MCP already configured." -ForegroundColor Yellow
Write-Host " Updating configuration..." -ForegroundColor White
}
# For simplicity, we write the clean config (merging would require complex JSON handling)
# The backup preserves any other MCP servers the user had
# Use .NET to write UTF-8 without BOM (PowerShell's -Encoding UTF8 adds BOM which breaks JSON parsers)
[System.IO.File]::WriteAllText($ConfigFile, $JsonConfig)
Write-Host " Configuration updated successfully" -ForegroundColor White
} else {
# Create new config file
# Use .NET to write UTF-8 without BOM (PowerShell's -Encoding UTF8 adds BOM which breaks JSON parsers)
[System.IO.File]::WriteAllText($ConfigFile, $JsonConfig)
Write-Host " Created new configuration file" -ForegroundColor White
}
Write-Host " Claude Desktop configured" -ForegroundColor Green
Write-Host ""
# Step 3: Pre-download dependencies
Write-Host "Step 3: Pre-downloading ha-mcp..." -ForegroundColor Yellow
Write-Host " This speeds up Claude Desktop startup..."
try {
& uvx --refresh ha-mcp@latest --version 2>&1 | Out-Null
Write-Host " Dependencies cached" -ForegroundColor Green
} catch {
Write-Host " Pre-download skipped (will download on first use)" -ForegroundColor Yellow
}
Write-Host ""
# Success message
Write-Host "============================================" -ForegroundColor Green
Write-Host " Installation Complete!" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host ""
if ($ClaudeNotInstalled) {
Write-Host " 1. Download Claude Desktop: " -NoNewline
Write-Host "https://claude.ai/download" -ForegroundColor Cyan
Write-Host " 2. Create a free account at claude.ai (if you haven't)"
Write-Host ' 3. Open Claude Desktop and ask: "Can you see my Home Assistant?"'
} else {
Write-Host " 1. Exit Claude Desktop: File > Exit (or right-click system tray > Exit)"
Write-Host ' 2. Reopen and ask: "Can you see my Home Assistant?"'
}
Write-Host ""
Write-Host "Note: " -ForegroundColor Yellow -NoNewline
Write-Host "If Claude Desktop was already running, you must restart it"
Write-Host " to load the new configuration."
Write-Host ""
Write-Host "Demo environment:" -ForegroundColor Cyan
Write-Host " Web UI: $DemoUrl"
Write-Host " Login: mcp / mcp"
Write-Host " (Resets weekly - changes won't persist)"
Write-Host ""
Write-Host "To use YOUR Home Assistant:" -ForegroundColor Yellow
Write-Host " Edit: $ConfigFile"
Write-Host " Replace HOMEASSISTANT_URL with your HA URL"
Write-Host " Replace HOMEASSISTANT_TOKEN with your token"
Write-Host " (Generate token in HA: Profile > Security > Long-lived tokens)"
Write-Host ""
# Exit successfully
exit 0