Skip to main content
Glama
hekmon8

Home Assistant MCP Server

by hekmon8

toggle_entity

Switch Home Assistant devices on or off by specifying the entity ID and desired state to control smart home automation.

Instructions

Toggle a Home Assistant entity on/off

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_idYesThe entity ID to toggle (e.g., switch.bedroom)
stateYesThe desired state (on/off)

Implementation Reference

  • The main handler function that implements the toggle_entity tool logic by validating inputs and calling the Home Assistant API to turn the entity on or off.
    private async toggleEntity(args: any) {
      if (!args.entity_id || !args.state) {
        throw new McpError(ErrorCode.InvalidParams, 'entity_id and state are required');
      }
    
      const response = await this.haClient.post('/api/services/homeassistant/turn_' + args.state, {
        entity_id: args.entity_id,
      });
    
      return {
        content: [
          {
            type: 'text',
            text: `Successfully turned ${args.state} ${args.entity_id}`,
          },
        ],
      };
    }
  • Input schema defining the parameters for the toggle_entity tool: entity_id (required string) and state (required string enum ['on','off']).
    inputSchema: {
      type: 'object',
      properties: {
        entity_id: {
          type: 'string',
          description: 'The entity ID to toggle (e.g., switch.bedroom)',
        },
        state: {
          type: 'string',
          description: 'The desired state (on/off)',
          enum: ['on', 'off'],
        },
      },
      required: ['entity_id', 'state'],
    },
  • src/index.ts:70-88 (registration)
    Registration of the toggle_entity tool in the ListTools response, including name, description, and input schema.
    {
      name: 'toggle_entity',
      description: 'Toggle a Home Assistant entity on/off',
      inputSchema: {
        type: 'object',
        properties: {
          entity_id: {
            type: 'string',
            description: 'The entity ID to toggle (e.g., switch.bedroom)',
          },
          state: {
            type: 'string',
            description: 'The desired state (on/off)',
            enum: ['on', 'off'],
          },
        },
        required: ['entity_id', 'state'],
      },
    },
  • Switch case in the CallToolRequest handler that dispatches toggle_entity requests to the toggleEntity method.
    case 'toggle_entity':
      return await this.toggleEntity(request.params.arguments);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits such as required permissions, whether this is a destructive/mutative operation (implied but not explicit), error handling, or side effects (e.g., triggering automations).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste, front-loading the core action. It's appropriately sized for a simple toggle operation with well-documented parameters.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a mutative tool. It lacks context on permissions, error responses, or what happens post-toggle (e.g., state change confirmation), leaving gaps for agent usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents both parameters (entity_id with examples, state with enum). The description adds no additional meaning beyond implying the tool uses these parameters, meeting the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('toggle') and resource ('a Home Assistant entity'), specifying the action of switching between on/off states. It distinguishes from siblings like 'get_state' (read-only) and 'list_entities' (listing), but doesn't explicitly differentiate from 'trigger_automation' (which might involve entities).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., entity must be toggleable), exclusions (e.g., not for sensors), or compare to siblings like 'get_state' for checking current state before toggling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hekmon8/Homeassistant-server-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server