Skip to main content
Glama

list_entities

Retrieve and filter Home Assistant entities by domain, search query, or specific fields to manage smart home devices and sensors.

Instructions

Get a list of Home Assistant entities with optional filtering

Args: domain: Optional domain to filter by (e.g., 'light', 'switch', 'sensor') search_query: Optional search term to filter entities by name, id, or attributes (Note: Does not support wildcards. To get all entities, leave this empty) limit: Maximum number of entities to return (default: 100) fields: Optional list of specific fields to include in each entity detailed: If True, returns all entity fields without filtering

Returns: A list of entity dictionaries with lean formatting by default

Examples: domain="light" - get all lights search_query="kitchen", limit=20 - search entities domain="sensor", detailed=True - full sensor details

Best Practices: - Use lean format (default) for most operations - Prefer domain filtering over no filtering - For domain overviews, use domain_summary_tool instead of list_entities - Only request detailed=True when necessary for full attribute inspection - To get all entity types/domains, use list_entities without a domain filter, then extract domains from entity_ids

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
domainNo
search_queryNo
limitNo
fieldsNo
detailedNo

Implementation Reference

  • Primary handler for the 'list_entities' MCP tool. Registered with @mcp.tool(). Handles input parameters, logging, special '*' handling, and delegates core logic to get_entities helper with lean/detailed formatting.
    @mcp.tool()
    @async_handler("list_entities")
    async def list_entities(
        domain: Optional[str] = None, 
        search_query: Optional[str] = None, 
        limit: int = 100,
        fields: Optional[List[str]] = None,
        detailed: bool = False
    ) -> List[Dict[str, Any]]:
        """
        Get a list of Home Assistant entities with optional filtering
        
        Args:
            domain: Optional domain to filter by (e.g., 'light', 'switch', 'sensor')
            search_query: Optional search term to filter entities by name, id, or attributes
                         (Note: Does not support wildcards. To get all entities, leave this empty)
            limit: Maximum number of entities to return (default: 100)
            fields: Optional list of specific fields to include in each entity
            detailed: If True, returns all entity fields without filtering
        
        Returns:
            A list of entity dictionaries with lean formatting by default
        
        Examples:
            domain="light" - get all lights
            search_query="kitchen", limit=20 - search entities
            domain="sensor", detailed=True - full sensor details
        
        Best Practices:
            - Use lean format (default) for most operations
            - Prefer domain filtering over no filtering
            - For domain overviews, use domain_summary_tool instead of list_entities
            - Only request detailed=True when necessary for full attribute inspection
            - To get all entity types/domains, use list_entities without a domain filter, 
              then extract domains from entity_ids
        """
        log_message = "Getting entities"
        if domain:
            log_message += f" for domain: {domain}"
        if search_query:
            log_message += f" matching: '{search_query}'"
        if limit != 100:
            log_message += f" (limit: {limit})"
        if detailed:
            log_message += " (detailed format)"
        elif fields:
            log_message += f" (custom fields: {fields})"
        else:
            log_message += " (lean format)"
        
        logger.info(log_message)
        
        # Handle special case where search_query is a wildcard/asterisk - just ignore it
        if search_query == "*":
            search_query = None
            logger.info("Converting '*' search query to None (retrieving all entities)")
        
        # Use the updated get_entities function with field filtering
        return await get_entities(
            domain=domain, 
            search_query=search_query, 
            limit=limit,
            fields=fields,
            lean=not detailed  # Use lean format unless detailed is requested
        )
  • Core helper function implementing entity listing logic: fetches /api/states, filters by domain/search/limit, applies lean field selection with domain-specific attributes or custom fields.
    async def get_entities(
        domain: Optional[str] = None, 
        search_query: Optional[str] = None, 
        limit: int = 100,
        fields: Optional[List[str]] = None,
        lean: bool = True
    ) -> List[Dict[str, Any]]:
        """
        Get a list of all entities from Home Assistant with optional filtering and search
        
        Args:
            domain: Optional domain to filter entities by (e.g., 'light', 'switch')
            search_query: Optional case-insensitive search term to filter by entity_id, friendly_name or other attributes
            limit: Maximum number of entities to return (default: 100)
            fields: Optional list of specific fields to include in each entity
            lean: If True (default), returns token-efficient versions with minimal fields
        
        Returns:
            List of entity dictionaries, optionally filtered by domain and search terms,
            and optionally limited to specific fields
        """
        # Get all entities directly
        client = await get_client()
        response = await client.get(f"{HA_URL}/api/states", headers=get_ha_headers())
        response.raise_for_status()
        entities = response.json()
        
        # Filter by domain if specified
        if domain:
            entities = [entity for entity in entities if entity["entity_id"].startswith(f"{domain}.")]
        
        # Search if query is provided
        if search_query and search_query.strip():
            search_term = search_query.lower().strip()
            filtered_entities = []
            
            for entity in entities:
                # Search in entity_id
                if search_term in entity["entity_id"].lower():
                    filtered_entities.append(entity)
                    continue
                    
                # Search in friendly_name
                friendly_name = entity.get("attributes", {}).get("friendly_name", "").lower()
                if friendly_name and search_term in friendly_name:
                    filtered_entities.append(entity)
                    continue
                    
                # Search in other common attributes (state, area_id, etc.)
                if search_term in entity.get("state", "").lower():
                    filtered_entities.append(entity)
                    continue
                    
                # Search in other attributes
                for attr_name, attr_value in entity.get("attributes", {}).items():
                    # Check if attribute value can be converted to string
                    if isinstance(attr_value, (str, int, float, bool)):
                        if search_term in str(attr_value).lower():
                            filtered_entities.append(entity)
                            break
            
            entities = filtered_entities
        
        # Apply the limit
        if limit > 0 and len(entities) > limit:
            entities = entities[:limit]
        
        # Apply field filtering if requested
        if fields:
            # Use explicit field list when provided
            return [filter_fields(entity, fields) for entity in entities]
        elif lean:
            # Apply domain-specific lean fields to each entity
            result = []
            for entity in entities:
                # Get the entity's domain
                entity_domain = entity["entity_id"].split('.')[0]
                
                # Start with basic lean fields
                lean_fields = DEFAULT_LEAN_FIELDS.copy()
                
                # Add domain-specific important attributes
                if entity_domain in DOMAIN_IMPORTANT_ATTRIBUTES:
                    for attr in DOMAIN_IMPORTANT_ATTRIBUTES[entity_domain]:
                        lean_fields.append(f"attr.{attr}")
                
                # Filter and add to result
                result.append(filter_fields(entity, lean_fields))
            
            return result
        else:
            # Return full entities
            return entities
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the tool returns a list of entities with lean formatting by default, explains that search_query 'Does not support wildcards,' mentions the default limit of 100, and clarifies that detailed=True returns all fields. However, it doesn't cover aspects like rate limits, authentication needs, or error handling, which keeps it from a perfect score.

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

Conciseness4/5

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

The description is well-structured with sections (Args, Returns, Examples, Best Practices) and front-loaded with the core purpose. Most sentences earn their place by providing essential information, though some redundancy exists (e.g., repeating filtering concepts). It's appropriately sized but could be slightly more concise in the best practices section.

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

Completeness5/5

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

Given the tool's complexity (5 parameters, no annotations, no output schema), the description is highly complete. It covers purpose, parameters with semantics and examples, return format, usage guidelines, and best practices. While an output schema would help, the description adequately explains the return value ('A list of entity dictionaries with lean formatting by default') and behavioral context, making it sufficient for effective use.

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

Parameters5/5

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

The description adds significant meaning beyond the input schema, which has 0% schema description coverage. It explains each parameter's purpose: domain filters by type (e.g., 'light'), search_query filters by name/id/attributes, limit sets maximum returns, fields specifies included fields, and detailed controls output format. Examples like 'domain="light" - get all lights' provide concrete usage context, fully compensating for the schema's lack of descriptions.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'Get a list of Home Assistant entities with optional filtering.' It specifies the verb ('Get'), resource ('Home Assistant entities'), and scope ('with optional filtering'), and distinguishes it from sibling tools like domain_summary_tool and search_entities_tool by mentioning when to use alternatives.

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

Usage Guidelines5/5

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

The description provides explicit usage guidelines, including when to use this tool vs alternatives. It states: 'For domain overviews, use domain_summary_tool instead of list_entities' and 'To get all entity types/domains, use list_entities without a domain filter.' It also includes best practices like 'Prefer domain filtering over no filtering' and 'Only request detailed=True when necessary.'

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/voska/hass-mcp'

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