@coffeerunhobby/mcp-ha-connect 0.6.0 → 0.7.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 (100) hide show
  1. package/README.md +437 -105
  2. package/dist/haClient/calendars.d.ts +33 -0
  3. package/dist/haClient/calendars.js +68 -0
  4. package/dist/haClient/calendars.js.map +1 -0
  5. package/dist/haClient/index.d.ts +18 -1
  6. package/dist/haClient/index.js +23 -0
  7. package/dist/haClient/index.js.map +1 -1
  8. package/dist/haClient/labels.d.ts +64 -0
  9. package/dist/haClient/labels.js +177 -0
  10. package/dist/haClient/labels.js.map +1 -0
  11. package/dist/tools/calendar.d.ts +7 -0
  12. package/dist/tools/calendar.js +82 -0
  13. package/dist/tools/calendar.js.map +1 -0
  14. package/dist/tools/common.d.ts +17 -0
  15. package/dist/tools/common.js +9 -0
  16. package/dist/tools/common.js.map +1 -1
  17. package/dist/tools/index.js +24 -7
  18. package/dist/tools/index.js.map +1 -1
  19. package/dist/tools/labels.d.ts +12 -0
  20. package/dist/tools/labels.js +139 -0
  21. package/dist/tools/labels.js.map +1 -0
  22. package/dist/tools/listPersons.d.ts +6 -0
  23. package/dist/tools/listPersons.js +36 -0
  24. package/dist/tools/listPersons.js.map +1 -0
  25. package/dist/tools/searchEntities.js +3 -1
  26. package/dist/tools/searchEntities.js.map +1 -1
  27. package/dist/types/automations.d.ts +38 -0
  28. package/dist/types/automations.js +5 -0
  29. package/dist/types/automations.js.map +1 -0
  30. package/dist/types/calendars.d.ts +24 -0
  31. package/dist/types/calendars.js +5 -0
  32. package/dist/types/calendars.js.map +1 -0
  33. package/dist/types/config.d.ts +10 -0
  34. package/dist/types/config.js +5 -0
  35. package/dist/types/config.js.map +1 -0
  36. package/dist/types/entities.d.ts +13 -0
  37. package/dist/types/entities.js +5 -0
  38. package/dist/types/entities.js.map +1 -0
  39. package/dist/types/entity.d.ts +21 -0
  40. package/dist/types/history.d.ts +12 -0
  41. package/dist/types/history.js +5 -0
  42. package/dist/types/history.js.map +1 -0
  43. package/dist/types/index.d.ts +7 -1
  44. package/dist/types/index.js +1 -0
  45. package/dist/types/index.js.map +1 -1
  46. package/dist/types/labels.d.ts +34 -0
  47. package/dist/types/labels.js +5 -0
  48. package/dist/types/labels.js.map +1 -0
  49. package/dist/types/states.d.ts +19 -0
  50. package/dist/types/states.js +5 -0
  51. package/dist/types/states.js.map +1 -0
  52. package/dist/types/updates.d.ts +24 -0
  53. package/dist/types/updates.js +5 -0
  54. package/dist/types/updates.js.map +1 -0
  55. package/docs/CHANGELOG.md +114 -104
  56. package/docs/LOCAL_CLIENT.md +572 -338
  57. package/openapi.json +1149 -37
  58. package/package.json +4 -3
  59. package/src/haClient/calendars.ts +94 -0
  60. package/src/haClient/index.ts +36 -0
  61. package/src/tools/calendar.ts +97 -0
  62. package/src/tools/common.ts +11 -0
  63. package/src/tools/index.ts +28 -7
  64. package/src/tools/listPersons.ts +46 -0
  65. package/src/tools/searchEntities.ts +3 -1
  66. package/src/types/automations.ts +43 -0
  67. package/src/types/calendars.ts +26 -0
  68. package/src/types/config.ts +11 -0
  69. package/src/types/entities.ts +14 -0
  70. package/src/types/history.ts +13 -0
  71. package/src/types/index.ts +37 -1
  72. package/src/types/states.ts +21 -0
  73. package/src/types/updates.ts +28 -0
  74. package/tests/bdd/automation-creation.spec.ts +214 -0
  75. package/tests/bdd/automation-management.spec.ts +267 -0
  76. package/tests/bdd/calendar.spec.ts +190 -0
  77. package/tests/bdd/configuration.spec.ts +283 -0
  78. package/tests/bdd/device-control.spec.ts +344 -0
  79. package/tests/bdd/entity-listing.spec.ts +208 -0
  80. package/tests/bdd/entity-search.spec.ts +183 -0
  81. package/tests/bdd/history-retrieval.spec.ts +195 -0
  82. package/tests/bdd/notifications.spec.ts +238 -0
  83. package/tests/bdd/service-calls.spec.ts +144 -0
  84. package/tests/bdd/state-retrieval.spec.ts +204 -0
  85. package/tests/features/automation-creation.feature +36 -0
  86. package/tests/features/automation-management.feature +54 -0
  87. package/tests/features/calendar.feature +37 -0
  88. package/tests/features/configuration.feature +71 -0
  89. package/tests/features/device-control.feature +100 -0
  90. package/tests/features/entity-listing.feature +51 -0
  91. package/tests/features/entity-search.feature +44 -0
  92. package/tests/features/history-retrieval.feature +38 -0
  93. package/tests/features/notifications.feature +37 -0
  94. package/tests/features/service-calls.feature +35 -0
  95. package/tests/features/state-retrieval.feature +37 -0
  96. package/tests/haClient/index.test.ts +142 -110
  97. package/tests/localAI/index.test.ts +27 -18
  98. package/tests/server/stdio.test.ts +4 -6
  99. package/vitest.config.ts +1 -1
  100. package/src/types/entity.ts +0 -111
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,233 @@ 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 - AI Provider
301
+
302
+ | Variable | Default | Description |
303
+ |----------|---------|-------------|
304
+ | `AI_PROVIDER` | `ollama` | AI provider: `ollama`, `openai`, or `none` |
305
+ | `AI_URL` | `http://ollama.10.0.0.17.nip.io:11434` | AI server URL (Ollama) |
306
+ | `AI_MODEL` | `llama2` | AI model name |
307
+ | `AI_TIMEOUT` | `60000` | AI request timeout (ms) |
308
+
309
+ ## Advanced Configuration Examples
310
+
311
+ ### With AI Analysis (Ollama)
312
+
313
+ ```json
314
+ {
315
+ "mcpServers": {
316
+ "homeassistant": {
317
+ "command": "npx",
318
+ "args": ["-y", "@coffeerunhobby/mcp-ha-connect"],
319
+ "env": {
320
+ "HA_URL": "http://homeassistant.10.0.0.19.nip.io:8123",
321
+ "HA_TOKEN": "your_token",
322
+ "AI_PROVIDER": "ollama",
323
+ "AI_URL": "http://ollama.10.0.0.17.nip.io:11434",
324
+ "AI_MODEL": "llama2"
325
+ }
326
+ }
327
+ }
328
+ }
329
+ ```
150
330
 
151
- Copy `.env.example` to `.env` and configure:
331
+ ### Disable AI Features
332
+
333
+ ```json
334
+ {
335
+ "mcpServers": {
336
+ "homeassistant": {
337
+ "command": "npx",
338
+ "args": ["-y", "@coffeerunhobby/mcp-ha-connect"],
339
+ "env": {
340
+ "HA_URL": "http://homeassistant.10.0.0.19.nip.io:8123",
341
+ "HA_TOKEN": "your_token",
342
+ "AI_PROVIDER": "none"
343
+ }
344
+ }
345
+ }
346
+ }
347
+ ```
152
348
 
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
349
+ ### Docker with Network Configuration
350
+
351
+ For Linux, you may need to add `host.docker.internal`:
352
+
353
+ ```json
354
+ {
355
+ "mcpServers": {
356
+ "homeassistant": {
357
+ "command": "docker",
358
+ "args": [
359
+ "run",
360
+ "--rm",
361
+ "-i",
362
+ "--add-host=host.docker.internal:host-gateway",
363
+ "-e", "HA_URL=http://host.docker.internal:8123",
364
+ "-e", "HA_TOKEN=your_token",
365
+ "ghcr.io/coffeerunhobby/mcp-ha-connect:latest"
366
+ ]
367
+ }
368
+ }
369
+ }
190
370
  ```
191
371
 
192
- ## Usage
372
+ ## Usage Modes
373
+
374
+ ### Mode 1: MCP Client (Claude Desktop / LM Studio)
193
375
 
194
- ### Mode 1: Claude Desktop (Stdio Transport)
376
+ Default stdio mode for MCP clients. See [Quick Start](#quick-start) section for configuration.
195
377
 
196
- [`docs/LOCAL_CLIENT.md`](docs/LOCAL_CLIENT.md)
378
+ For detailed configuration options, see [docs/LOCAL_CLIENT.md](docs/LOCAL_CLIENT.md).
197
379
 
198
380
  ### Mode 2: HTTP Server
199
381
 
382
+ Start as standalone HTTP server for web applications:
383
+
200
384
  ```bash
201
- # Start HTTP server
202
- MCP_SERVER_USE_HTTP=true npm start
385
+ # Using npx
386
+ npx @coffeerunhobby/mcp-ha-connect
387
+
388
+ # Or with environment variables
389
+ MCP_SERVER_USE_HTTP=true \
390
+ MCP_HTTP_PORT=3000 \
391
+ HA_URL=http://homeassistant.10.0.0.19.nip.io:8123 \
392
+ HA_TOKEN=your_token \
393
+ npx @coffeerunhobby/mcp-ha-connect
203
394
  ```
204
395
 
205
- #### Streamable HTTP Transport (Recommended)
396
+ #### Streamable HTTP Transport
206
397
 
207
398
  Configure your MCP client to use:
208
- - **URL:** `http://mcpserver.10.0.0.18.nip.io:3000/mcp`
399
+ - **URL:** `http://localhost:3000/mcp`
209
400
  - **Transport:** Streamable HTTP (MCP 2025-03-26)
210
401
 
211
402
  #### SSE Event Subscription
212
403
 
213
404
  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
405
 
218
- ### Mode 3: Docker
406
+ ```javascript
407
+ const eventSource = new EventSource(
408
+ 'http://localhost:3000/subscribe_events?domain=light&entity_id=light.living_room'
409
+ );
410
+
411
+ eventSource.addEventListener('state_changed', (event) => {
412
+ const data = JSON.parse(event.data);
413
+ console.log('Entity changed:', data.entity_id, data.new_state);
414
+ });
415
+ ```
416
+
417
+ See [docs/SSE_API.md](docs/SSE_API.md) for complete SSE documentation.
418
+
419
+ ### Mode 3: Docker Standalone
219
420
 
220
421
  ```bash
221
- # Build image
222
- docker build -t mcp-ha-connect .
422
+ # Pull image
423
+ docker pull ghcr.io/coffeerunhobby/mcp-ha-connect:latest
223
424
 
224
- # Run container
425
+ # Run in HTTP mode
225
426
  docker run -d --name mcp-ha-connect \
226
427
  -e HA_URL=http://homeassistant.10.0.0.19.nip.io:8123 \
227
428
  -e HA_TOKEN=your_token \
228
429
  -e MCP_SERVER_USE_HTTP=true \
229
430
  -p 3000:3000 \
230
- mcp-ha-connect
431
+ ghcr.io/coffeerunhobby/mcp-ha-connect:latest
231
432
  ```
232
433
 
434
+ ### Mode 4: Docker Compose
435
+
436
+ ```yaml
437
+ version: '3.8'
438
+
439
+ services:
440
+ mcp-ha-connect:
441
+ image: ghcr.io/coffeerunhobby/mcp-ha-connect:latest
442
+ container_name: mcp-ha-connect
443
+ restart: unless-stopped
444
+ ports:
445
+ - "3000:3000"
446
+ environment:
447
+ - HA_URL=http://homeassistant.10.0.0.19.nip.io:8123
448
+ - HA_TOKEN=${HA_TOKEN}
449
+ - MCP_SERVER_USE_HTTP=true
450
+ - MCP_HTTP_BIND_ADDR=0.0.0.0
451
+ networks:
452
+ - home-automation
453
+
454
+ networks:
455
+ home-automation:
456
+ driver: bridge
457
+ ```
233
458
 
234
459
  ## Integration Examples
235
460
 
@@ -278,56 +503,151 @@ docker exec -it n8n n8n list:workflow
278
503
 
279
504
  Use the HTTP transport with your MCP-compatible web client:
280
505
 
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
506
+ 1. Start server in HTTP mode
507
+ 2. Configure client to use `http://localhost:3000/mcp`
508
+ 3. Set transport to Streamable HTTP (MCP 2025-03-26)
509
+ 4. Enable CORS by adding your origin to `MCP_HTTP_ALLOWED_ORIGINS`
510
+
511
+ ### With Remote MCP Proxy (uvx)
512
+
513
+ Connect to a remote MCP server using mcp-remote:
514
+
515
+ ```json
516
+ {
517
+ "mcpServers": {
518
+ "homeassistant": {
519
+ "command": "uvx",
520
+ "args": [
521
+ "mcp-remote",
522
+ "http://your-server:3000/mcp"
523
+ ]
524
+ }
525
+ }
526
+ }
291
527
  ```
292
528
 
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
529
+ ## Network Configuration Notes
297
530
 
298
- Connect to SSE for real-time updates
531
+ - **`host.docker.internal`** - Use this to access services on your host machine from Docker
532
+ - Works on Windows and macOS by default
533
+ - On Linux, add `--add-host=host.docker.internal:host-gateway` to docker args
534
+ - **Direct IP** - Use your machine's IP address (e.g., `http://10.0.0.19:8123`)
535
+ - **nip.io domains** - Use wildcard DNS for easy local development (e.g., `http://homeassistant.10.0.0.19.nip.io:8123`)
299
536
 
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
537
+ ## Security Best Practices
312
538
 
313
539
  ### Network Security
314
540
 
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
541
+ - **Network Segmentation**: Run MCP server on private LAN only
542
+ - **Docker Networks**: Use Docker networks for container isolation
543
+ - **VLAN**: Consider VLAN for IoT devices
544
+ - **No Internet Exposure**: Never expose MCP server directly to internet
320
545
 
321
- ### Best Practices
546
+ ### Token & Configuration Security
322
547
 
323
548
  - Store `.env` securely (contains access token)
324
- - Never commit `.env` to version control
549
+ - **Never** commit `.env` to version control
325
550
  - Set `.env` permissions: `chmod 600 .env`
326
551
  - Use `HA_STRICT_SSL=true` for HTTPS in production
327
552
  - Rotate access tokens periodically
328
- - Restrict `MCP_HTTP_ALLOWED_ORIGINS` (avoid wildcard)
553
+ - Restrict `MCP_HTTP_ALLOWED_ORIGINS` (avoid wildcard `*`)
329
554
  - Bind to `127.0.0.1` for local-only access
330
- - Enable rate limiting in production
555
+ - Enable rate limiting in production (`MCP_RATE_LIMIT_ENABLED=true`)
556
+
557
+ ### MCP Client Configuration Security
558
+
559
+ ⚠️ **Important:** Storing tokens directly in MCP client config files (Claude Desktop, LM Studio) exposes them to anyone with filesystem access. Consider:
560
+
561
+ - Using `.env` files with restricted permissions for Docker/local deployments
562
+ - Setting file permissions on config files (e.g., `chmod 600`)
563
+ - Using environment variable substitution if supported by your client
564
+ - Never committing config files with real tokens to version control
565
+
566
+ ## Troubleshooting
567
+
568
+ ### Claude Desktop / LM Studio Not Connecting
569
+
570
+ 1. **Check config file location** - Verify you're editing the correct file
571
+ 2. **Restart the application** - Close and reopen after config changes
572
+ 3. **Check logs** - Look for error messages in the application logs
573
+ 4. **Test connection manually**:
574
+
575
+ ```bash
576
+ # Test npx
577
+ npx @coffeerunhobby/mcp-ha-connect
578
+
579
+ # Test Docker
580
+ docker run --rm -i \
581
+ -e HA_URL=http://homeassistant.10.0.0.19.nip.io:8123 \
582
+ -e HA_TOKEN=your_token \
583
+ ghcr.io/coffeerunhobby/mcp-ha-connect:latest
584
+ ```
585
+
586
+ ### Docker `host.docker.internal` Not Working (Linux)
587
+
588
+ Add host gateway:
589
+
590
+ ```json
591
+ {
592
+ "args": [
593
+ "run",
594
+ "--rm",
595
+ "-i",
596
+ "--add-host=host.docker.internal:host-gateway",
597
+ "-e", "HA_URL=http://host.docker.internal:8123",
598
+ ...
599
+ ]
600
+ }
601
+ ```
602
+
603
+ ### Home Assistant Connection Issues
604
+
605
+ 1. **Verify URL** - Try accessing `http://your-ha-url:8123/api/` in browser
606
+ 2. **Check token** - Ensure it's a valid long-lived access token
607
+ 3. **Network access** - Verify MCP server can reach Home Assistant
608
+ 4. **SSL issues** - Try `HA_STRICT_SSL=false` for testing
609
+
610
+ ### AI Analysis Not Working
611
+
612
+ 1. **Verify Ollama is running** - `curl http://your-ollama-url:11434/api/tags`
613
+ 2. **Check model is available** - Ensure model is pulled: `ollama pull llama2`
614
+ 3. **Set AI_PROVIDER** - Must be set to `ollama` (not `none`)
615
+
616
+ ## Development
617
+
618
+ ### Setup
619
+
620
+ ```bash
621
+ # Clone repository
622
+ git clone https://github.com/coffeerunhobby/mcp-ha-connect.git
623
+ cd mcp-ha-connect
624
+
625
+ # Install dependencies
626
+ npm install
627
+
628
+ # Copy environment template
629
+ cp .env.example .env
630
+
631
+ # Edit .env with your Home Assistant details
632
+ nano .env
633
+
634
+ # Build
635
+ npm run build
636
+
637
+ # Run
638
+ npm start
639
+ ```
640
+
641
+ ### Available Scripts
642
+
643
+ ```bash
644
+ npm run build # Build TypeScript to dist/
645
+ npm run dev # Run in development mode with watch
646
+ npm start # Run built version
647
+ npm test # Run tests
648
+ npm run lint # Run ESLint
649
+ npm run format # Format code with Prettier
650
+ ```
331
651
 
332
652
  ## License
333
653
 
@@ -335,12 +655,24 @@ MIT
335
655
 
336
656
  ## Author
337
657
 
338
- Coffee Run Hobby (github.com/coffeerunhobby)
658
+ Coffee Run Hobby ([github.com/coffeerunhobby](https://github.com/coffeerunhobby))
339
659
 
340
660
  ## Version
341
661
 
342
- 0.6.0
662
+ 0.7.0
663
+
664
+ ## Links
665
+
666
+ - **GitHub**: [https://github.com/coffeerunhobby/mcp-ha-connect](https://github.com/coffeerunhobby/mcp-ha-connect)
667
+ - **npm**: [https://www.npmjs.com/package/@coffeerunhobby/mcp-ha-connect](https://www.npmjs.com/package/@coffeerunhobby/mcp-ha-connect)
668
+ - **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)
669
+
670
+ ## Documentation
671
+
672
+ - [Changelog](docs/CHANGELOG.md)
673
+ - [Local Client Configuration](docs/LOCAL_CLIENT.md)
674
+ - [SSE Event API](docs/SSE_API.md)
343
675
 
344
- ## Changelog
676
+ ## Contributing
345
677
 
346
- [`docs/CHANGELOG.md`](docs/CHANGELOG.md)
678
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Calendar Operations for Home Assistant API
3
+ * Handles calendar listing and event retrieval
4
+ */
5
+ import type { CalendarEvent, Calendar } from '../types/index.js';
6
+ import type { RequestHandler } from './request.js';
7
+ /**
8
+ * Calendar-related operations for the Home Assistant API.
9
+ */
10
+ export declare class CalendarOperations {
11
+ private readonly request;
12
+ constructor(request: RequestHandler);
13
+ /**
14
+ * Get all calendar entities
15
+ */
16
+ getCalendars(): Promise<Calendar[]>;
17
+ /**
18
+ * Get events from a calendar
19
+ * @param entityId - Calendar entity ID (e.g., 'calendar.my_calendar')
20
+ * @param startDate - Start date for event range (defaults to now)
21
+ * @param endDate - End date for event range (defaults to 30 days from start)
22
+ */
23
+ getCalendarEvents(entityId: string, startDate?: Date, endDate?: Date): Promise<CalendarEvent[]>;
24
+ /**
25
+ * Get events from all calendars
26
+ * @param startDate - Start date for event range (defaults to now)
27
+ * @param endDate - End date for event range (defaults to 30 days from start)
28
+ */
29
+ getAllCalendarEvents(startDate?: Date, endDate?: Date): Promise<Array<{
30
+ calendar: string;
31
+ events: CalendarEvent[];
32
+ }>>;
33
+ }