advanced-homeassistant-mcp
Copilot instructions57 starsChanged 13 months agoApache-2.0View on GitHub
This document provides essential guidance for AI agents working on the homeassistant-mcp codebase. The project is a Model Context Protocol (MCP) server for Home Assistant. It has two primary modes of operation, determined by which entry point is used: The project has recently transitioned from Bun to esbuild and node. The package.json contains the most up-to-date commands. The project is written in TypeScript and must be compiled to CommonJS (.cjs) before running. This command compiles src/index.ts, src/stdio-server.ts, and src/http-server.ts into…
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this copilot-instructions.md into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 69
DO NOT: use .js extensions in import or export statements.
- Very specific: line 87
When catching errors, always check if the error is an instanceof Error before accessing properties like message.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AI Agent Instructions for homeassistant-mcp
This document provides essential guidance for AI agents working on the homeassistant-mcp codebase.
1. Architecture & Core Concepts
The project is a Model Context Protocol (MCP) server for Home Assistant. It has two primary modes of operation, determined by which entry point is used:
- Standalone HTTP/WebSocket Server (
src/index.ts): This is the main entry point. It creates an Express server that handles HTTP REST, WebSocket, and Server-Sent Events (SSE) transports. This is the mode for production deployments and general use. - STDIO Server (
src/stdio-server.ts): A lightweight, dependency-minimal server that communicates overstdin/stdout. This is used for integration with tools like the Smithery CLI and other local clients that manage the server as a child process.
Key Components:
src/index.ts: The main application entry point. It initializes the Express app, sets up middleware (security, logging), and instantiates theMCPServer.src/mcp/MCPServer.ts: The core of the application. It manages different transport layers (HTTP, WebSocket, STDIO), loads tools, and handles the MCP request/response lifecycle. It is designed to be transport-agnostic.src/mcp/transports/: Contains the logic for different communication protocols. Thehttp.transport.tsis crucial as it hooks into the main Express app created insrc/index.ts.src/tools/: This directory contains all the "tools" that the MCP server exposes. Each tool is a self-contained module that interacts with the Home Assistant API. Seesrc/tools/homeassistant/for examples.src/hass/: This directory contains the client for interacting with the Home Assistant WebSocket API. It's the primary way the server communicates with Home Assistant.
2. Developer Workflow & Commands
The project has recently transitioned from Bun to esbuild and node. The package.json contains the most up-to-date commands.
Building the Project
The project is written in TypeScript and must be compiled to CommonJS (.cjs) before running.
- Build everything:
This command compilesnpm run build:allsrc/index.ts,src/stdio-server.ts, andsrc/http-server.tsinto thedist/directory.
Running the Server
- Run the main HTTP/WebSocket server:
npm run start - Run the STDIO-only server:
npm run start:stdio
Testing
- Run all tests:
Note: The test runner is stillbun testbun testeven though the runtime is Node.
Smithery Integration
Smithery is used for deployment and local development testing.
- Run the server in a Smithery-like environment:
This is the most important command for debugging deployment issues. It simulates how the Smithery platform will run the STDIO server.npx @smithery/cli playground-stdio -- npm run start:stdio
3. Code Conventions & Patterns
Module System: CommonJS
The entire project is being converted from ESM to CommonJS (CJS) to ensure compatibility with the Smithery runtime.
- DO NOT use
.jsextensions inimportorexportstatements.// Correct import { MCPServer } from '../mcp/MCPServer'; // Incorrect import { MCPServer } from '../mcp/MCPServer.js'; - The build process (
esbuild) is configured to output.cjsfiles. Ensurepackage.jsonscripts reflect this.
Configuration
- Configuration is managed via environment variables, loaded by
dotenv. - The
src/config.tsfile is responsible for parsing and validating environment variables.
Error Handling
- The project uses
winstonfor logging. Use the logger fromsrc/utils/logger.tsinstead ofconsole.log. When catching errors, always check if the error is an
instanceof Errorbefore accessing properties likemessage.try { // ... } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); logger.error(`Something went wrong: ${errorMessage}`); }
4. Key Dependencies
express: The web server framework.fastmcp: Used instdio-server.tsandhttp-server.tsfor a lightweight MCP implementation. Note thatsrc/index.tsuses a custom, more complex MCP server implementation.esbuild: The build tool for compiling TypeScript to CommonJS.winston: The logging library.ws: The WebSocket client for connecting to Home Assistant.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

