Skip to content

Commit f9a5b39

Browse files
authored
fix: change log path to user home and force uvx refresh in install scripts (#443)
* fix: change default log path to user home dir to avoid read-only errors * fix: force uvx refresh in install scripts to ensure latest version
1 parent 575a5a8 commit f9a5b39

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

scripts/install-macos.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ if 'mcpServers' not in config:
121121
# Add/update Home Assistant config (using full path for Claude Desktop compatibility)
122122
config['mcpServers']['Home Assistant'] = {
123123
"command": uvx_path,
124-
"args": ["ha-mcp@latest"],
124+
"args": ["--refresh", "ha-mcp@latest"],
125125
"env": {
126126
"HOMEASSISTANT_URL": demo_url,
127127
"HOMEASSISTANT_TOKEN": demo_token
@@ -140,7 +140,7 @@ else
140140
"mcpServers": {
141141
"Home Assistant": {
142142
"command": "$UVX_PATH",
143-
"args": ["ha-mcp@latest"],
143+
"args": ["--refresh", "ha-mcp@latest"],
144144
"env": {
145145
"HOMEASSISTANT_URL": "$DEMO_URL",
146146
"HOMEASSISTANT_TOKEN": "$DEMO_TOKEN"
@@ -157,7 +157,7 @@ printf "\n"
157157
# Step 3: Pre-download dependencies
158158
printf "${YELLOW}Step 3: Pre-downloading ha-mcp...${NC}\n"
159159
printf " This speeds up Claude Desktop startup...\n"
160-
"$UVX_PATH" ha-mcp@latest --version > /dev/null 2>&1 || true
160+
"$UVX_PATH" --refresh ha-mcp@latest --version > /dev/null 2>&1 || true
161161
printf "${GREEN} Dependencies cached${NC}\n"
162162
printf "\n"
163163

scripts/install-windows.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $JsonConfig = @"
7171
"mcpServers": {
7272
"Home Assistant": {
7373
"command": "uvx",
74-
"args": ["ha-mcp@latest"],
74+
"args": ["--refresh", "ha-mcp@latest"],
7575
"env": {
7676
"HOMEASSISTANT_URL": "$DemoUrl",
7777
"HOMEASSISTANT_TOKEN": "$DemoToken"
@@ -114,7 +114,7 @@ Write-Host ""
114114
Write-Host "Step 3: Pre-downloading ha-mcp..." -ForegroundColor Yellow
115115
Write-Host " This speeds up Claude Desktop startup..."
116116
try {
117-
& uvx ha-mcp@latest --version 2>&1 | Out-Null
117+
& uvx --refresh ha-mcp@latest --version 2>&1 | Out-Null
118118
Write-Host " Dependencies cached" -ForegroundColor Green
119119
} catch {
120120
Write-Host " Pre-download skipped (will download on first use)" -ForegroundColor Yellow

src/ha_mcp/utils/usage_logger.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,22 @@ class UsageLogger:
108108

109109
def __init__(
110110
self,
111-
log_file_path: str = "logs/mcp_usage.jsonl",
111+
log_file_path: str | None = None,
112112
ring_buffer_size: int = DEFAULT_RING_BUFFER_SIZE,
113113
):
114114
self._enabled = True
115-
self.log_file_path = Path(log_file_path)
115+
116+
if log_file_path:
117+
self.log_file_path = Path(log_file_path)
118+
else:
119+
# Use user's home directory by default to avoid read-only filesystem errors
120+
# when running via uvx/npx which might have read-only CWD
121+
self.log_file_path = Path.home() / ".ha-mcp" / "logs" / "mcp_usage.jsonl"
122+
116123
try:
117124
self.log_file_path.parent.mkdir(parents=True, exist_ok=True)
118125
except OSError:
119-
# Directory creation failed (e.g., read-only filesystem when running via uvx)
126+
# Directory creation failed (e.g., read-only filesystem)
120127
# Disable logging silently to avoid disrupting the MCP server
121128
self._enabled = False
122129

tests/src/unit/test_usage_logger.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ def test_ring_buffer_with_error_entries(self, logger):
167167
assert entries[0]["error_message"] == "Entity not found"
168168

169169

170+
class TestUsageLoggerDefaults:
171+
"""Test UsageLogger default behavior."""
172+
173+
def test_default_log_path(self):
174+
"""Test that default log path is in user home directory."""
175+
logger = UsageLogger()
176+
assert str(logger.log_file_path).startswith(str(Path.home()))
177+
assert ".ha-mcp" in str(logger.log_file_path)
178+
logger.shutdown()
179+
180+
170181
class TestUsageLoggerConstants:
171182
"""Test constants are properly defined."""
172183

0 commit comments

Comments
 (0)