Skip to main content
Glama
handsomejustin

Xiaomi smart home MCP server

list_homes

Retrieve a complete overview of all Xiaomi smart homes and their connected devices. Optionally refresh cached data to get the latest status.

Instructions

列出所有家庭及其设备概览。

Args:
    refresh: 是否强制刷新缓存

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
refreshNo

Implementation Reference

  • MCP tool handler for 'list_homes' - calls the backend API endpoint /homes/ with optional refresh parameter.
    @mcp.tool()
    async def list_homes(refresh: bool = False) -> dict:
        """列出所有家庭及其设备概览。
    
        Args:
            refresh: 是否强制刷新缓存
        """
        params = {}
        if refresh:
            params["refresh"] = "true"
        return await _request("GET", "/homes/", params=params)
  • Flask API endpoint handler for listing homes - validates the refresh query parameter and calls HomeService.list_homes.
    @homes_ns.route("/", methods=["GET"])
    @auth_required
    @limiter.limit("60 per minute")
    def list_homes():
        """获取家庭列表
        ---
        tags:
          - 家庭
        security:
          - cookieAuth: []
          - bearerAuth: []
        parameters:
          - in: query
            name: refresh
            type: boolean
            default: false
        responses:
          200:
            description: 家庭列表
        """
        refresh = request.args.get("refresh", "false").lower() == "true"
        try:
            homes = HomeService.list_homes(get_current_user_id(), refresh=refresh)
            return success(homes)
        except Exception as e:
            return error(str(e), 500)
  • Core business logic for list_homes - returns cached homes or refreshes from the Mi Jia API if refresh is requested or cache is empty.
    def list_homes(user_id: int, refresh: bool = False) -> list[dict]:
        if refresh:
            return HomeService._refresh_homes(user_id)
    
        cached = HomeCache.query.filter_by(user_id=user_id).all()
        if not cached:
            return HomeService._refresh_homes(user_id)
    
        return [
            {
                "home_id": h.home_id,
                "name": h.name,
                "room_list": h.room_list,
            }
            for h in cached
        ]
  • The @mcp.tool() decorator registers 'list_homes' as an MCP tool in the FastMCP server.
    @mcp.tool()
    async def list_devices(home_id: str | None = None, refresh: bool = False) -> dict:
        """列出所有米家智能设备。返回设备ID、名称、型号、在线状态等信息。
    
        Args:
            home_id: 按家庭ID过滤,不传则返回全部设备
            refresh: 是否强制刷新设备列表缓存
        """
        params = {}
        if home_id:
            params["home_id"] = home_id
        if refresh:
            params["refresh"] = "true"
        return await _request("GET", "/devices/", params=params)
    
    
    @mcp.tool()
    async def get_device(did: str) -> dict:
        """获取设备详情,包含设备规格、可用属性列表和动作列表。
    
        Args:
            did: 设备ID
        """
        return await _request("GET", f"/devices/{quote(did)}")
    
    
    # ── 设备属性读写 ──
    
    
    @mcp.tool()
    async def get_property(did: str, prop_name: str) -> dict:
        """读取设备属性值,例如灯光亮度、空调温度、开关状态等。
    
        Args:
            did: 设备ID
            prop_name: 属性名称,如 power、brightness、temperature
        """
        return await _request("GET", f"/devices/{quote(did)}/props/{prop_name}")
    
    
    @mcp.tool()
    async def set_property(did: str, prop_name: str, value) -> dict:
        """设置设备属性值,用于控制设备。例如开灯、调亮度、设温度等。
    
        Args:
            did: 设备ID
            prop_name: 属性名称,如 power、brightness、temperature
            value: 属性值,类型取决于属性定义。常见值:power 为 "on"/"off",brightness 为 0-100,temperature 为数字
        """
        return await _request("PUT", f"/devices/{quote(did)}/props/{prop_name}", json_data={"value": value})
    
    
    # ── 设备动作 ──
    
    
    @mcp.tool()
    async def run_action(did: str, action_name: str, value: dict | None = None) -> dict:
        """执行设备动作,例如扫地机开始清扫、播放音乐等。
    
        Args:
            did: 设备ID
            action_name: 动作名称,如 start-sweep、stop-sweeping
            value: 动作参数,可选
        """
        body = {"value": value} if value is not None else {}
        return await _request("POST", f"/devices/{quote(did)}/actions/{action_name}", json_data=body)
    
    
    # ── 场景管理 ──
    
    
    @mcp.tool()
    async def list_scenes(home_id: str | None = None, refresh: bool = False) -> dict:
        """列出所有米家场景。
    
        Args:
            home_id: 按家庭ID过滤
            refresh: 是否强制刷新缓存
        """
        params = {}
        if home_id:
            params["home_id"] = home_id
        if refresh:
            params["refresh"] = "true"
        return await _request("GET", "/scenes/", params=params)
    
    
    @mcp.tool()
    async def run_scene(scene_id: str) -> dict:
        """执行一个米家场景,触发该场景中预设的所有设备操作。
    
        Args:
            scene_id: 场景ID
        """
        return await _request("POST", f"/scenes/{scene_id}/run")
    
    
    # ── 家庭管理 ──
    
    
    @mcp.tool()
Behavior3/5

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

The description adds some transparency about the refresh parameter controlling cache forcing, but no annotations exist. It does not mention read-only nature or any other behavioral traits beyond caching.

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 extremely concise: a single purpose sentence and an Args line. No unnecessary information.

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

Completeness3/5

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

While it covers the tool's purpose and the single parameter, it lacks details about the return format or any prerequisites. With no output schema, some description of the output would improve completeness.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates by explaining the refresh parameter's meaning ('whether to force refresh cache'), adding value beyond the schema's title alone.

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 it lists all homes and their device overview (specific verb+resource). However, it does not explicitly differentiate from sibling tools like get_home, though the name implies it.

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 (e.g., get_home for a single home, or list_devices for devices). The description only states what it does.

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/handsomejustin/mijia-control'

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