agentleFS
jango-blockchainedjango-blockchained/advanced-homeassistant-mcp/.github/copilot-instructions.md

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.

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
  1. Very specific:

    DO NOT: use .js extensions in import or export statements.

    line 69
  2. Very specific:

    When catching errors, always check if the error is an instanceof Error before accessing properties like message.

    line 87

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

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:

  1. 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.
  2. STDIO Server (src/stdio-server.ts): A lightweight, dependency-minimal server that communicates over stdin/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 the MCPServer.
  • 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. The http.transport.ts is crucial as it hooks into the main Express app created in src/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. See src/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:
    npm run build:all
    This command compiles src/index.ts, src/stdio-server.ts, and src/http-server.ts into the dist/ 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:
    bun test
    Note: The test runner is still bun test even though the runtime is Node.

Smithery Integration

Smithery is used for deployment and local development testing.

  • Run the server in a Smithery-like environment:
    npx @smithery/cli playground-stdio -- npm run start:stdio
    This is the most important command for debugging deployment issues. It simulates how the Smithery platform will run the STDIO server.

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 .js extensions in import or export statements.
    // Correct
    import { MCPServer } from '../mcp/MCPServer';
    
    // Incorrect
    import { MCPServer } from '../mcp/MCPServer.js';
  • The build process (esbuild) is configured to output .cjs files. Ensure package.json scripts reflect this.

Configuration

  • Configuration is managed via environment variables, loaded by dotenv.
  • The src/config.ts file is responsible for parsing and validating environment variables.

Error Handling

  • The project uses winston for logging. Use the logger from src/utils/logger.ts instead of console.log.
  • When catching errors, always check if the error is an instanceof Error before accessing properties like message.

    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 in stdio-server.ts and http-server.ts for a lightweight MCP implementation. Note that src/index.ts uses 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.