Home Assistant MCP server

Demonstrates light control in Home Assistant by comparing OpenAI function calling with a standardized protocol for external tool interaction
Back to servers
Setup instructions
Provider
Andre Landgraf
Release date
Mar 06, 2025
Language
TypeScript
Stats
8 stars

This server implements the Model Context Protocol (MCP) to provide a standardized interface for controlling Home Assistant lights. Unlike function calling that runs in your LLM application code, this MCP server works as a standalone service that any MCP-compatible LLM can connect to and use.

Installation

To set up the MCP server for controlling Home Assistant lights:

  1. Clone the repository and navigate to the MCP server directory
  2. Create an environment file by copying the example:
cp mcp-server/.env.example mcp-server/.env
  1. Edit the .env file to add your Home Assistant API token:
HOME_ASSISTANT_API_TOKEN=<your-home-assistant-api-token>
  1. Install dependencies and build the server:
bun i
bun run build

Configuring Your LLM

After installation, you need to configure your LLM application to use the MCP server:

For Cursor

Add the following configuration to your Cursor settings:

{
  "name": "home-assistant",
  "command": "node /path/to/mcp-server/dist/index.js"
}

Replace /path/to/mcp-server with the actual path to your installation.

Usage

Once configured, your LLM application can communicate with the MCP server to control your Home Assistant lights. The server exposes a control_lights function that allows you to:

  • Turn lights on or off
  • Control brightness
  • Change light colors
  • Group multiple lights

Example Commands

You can prompt your LLM with natural language requests such as:

  • "Turn on the lights in my office"
  • "Set the living room lights to 50% brightness"
  • "Change the bedroom lights to a warm color"

The MCP server handles the communication with Home Assistant behind the scenes, executing your commands through the Home Assistant WebSocket API.

Troubleshooting

If you encounter issues:

  • Verify your Home Assistant API token is correct
  • Ensure Home Assistant is running and accessible
  • Check that the MCP server built correctly
  • Confirm your LLM application is properly configured to use the MCP server

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "home-assistant" '{"command":"node","args":["/Users/andrelandgraf/workspaces/mcps/mcp-server/dist/index.js"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "home-assistant": {
            "command": "node",
            "args": [
                "/Users/andrelandgraf/workspaces/mcps/mcp-server/dist/index.js"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "home-assistant": {
            "command": "node",
            "args": [
                "/Users/andrelandgraf/workspaces/mcps/mcp-server/dist/index.js"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later