@coffeerunhobby/mcp-ha-connect 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/.env.example +19 -0
  2. package/README.md +444 -105
  3. package/dist/config.d.ts +2 -0
  4. package/dist/config.js +19 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/haClient/calendars.d.ts +33 -0
  7. package/dist/haClient/calendars.js +68 -0
  8. package/dist/haClient/calendars.js.map +1 -0
  9. package/dist/haClient/index.d.ts +18 -1
  10. package/dist/haClient/index.js +23 -0
  11. package/dist/haClient/index.js.map +1 -1
  12. package/dist/haClient/labels.d.ts +64 -0
  13. package/dist/haClient/labels.js +177 -0
  14. package/dist/haClient/labels.js.map +1 -0
  15. package/dist/server/auth.d.ts +20 -0
  16. package/dist/server/auth.js +74 -0
  17. package/dist/server/auth.js.map +1 -0
  18. package/dist/server/common.js +2 -1
  19. package/dist/server/common.js.map +1 -1
  20. package/dist/server/http.js +45 -4
  21. package/dist/server/http.js.map +1 -1
  22. package/dist/tools/calendar.d.ts +7 -0
  23. package/dist/tools/calendar.js +82 -0
  24. package/dist/tools/calendar.js.map +1 -0
  25. package/dist/tools/common.d.ts +17 -0
  26. package/dist/tools/common.js +9 -0
  27. package/dist/tools/common.js.map +1 -1
  28. package/dist/tools/index.js +24 -7
  29. package/dist/tools/index.js.map +1 -1
  30. package/dist/tools/labels.d.ts +12 -0
  31. package/dist/tools/labels.js +139 -0
  32. package/dist/tools/labels.js.map +1 -0
  33. package/dist/tools/listPersons.d.ts +6 -0
  34. package/dist/tools/listPersons.js +36 -0
  35. package/dist/tools/listPersons.js.map +1 -0
  36. package/dist/tools/searchEntities.js +3 -1
  37. package/dist/tools/searchEntities.js.map +1 -1
  38. package/dist/types/automations.d.ts +38 -0
  39. package/dist/types/automations.js +5 -0
  40. package/dist/types/automations.js.map +1 -0
  41. package/dist/types/calendars.d.ts +24 -0
  42. package/dist/types/calendars.js +5 -0
  43. package/dist/types/calendars.js.map +1 -0
  44. package/dist/types/config.d.ts +10 -0
  45. package/dist/types/config.js +5 -0
  46. package/dist/types/config.js.map +1 -0
  47. package/dist/types/entities.d.ts +13 -0
  48. package/dist/types/entities.js +5 -0
  49. package/dist/types/entities.js.map +1 -0
  50. package/dist/types/entity.d.ts +21 -0
  51. package/dist/types/history.d.ts +12 -0
  52. package/dist/types/history.js +5 -0
  53. package/dist/types/history.js.map +1 -0
  54. package/dist/types/index.d.ts +7 -1
  55. package/dist/types/index.js +1 -0
  56. package/dist/types/index.js.map +1 -1
  57. package/dist/types/labels.d.ts +34 -0
  58. package/dist/types/labels.js +5 -0
  59. package/dist/types/labels.js.map +1 -0
  60. package/dist/types/states.d.ts +19 -0
  61. package/dist/types/states.js +5 -0
  62. package/dist/types/states.js.map +1 -0
  63. package/dist/types/updates.d.ts +24 -0
  64. package/dist/types/updates.js +5 -0
  65. package/dist/types/updates.js.map +1 -0
  66. package/dist/utils/sanitize.d.ts +25 -0
  67. package/dist/utils/sanitize.js +92 -0
  68. package/dist/utils/sanitize.js.map +1 -0
  69. package/dist/version.d.ts +5 -0
  70. package/dist/version.js +17 -0
  71. package/dist/version.js.map +1 -0
  72. package/docs/CHANGELOG.md +126 -104
  73. package/docs/LOCAL_CLIENT.md +572 -338
  74. package/docs/SSE_API.md +1 -1
  75. package/openapi.json +1149 -37
  76. package/package.json +4 -3
  77. package/src/config.ts +29 -0
  78. package/src/haClient/calendars.ts +94 -0
  79. package/src/haClient/index.ts +36 -0
  80. package/src/server/auth.ts +103 -0
  81. package/src/server/common.ts +2 -1
  82. package/src/server/http.ts +56 -4
  83. package/src/tools/calendar.ts +97 -0
  84. package/src/tools/common.ts +11 -0
  85. package/src/tools/index.ts +28 -7
  86. package/src/tools/listPersons.ts +46 -0
  87. package/src/tools/searchEntities.ts +3 -1
  88. package/src/types/automations.ts +43 -0
  89. package/src/types/calendars.ts +26 -0
  90. package/src/types/config.ts +11 -0
  91. package/src/types/entities.ts +14 -0
  92. package/src/types/history.ts +13 -0
  93. package/src/types/index.ts +37 -1
  94. package/src/types/states.ts +21 -0
  95. package/src/types/updates.ts +28 -0
  96. package/src/version.ts +16 -0
  97. package/tests/bdd/automation-creation.spec.ts +214 -0
  98. package/tests/bdd/automation-management.spec.ts +267 -0
  99. package/tests/bdd/calendar.spec.ts +190 -0
  100. package/tests/bdd/configuration.spec.ts +283 -0
  101. package/tests/bdd/device-control.spec.ts +344 -0
  102. package/tests/bdd/entity-listing.spec.ts +208 -0
  103. package/tests/bdd/entity-search.spec.ts +183 -0
  104. package/tests/bdd/history-retrieval.spec.ts +195 -0
  105. package/tests/bdd/notifications.spec.ts +238 -0
  106. package/tests/bdd/service-calls.spec.ts +144 -0
  107. package/tests/bdd/state-retrieval.spec.ts +204 -0
  108. package/tests/features/automation-creation.feature +36 -0
  109. package/tests/features/automation-management.feature +54 -0
  110. package/tests/features/calendar.feature +37 -0
  111. package/tests/features/configuration.feature +71 -0
  112. package/tests/features/device-control.feature +100 -0
  113. package/tests/features/entity-listing.feature +51 -0
  114. package/tests/features/entity-search.feature +44 -0
  115. package/tests/features/history-retrieval.feature +38 -0
  116. package/tests/features/notifications.feature +37 -0
  117. package/tests/features/service-calls.feature +35 -0
  118. package/tests/features/state-retrieval.feature +37 -0
  119. package/tests/haClient/index.test.ts +142 -110
  120. package/tests/localAI/index.test.ts +27 -18
  121. package/tests/server/auth.test.ts +206 -0
  122. package/tests/server/http.test.ts +118 -5
  123. package/tests/server/stdio.test.ts +4 -6
  124. package/vitest.config.ts +1 -1
  125. package/src/types/entity.ts +0 -111
package/.env.example CHANGED
@@ -104,6 +104,21 @@ MCP_HTTP_ALLOW_CORS=true
104
104
  # Default: 127.0.0.1,localhost
105
105
  MCP_HTTP_ALLOWED_ORIGINS=127.0.0.1,localhost,http://mcpserver.10.0.0.18.nip.io:3000
106
106
 
107
+ # -----------------------------------------------------------------------------
108
+ # Authentication Configuration (only when MCP_SERVER_USE_HTTP=true)
109
+ # -----------------------------------------------------------------------------
110
+
111
+ # Authentication method: none or bearer
112
+ # - none: No authentication required
113
+ # - bearer: Require Bearer token in Authorization header
114
+ # Default: none
115
+ MCP_AUTH_METHOD=none
116
+
117
+ # Authentication tokens (comma-separated for multiple clients)
118
+ # Required when MCP_AUTH_METHOD=bearer
119
+ # Example: MCP_AUTH_TOKEN=token1,token2,token3
120
+ # MCP_AUTH_TOKEN=your-secret-token-here
121
+
107
122
  # =============================================================================
108
123
  # Usage Examples
109
124
  # =============================================================================
@@ -138,6 +153,8 @@ MCP_HTTP_ALLOWED_ORIGINS=127.0.0.1,localhost,http://mcpserver.10.0.0.18.nip.io:3
138
153
  # MCP_HTTP_BIND_ADDR=0.0.0.0
139
154
  # MCP_HTTP_ALLOWED_ORIGINS=https://your-app.com
140
155
  # MCP_SERVER_STATEFUL=true
156
+ # MCP_AUTH_METHOD=bearer
157
+ # MCP_AUTH_TOKEN=n8n-token,openwebui-token,cli-token
141
158
 
142
159
  # =============================================================================
143
160
  # Security Notes
@@ -147,3 +164,5 @@ MCP_HTTP_ALLOWED_ORIGINS=127.0.0.1,localhost,http://mcpserver.10.0.0.18.nip.io:3
147
164
  # - Restrict MCP_HTTP_ALLOWED_ORIGINS to trusted domains
148
165
  # - Use MCP_HTTP_BIND_ADDR=127.0.0.1 for local-only access
149
166
  # - Rotate your Home Assistant tokens periodically
167
+ # - Enable MCP_AUTH_METHOD=bearer in production for API security
168
+ # - Use unique tokens per client for better access control and audit
package/README.md CHANGED
@@ -1,8 +1,101 @@
1
1
  # MCP-HA-Connect
2
2
 
3
- A production-ready Model Context Protocol (MCP) server for Home Assistant integration with AI assistants like Claude.
3
+ A production-ready Model Context Protocol (MCP) server for Home Assistant integration with AI assistants like Claude and LM Studio.
4
+
5
+ [![npm version](https://badge.fury.io/js/%40coffeerunhobby%2Fmcp-ha-connect.svg)](https://www.npmjs.com/package/@coffeerunhobby/mcp-ha-connect)
6
+ [![Docker](https://img.shields.io/badge/docker-ghcr.io-blue)](https://github.com/coffeerunhobby/mcp-ha-connect/pkgs/container/mcp-ha-connect)
7
+
8
+ ## Quick Start
9
+
10
+ Choose your preferred installation method:
11
+
12
+ ### Option 1: npx (Recommended - No Installation Required)
13
+
14
+ ```json
15
+ {
16
+ "mcpServers": {
17
+ "homeassistant": {
18
+ "command": "npx",
19
+ "args": ["-y", "@coffeerunhobby/mcp-ha-connect"],
20
+ "env": {
21
+ "HA_URL": "http://homeassistant.10.0.0.19.nip.io:8123",
22
+ "HA_TOKEN": "your_long_lived_access_token"
23
+ }
24
+ }
25
+ }
26
+ }
27
+ ```
28
+
29
+ ### Option 2: Global npm Install
30
+
31
+ ```bash
32
+ npm install -g @coffeerunhobby/mcp-ha-connect
33
+ ```
34
+
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "homeassistant": {
39
+ "command": "mcp-ha-connect",
40
+ "env": {
41
+ "HA_URL": "http://homeassistant.10.0.0.19.nip.io:8123",
42
+ "HA_TOKEN": "your_token"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### Option 3: Docker
50
+
51
+ ```json
52
+ {
53
+ "mcpServers": {
54
+ "homeassistant": {
55
+ "command": "docker",
56
+ "args": [
57
+ "run",
58
+ "--rm",
59
+ "-i",
60
+ "-e", "HA_URL=http://host.docker.internal:8123",
61
+ "-e", "HA_TOKEN=your_token",
62
+ "ghcr.io/coffeerunhobby/mcp-ha-connect:latest"
63
+ ]
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ ### Option 4: Local Development
70
+
71
+ ```json
72
+ {
73
+ "mcpServers": {
74
+ "homeassistant": {
75
+ "command": "node",
76
+ "args": ["C:\\workspace\\mcp-homeassistant\\dist\\index.js"],
77
+ "env": {
78
+ "HA_URL": "http://homeassistant.10.0.0.19.nip.io:8123",
79
+ "HA_TOKEN": "your_token"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
4
85
 
5
- ## Autonomous safety monitoring system:
86
+ ## Configuration Locations
87
+
88
+ ### Claude Desktop
89
+ - **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
90
+ - **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
91
+ - **Linux:** `~/.config/Claude/claude_desktop_config.json`
92
+
93
+ ### LM Studio
94
+ - **Windows:** `%USERPROFILE%\.lmstudio\config.json`
95
+ - **macOS:** `~/Library/Application Support/LM Studio/config.json`
96
+ - **Linux:** `~/.config/lmstudio/config.json`
97
+
98
+ ## Autonomous Safety Monitoring System
6
99
 
7
100
  1. **JS Pre-filter**: Tier A triggers + basic anomaly detection
8
101
  2. **Issue Objects**: Structured alerts (entity, area, threshold, observed, last_changed)
@@ -11,7 +104,6 @@ A production-ready Model Context Protocol (MCP) server for Home Assistant integr
11
104
  5. **Acknowledgment**: HA notification, Telegram, mobile app action, or voice
12
105
  6. **Auto-Response**: Water/gas shutoff via HA valves/switches
13
106
 
14
-
15
107
  See [docs/SSE_API.md](docs/SSE_API.md) for complete documentation of the SSE system.
16
108
 
17
109
  ## Key Features
@@ -56,7 +148,7 @@ See [docs/SSE_API.md](docs/SSE_API.md) for complete documentation of the SSE sys
56
148
  - Full type safety with TypeScript
57
149
  - Stateful and stateless session support
58
150
 
59
- ## Available Tools (34 Total)
151
+ ## Available Tools (37 Total)
60
152
 
61
153
  ### State & Entity Tools
62
154
 
@@ -70,6 +162,7 @@ See [docs/SSE_API.md](docs/SSE_API.md) for complete documentation of the SSE sys
70
162
  | `listEntities` | List entities with filtering (domain, state, search, limit) |
71
163
  | `getDomainSummary` | Get summary statistics for a domain |
72
164
  | `getHistory` | Get historical data for an entity |
165
+ | `listPersons` | List all household members with location state (home/away) |
73
166
 
74
167
  ### Service & Control Tools
75
168
 
@@ -116,6 +209,13 @@ See [docs/SSE_API.md](docs/SSE_API.md) for complete documentation of the SSE sys
116
209
  | `checkUpdates` | Check for available updates |
117
210
  | `analyzeSensors` | AI-powered sensor analysis using Ollama |
118
211
 
212
+ ### Calendar Tools
213
+
214
+ | Tool | Description |
215
+ |------|-------------|
216
+ | `listCalendars` | List all calendar entities |
217
+ | `getCalendarEvents` | Get events from one or all calendars |
218
+
119
219
  ### MCP Resources
120
220
 
121
221
  | Resource URI | Description |
@@ -128,108 +228,240 @@ See [docs/SSE_API.md](docs/SSE_API.md) for complete documentation of the SSE sys
128
228
 
129
229
  ## Prerequisites
130
230
 
131
- - **Node.js 20+** (tested with v20.19.6)
132
- - **npm 10.8+** (tested with v10.8.2)
231
+ - **Node.js 20+** (tested with v20.19.6) - for npm/npx methods
232
+ - **npm 10.8+** (tested with v10.8.2) - for npm/npx methods
233
+ - **Docker** (optional) - for Docker method
133
234
  - Home Assistant instance with long-lived access token
134
235
  - Network access to your Home Assistant instance
135
236
  - (Optional) Ollama for AI-powered analysis
136
- - (Optional) Docker for containerized deployment
137
-
138
- ## Configuration
139
237
 
140
- ### Getting Long-Lived Access Token
238
+ ## Getting Your Home Assistant Token
141
239
 
142
- 1. Log into your Home Assistant
240
+ 1. Log into your Home Assistant instance
143
241
  2. Click on your profile (bottom left)
144
242
  3. Scroll down to "Long-Lived Access Tokens"
145
243
  4. Click "Create Token"
146
244
  5. Give it a name (e.g., "MCP Server")
147
245
  6. Copy the token (shown only once!)
148
246
 
149
- ### Environment Variables
247
+ ## Environment Variables
248
+
249
+ ### Required
250
+
251
+ | Variable | Description | Example |
252
+ |----------|-------------|---------|
253
+ | `HA_URL` | Home Assistant URL | `http://homeassistant.10.0.0.19.nip.io:8123` |
254
+ | `HA_TOKEN` | Long-lived access token | `eyJhbGciOiJIUzI1NiIsInR5cCI...` |
255
+
256
+ ### Optional - Home Assistant
257
+
258
+ | Variable | Default | Description |
259
+ |----------|---------|-------------|
260
+ | `HA_STRICT_SSL` | `true` | Validate SSL certificates |
261
+ | `HA_TIMEOUT` | `30000` | API request timeout (ms) |
262
+
263
+ ### Optional - MCP Server
264
+
265
+ | Variable | Default | Description |
266
+ |----------|---------|-------------|
267
+ | `MCP_SERVER_LOG_LEVEL` | `info` | Log level: `debug`, `info`, `warn`, `error` |
268
+ | `MCP_SERVER_LOG_FORMAT` | `plain` | Log format: `plain`, `json`, `gcp-json` |
269
+ | `MCP_SERVER_USE_HTTP` | `false` | Enable HTTP mode (vs stdio) |
270
+ | `MCP_SERVER_STATEFUL` | `false` | Enable stateful sessions in HTTP mode |
271
+
272
+ ### Optional - HTTP Mode
273
+
274
+ | Variable | Default | Description |
275
+ |----------|---------|-------------|
276
+ | `MCP_HTTP_PORT` | `3000` | HTTP server port |
277
+ | `MCP_HTTP_TRANSPORT` | `stream` | Transport: `stream` or `sse` |
278
+ | `MCP_HTTP_BIND_ADDR` | `127.0.0.1` | Bind address |
279
+ | `MCP_HTTP_PATH` | `/mcp` | MCP endpoint path |
280
+ | `MCP_HTTP_ENABLE_HEALTHCHECK` | `true` | Enable health check endpoint |
281
+ | `MCP_HTTP_HEALTHCHECK_PATH` | `/health` | Health check path |
282
+ | `MCP_HTTP_ALLOW_CORS` | `true` | Enable CORS |
283
+ | `MCP_HTTP_ALLOWED_ORIGINS` | `127.0.0.1,localhost` | Allowed CORS origins |
284
+
285
+ ### Optional - SSE Events
286
+
287
+ | Variable | Default | Description |
288
+ |----------|---------|-------------|
289
+ | `MCP_SSE_EVENTS_ENABLED` | `false` | Enable real-time SSE events |
290
+ | `MCP_SSE_EVENTS_PATH` | `/subscribe_events` | SSE endpoint path |
291
+
292
+ ### Optional - Rate Limiting
293
+
294
+ | Variable | Default | Description |
295
+ |----------|---------|-------------|
296
+ | `MCP_RATE_LIMIT_ENABLED` | `false` | Enable rate limiting |
297
+ | `MCP_RATE_LIMIT_WINDOW_MS` | `60000` | Rate limit window (ms) |
298
+ | `MCP_RATE_LIMIT_MAX_REQUESTS` | `100` | Max requests per window |
299
+
300
+ ### Optional - Authentication
301
+
302
+ | Variable | Default | Description |
303
+ |----------|---------|-------------|
304
+ | `MCP_AUTH_METHOD` | `none` | Auth method: `none` or `bearer` |
305
+ | `MCP_AUTH_TOKEN` | - | Bearer token(s), can be comma-separated for multiple clients |
306
+
307
+ ### Optional - AI Provider
308
+
309
+ | Variable | Default | Description |
310
+ |----------|---------|-------------|
311
+ | `AI_PROVIDER` | `ollama` | AI provider: `ollama`, `openai`, or `none` |
312
+ | `AI_URL` | `http://ollama.10.0.0.17.nip.io:11434` | AI server URL (Ollama) |
313
+ | `AI_MODEL` | `llama2` | AI model name |
314
+ | `AI_TIMEOUT` | `60000` | AI request timeout (ms) |
315
+
316
+ ## Advanced Configuration Examples
317
+
318
+ ### With AI Analysis (Ollama)
319
+
320
+ ```json
321
+ {
322
+ "mcpServers": {
323
+ "homeassistant": {
324
+ "command": "npx",
325
+ "args": ["-y", "@coffeerunhobby/mcp-ha-connect"],
326
+ "env": {
327
+ "HA_URL": "http://homeassistant.10.0.0.19.nip.io:8123",
328
+ "HA_TOKEN": "your_token",
329
+ "AI_PROVIDER": "ollama",
330
+ "AI_URL": "http://ollama.10.0.0.17.nip.io:11434",
331
+ "AI_MODEL": "llama2"
332
+ }
333
+ }
334
+ }
335
+ }
336
+ ```
150
337
 
151
- Copy `.env.example` to `.env` and configure:
338
+ ### Disable AI Features
339
+
340
+ ```json
341
+ {
342
+ "mcpServers": {
343
+ "homeassistant": {
344
+ "command": "npx",
345
+ "args": ["-y", "@coffeerunhobby/mcp-ha-connect"],
346
+ "env": {
347
+ "HA_URL": "http://homeassistant.10.0.0.19.nip.io:8123",
348
+ "HA_TOKEN": "your_token",
349
+ "AI_PROVIDER": "none"
350
+ }
351
+ }
352
+ }
353
+ }
354
+ ```
152
355
 
153
- ```bash
154
- # Home Assistant Connection
155
- HA_URL=http://homeassistant.10.0.0.19.nip.io:8123
156
- HA_TOKEN=your_long_lived_access_token_here
157
- HA_STRICT_SSL=false
158
- HA_TIMEOUT=30000
159
-
160
- # MCP Server Configuration
161
- MCP_SERVER_LOG_LEVEL=info # debug, info, warn, error
162
- MCP_SERVER_LOG_FORMAT=plain # plain, json, gcp-json
163
- MCP_SERVER_USE_HTTP=false # true for HTTP mode, false for stdio
164
- MCP_SERVER_STATEFUL=false # Enable stateful sessions in HTTP mode
165
-
166
- # HTTP Configuration (when MCP_SERVER_USE_HTTP=true)
167
- MCP_HTTP_PORT=3000
168
- MCP_HTTP_TRANSPORT=stream # stream or sse
169
- MCP_HTTP_BIND_ADDR=127.0.0.1
170
- MCP_HTTP_PATH=/mcp # /mcp for stream, /sse for SSE
171
- MCP_HTTP_ENABLE_HEALTHCHECK=true
172
- MCP_HTTP_HEALTHCHECK_PATH=/health
173
- MCP_HTTP_ALLOW_CORS=true
174
- MCP_HTTP_ALLOWED_ORIGINS=127.0.0.1,localhost
175
-
176
- # SSE Event Subscription (real-time updates)
177
- MCP_SSE_EVENTS_ENABLED=true # Enable SSE event subscription
178
- MCP_SSE_EVENTS_PATH=/subscribe_events # SSE endpoint path
179
-
180
- # Rate Limiting
181
- MCP_RATE_LIMIT_ENABLED=true # Enable rate limiting
182
- MCP_RATE_LIMIT_WINDOW_MS=60000 # Time window in ms (default: 1 minute)
183
- MCP_RATE_LIMIT_MAX_REQUESTS=100 # Max requests per window
184
-
185
- # AI Configuration (optional)
186
- AI_PROVIDER=ollama # ollama or openai
187
- AI_URL=http://ollama.10.0.0.17.nip.io:11434
188
- AI_MODEL=phi4:14b
189
- AI_TIMEOUT=60000
356
+ ### Docker with Network Configuration
357
+
358
+ For Linux, you may need to add `host.docker.internal`:
359
+
360
+ ```json
361
+ {
362
+ "mcpServers": {
363
+ "homeassistant": {
364
+ "command": "docker",
365
+ "args": [
366
+ "run",
367
+ "--rm",
368
+ "-i",
369
+ "--add-host=host.docker.internal:host-gateway",
370
+ "-e", "HA_URL=http://host.docker.internal:8123",
371
+ "-e", "HA_TOKEN=your_token",
372
+ "ghcr.io/coffeerunhobby/mcp-ha-connect:latest"
373
+ ]
374
+ }
375
+ }
376
+ }
190
377
  ```
191
378
 
192
- ## Usage
379
+ ## Usage Modes
380
+
381
+ ### Mode 1: MCP Client (Claude Desktop / LM Studio)
193
382
 
194
- ### Mode 1: Claude Desktop (Stdio Transport)
383
+ Default stdio mode for MCP clients. See [Quick Start](#quick-start) section for configuration.
195
384
 
196
- [`docs/LOCAL_CLIENT.md`](docs/LOCAL_CLIENT.md)
385
+ For detailed configuration options, see [docs/LOCAL_CLIENT.md](docs/LOCAL_CLIENT.md).
197
386
 
198
387
  ### Mode 2: HTTP Server
199
388
 
389
+ Start as standalone HTTP server for web applications:
390
+
200
391
  ```bash
201
- # Start HTTP server
202
- MCP_SERVER_USE_HTTP=true npm start
392
+ # Using npx
393
+ npx @coffeerunhobby/mcp-ha-connect
394
+
395
+ # Or with environment variables
396
+ MCP_SERVER_USE_HTTP=true \
397
+ MCP_HTTP_PORT=3000 \
398
+ HA_URL=http://homeassistant.10.0.0.19.nip.io:8123 \
399
+ HA_TOKEN=your_token \
400
+ npx @coffeerunhobby/mcp-ha-connect
203
401
  ```
204
402
 
205
- #### Streamable HTTP Transport (Recommended)
403
+ #### Streamable HTTP Transport
206
404
 
207
405
  Configure your MCP client to use:
208
- - **URL:** `http://mcpserver.10.0.0.18.nip.io:3000/mcp`
406
+ - **URL:** `http://localhost:3000/mcp`
209
407
  - **Transport:** Streamable HTTP (MCP 2025-03-26)
210
408
 
211
409
  #### SSE Event Subscription
212
410
 
213
411
  Subscribe to real-time events:
214
- - **URL:** `http://mcpserver.10.0.0.18.nip.io:3000/subscribe_events`
215
- - **Method:** GET
216
- - **Query params:** `domain`, `entity_id`, `event_types`
217
412
 
218
- ### Mode 3: Docker
413
+ ```javascript
414
+ const eventSource = new EventSource(
415
+ 'http://localhost:3000/subscribe_events?domain=light&entity_id=light.living_room'
416
+ );
417
+
418
+ eventSource.addEventListener('state_changed', (event) => {
419
+ const data = JSON.parse(event.data);
420
+ console.log('Entity changed:', data.entity_id, data.new_state);
421
+ });
422
+ ```
423
+
424
+ See [docs/SSE_API.md](docs/SSE_API.md) for complete SSE documentation.
425
+
426
+ ### Mode 3: Docker Standalone
219
427
 
220
428
  ```bash
221
- # Build image
222
- docker build -t mcp-ha-connect .
429
+ # Pull image
430
+ docker pull ghcr.io/coffeerunhobby/mcp-ha-connect:latest
223
431
 
224
- # Run container
432
+ # Run in HTTP mode
225
433
  docker run -d --name mcp-ha-connect \
226
434
  -e HA_URL=http://homeassistant.10.0.0.19.nip.io:8123 \
227
435
  -e HA_TOKEN=your_token \
228
436
  -e MCP_SERVER_USE_HTTP=true \
229
437
  -p 3000:3000 \
230
- mcp-ha-connect
438
+ ghcr.io/coffeerunhobby/mcp-ha-connect:latest
231
439
  ```
232
440
 
441
+ ### Mode 4: Docker Compose
442
+
443
+ ```yaml
444
+ version: '3.8'
445
+
446
+ services:
447
+ mcp-ha-connect:
448
+ image: ghcr.io/coffeerunhobby/mcp-ha-connect:latest
449
+ container_name: mcp-ha-connect
450
+ restart: unless-stopped
451
+ ports:
452
+ - "3000:3000"
453
+ environment:
454
+ - HA_URL=http://homeassistant.10.0.0.19.nip.io:8123
455
+ - HA_TOKEN=${HA_TOKEN}
456
+ - MCP_SERVER_USE_HTTP=true
457
+ - MCP_HTTP_BIND_ADDR=0.0.0.0
458
+ networks:
459
+ - home-automation
460
+
461
+ networks:
462
+ home-automation:
463
+ driver: bridge
464
+ ```
233
465
 
234
466
  ## Integration Examples
235
467
 
@@ -278,56 +510,151 @@ docker exec -it n8n n8n list:workflow
278
510
 
279
511
  Use the HTTP transport with your MCP-compatible web client:
280
512
 
281
- 1. Configure client to use `http://mcpserver.10.0.0.18.nip.io:3000/mcp`
282
- 2. Set transport to Streamable HTTP (MCP 2025-03-26)
283
- 3. Enable CORS by adding your origin to `MCP_HTTP_ALLOWED_ORIGINS`
284
-
285
- ### With Stateful Sessions
286
-
287
- Enable session persistence:
288
-
289
- ```bash
290
- MCP_SERVER_STATEFUL=true
513
+ 1. Start server in HTTP mode
514
+ 2. Configure client to use `http://localhost:3000/mcp`
515
+ 3. Set transport to Streamable HTTP (MCP 2025-03-26)
516
+ 4. Enable CORS by adding your origin to `MCP_HTTP_ALLOWED_ORIGINS`
517
+
518
+ ### With Remote MCP Proxy (uvx)
519
+
520
+ Connect to a remote MCP server using mcp-remote:
521
+
522
+ ```json
523
+ {
524
+ "mcpServers": {
525
+ "homeassistant": {
526
+ "command": "uvx",
527
+ "args": [
528
+ "mcp-remote",
529
+ "http://your-server:3000/mcp"
530
+ ]
531
+ }
532
+ }
533
+ }
291
534
  ```
292
535
 
293
- Your MCP client should:
294
- 1. Include `Mcp-Session-Id` header in requests
295
- 2. Reuse the same session ID for related requests
296
- 3. Session state is maintained server-side
536
+ ## Network Configuration Notes
297
537
 
298
- Connect to SSE for real-time updates
538
+ - **`host.docker.internal`** - Use this to access services on your host machine from Docker
539
+ - Works on Windows and macOS by default
540
+ - On Linux, add `--add-host=host.docker.internal:host-gateway` to docker args
541
+ - **Direct IP** - Use your machine's IP address (e.g., `http://10.0.0.19:8123`)
542
+ - **nip.io domains** - Use wildcard DNS for easy local development (e.g., `http://homeassistant.10.0.0.19.nip.io:8123`)
299
543
 
300
- ```javascript
301
- const eventSource = new EventSource(
302
- 'http://mcpserver.10.0.0.18.nip.io:3000/subscribe_events?domain=light'
303
- );
304
-
305
- eventSource.addEventListener('state_changed', (event) => {
306
- const data = JSON.parse(event.data);
307
- updateUI(data.entity_id, data.new_state);
308
- });
309
- ```
310
-
311
- ## Security
544
+ ## Security Best Practices
312
545
 
313
546
  ### Network Security
314
547
 
315
- **Network Segmentation:**
316
- - Run MCP server on private LAN only (192.168.0.0/24)
317
- - Use Docker networks for container isolation
318
- - Consider VLAN for IoT devices
319
- - Never expose MCP server directly to internet
548
+ - **Network Segmentation**: Run MCP server on private LAN only
549
+ - **Docker Networks**: Use Docker networks for container isolation
550
+ - **VLAN**: Consider VLAN for IoT devices
551
+ - **No Internet Exposure**: Never expose MCP server directly to internet
320
552
 
321
- ### Best Practices
553
+ ### Token & Configuration Security
322
554
 
323
555
  - Store `.env` securely (contains access token)
324
- - Never commit `.env` to version control
556
+ - **Never** commit `.env` to version control
325
557
  - Set `.env` permissions: `chmod 600 .env`
326
558
  - Use `HA_STRICT_SSL=true` for HTTPS in production
327
559
  - Rotate access tokens periodically
328
- - Restrict `MCP_HTTP_ALLOWED_ORIGINS` (avoid wildcard)
560
+ - Restrict `MCP_HTTP_ALLOWED_ORIGINS` (avoid wildcard `*`)
329
561
  - Bind to `127.0.0.1` for local-only access
330
- - Enable rate limiting in production
562
+ - Enable rate limiting in production (`MCP_RATE_LIMIT_ENABLED=true`)
563
+
564
+ ### MCP Client Configuration Security
565
+
566
+ ⚠️ **Important:** Storing tokens directly in MCP client config files (Claude Desktop, LM Studio) exposes them to anyone with filesystem access. Consider:
567
+
568
+ - Using `.env` files with restricted permissions for Docker/local deployments
569
+ - Setting file permissions on config files (e.g., `chmod 600`)
570
+ - Using environment variable substitution if supported by your client
571
+ - Never committing config files with real tokens to version control
572
+
573
+ ## Troubleshooting
574
+
575
+ ### Claude Desktop / LM Studio Not Connecting
576
+
577
+ 1. **Check config file location** - Verify you're editing the correct file
578
+ 2. **Restart the application** - Close and reopen after config changes
579
+ 3. **Check logs** - Look for error messages in the application logs
580
+ 4. **Test connection manually**:
581
+
582
+ ```bash
583
+ # Test npx
584
+ npx @coffeerunhobby/mcp-ha-connect
585
+
586
+ # Test Docker
587
+ docker run --rm -i \
588
+ -e HA_URL=http://homeassistant.10.0.0.19.nip.io:8123 \
589
+ -e HA_TOKEN=your_token \
590
+ ghcr.io/coffeerunhobby/mcp-ha-connect:latest
591
+ ```
592
+
593
+ ### Docker `host.docker.internal` Not Working (Linux)
594
+
595
+ Add host gateway:
596
+
597
+ ```json
598
+ {
599
+ "args": [
600
+ "run",
601
+ "--rm",
602
+ "-i",
603
+ "--add-host=host.docker.internal:host-gateway",
604
+ "-e", "HA_URL=http://host.docker.internal:8123",
605
+ ...
606
+ ]
607
+ }
608
+ ```
609
+
610
+ ### Home Assistant Connection Issues
611
+
612
+ 1. **Verify URL** - Try accessing `http://your-ha-url:8123/api/` in browser
613
+ 2. **Check token** - Ensure it's a valid long-lived access token
614
+ 3. **Network access** - Verify MCP server can reach Home Assistant
615
+ 4. **SSL issues** - Try `HA_STRICT_SSL=false` for testing
616
+
617
+ ### AI Analysis Not Working
618
+
619
+ 1. **Verify Ollama is running** - `curl http://your-ollama-url:11434/api/tags`
620
+ 2. **Check model is available** - Ensure model is pulled: `ollama pull llama2`
621
+ 3. **Set AI_PROVIDER** - Must be set to `ollama` (not `none`)
622
+
623
+ ## Development
624
+
625
+ ### Setup
626
+
627
+ ```bash
628
+ # Clone repository
629
+ git clone https://github.com/coffeerunhobby/mcp-ha-connect.git
630
+ cd mcp-ha-connect
631
+
632
+ # Install dependencies
633
+ npm install
634
+
635
+ # Copy environment template
636
+ cp .env.example .env
637
+
638
+ # Edit .env with your Home Assistant details
639
+ nano .env
640
+
641
+ # Build
642
+ npm run build
643
+
644
+ # Run
645
+ npm start
646
+ ```
647
+
648
+ ### Available Scripts
649
+
650
+ ```bash
651
+ npm run build # Build TypeScript to dist/
652
+ npm run dev # Run in development mode with watch
653
+ npm start # Run built version
654
+ npm test # Run tests
655
+ npm run lint # Run ESLint
656
+ npm run format # Format code with Prettier
657
+ ```
331
658
 
332
659
  ## License
333
660
 
@@ -335,12 +662,24 @@ MIT
335
662
 
336
663
  ## Author
337
664
 
338
- Coffee Run Hobby (github.com/coffeerunhobby)
665
+ Coffee Run Hobby ([github.com/coffeerunhobby](https://github.com/coffeerunhobby))
339
666
 
340
667
  ## Version
341
668
 
342
- 0.6.0
669
+ 0.7.0
670
+
671
+ ## Links
672
+
673
+ - **GitHub**: [https://github.com/coffeerunhobby/mcp-ha-connect](https://github.com/coffeerunhobby/mcp-ha-connect)
674
+ - **npm**: [https://www.npmjs.com/package/@coffeerunhobby/mcp-ha-connect](https://www.npmjs.com/package/@coffeerunhobby/mcp-ha-connect)
675
+ - **Docker**: [https://github.com/coffeerunhobby/mcp-ha-connect/pkgs/container/mcp-ha-connect](https://github.com/coffeerunhobby/mcp-ha-connect/pkgs/container/mcp-ha-connect)
676
+
677
+ ## Documentation
678
+
679
+ - [Changelog](docs/CHANGELOG.md)
680
+ - [Local Client Configuration](docs/LOCAL_CLIENT.md)
681
+ - [SSE Event API](docs/SSE_API.md)
343
682
 
344
- ## Changelog
683
+ ## Contributing
345
684
 
346
- [`docs/CHANGELOG.md`](docs/CHANGELOG.md)
685
+ Contributions are welcome! Please feel free to submit a Pull Request.