Skip to main content
Glama
HA MCP Bridge

HA MCP Bridge

by shaike1
README.md
# 🏠 HA MCP Bridge

**Multi-tenant Home Assistant MCP Bridge** - Connect your Home Assistant smart home to Claude and ChatGPT via the Model Context Protocol (MCP).

[![Docker Build](https://github.com/shaike1/ha-mcp-bridge/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/shaike1/ha-mcp-bridge/actions/workflows/docker-publish.yml)
[![Node.js CI](https://github.com/shaike1/ha-mcp-bridge/actions/workflows/node-ci.yml/badge.svg)](https://github.com/shaike1/ha-mcp-bridge/actions/workflows/node-ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## ✨ Features

- 🔌 **Multi-tenant Support** - Multiple users can connect their own Home Assistant
- 🛡️ **Secure Authentication** - Individual API keys for each user
- 🎛️ **User Dashboard** - Web interface for account management
- 🚀 **Easy Deployment** - Docker support with Traefik integration
- 📊 **Usage Analytics** - Track requests and monitor usage
- 🔄 **Real-time Updates** - Live configuration changes
- 🌐 **Production Ready** - SSL, rate limiting, monitoring

## 🚀 Quick Start

### 1. Clone and Install
```bash
git clone https://github.com/shaike1/ha-mcp-bridge.git
cd ha-mcp-bridge
npm install
```

### 2. Setup Configuration
```bash
npm run setup
```

### 3. Start the Server
```bash
npm start
```

### 4. Access Dashboard
Visit `http://localhost:3001/dashboard` to register and manage your account.

## 📋 Prerequisites

- **Node.js** 16.0.0 or higher
- **Home Assistant** with Long-Lived Access Token
- **Claude Desktop** or **ChatGPT Desktop**

## 🔧 User Registration

### Via Dashboard
1. Visit `/dashboard`
2. Click "Register"
3. Enter email, HA URL, and token
4. Get your API key
5. Copy Claude Desktop configuration

### Via API
```bash
curl -X POST http://localhost:3001/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "haUrl": "http://homeassistant.local:8123",
    "haToken": "your_token_here"
  }'
```

## 🐳 Docker Deployment

### Simple Docker
```bash
docker-compose up -d
```

### Production with Traefik
```bash
# Create network
docker network create traefik-network

# Update domain in docker-compose.traefik.yml
# Deploy
docker-compose -f docker-compose.traefik.yml up -d
```

## 🎛️ User Dashboard Features

- **Account Management** - View and update settings
- **API Key Management** - Regenerate keys securely
- **HA Configuration** - Update Home Assistant settings
- **Connection Testing** - Verify HA connectivity
- **Usage Statistics** - Monitor API usage
- **Claude & ChatGPT Integration** - Ready-to-use configurations

## 🤖 ChatGPT Desktop Integration

ChatGPT Desktop supports MCP remote servers. Use either the dashboard snippet or the example config below.

Steps:

1. Start the server and register via `/dashboard` to get your API key.
2. In ChatGPT Desktop, open `Settings → Integrations → Model Context Protocol`.
3. Click `Add server` and paste this JSON (replace the URL if needed):

```json
{
  "mcpServers": {
    "homeassistant": {
      "type": "remote",
      "url": "https://your-server-url.com",
      "headers": { "Authorization": "Bearer YOUR_API_KEY" }
    }
  }
}
```

You can also find a ready-made example at `examples/chatgpt-desktop-config.json` and a copyable config in the dashboard after login.

## 🛡️ Security Features

- Individual API keys per user
- Encrypted data storage
- Rate limiting and CORS protection
- Admin interface for management
- Audit logging for all requests

## 👨‍💼 Admin Features

```bash
# View all users
curl -H "Authorization: Bearer $ADMIN_API_KEY" \
     http://localhost:3001/admin/users

# Delete user
curl -X DELETE \
     -H "Authorization: Bearer $ADMIN_API_KEY" \
     http://localhost:3001/admin/users/USER_API_KEY
```

## 🔧 Available Tools

- Core
  - **get_entities** — Get all entities or filter by domain
  - **call_service** — Call any HA service (domain/service)
- Lights & Switches
  - **get_lights** — List all light entities
  - **get_switches** — List all switch entities
- Automations & Scripts
  - **get_automations** — List automations
  - **get_scripts** — List scripts
  - **run_script** — Run a script (entity_id)
- Scenes
  - **get_scenes** — List scenes
  - **activate_scene** — Activate a scene (entity_id)
- Climate
  - **get_climate** — List climate entities
  - **set_climate** — Set temperature/hvac/preset/fan (entity_id, temperature, hvac_mode, preset_mode, fan_mode)
- Media Player
  - **get_media_players** — List media players
  - **media_play**, **media_pause**, **media_next**, **media_previous** — Control playback (entity_id)
  - **set_volume** — Set volume (entity_id, volume_level 0.0–1.0)
- Covers
  - **get_covers** — List covers (blinds, shades, garage doors)
  - **open_cover**, **close_cover**, **stop_cover** — Control movement (entity_id)
  - **set_cover_position** — Set position 0–100 (entity_id, position)

## 📊 Monitoring

- Health endpoint: `/health`
- User dashboard: `/dashboard`
- Admin interface: `/admin/users`
- Docker health checks included

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

## 📝 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🆘 Support

- 📖 [Documentation](docs/)
- 🐛 [Report Issues](https://github.com/shaike1/ha-mcp-bridge/issues)
- 💬 [Discussions](https://github.com/shaike1/ha-mcp-bridge/discussions)

## ⭐ Acknowledgments

- [Home Assistant](https://www.home-assistant.io/) for the amazing platform
- [Anthropic](https://www.anthropic.com/) for Claude and MCP
- The open-source community for inspiration

---

**Made with ❤️ for the smart home community**