Skip to main content
Glama
handsomejustin

Xiaomi smart home MCP server

set_property

Set device properties to control smart home appliances. Change power, brightness, temperature, and more using device ID, property name, and value.

Instructions

设置设备属性值,用于控制设备。例如开灯、调亮度、设温度等。

Args:
    did: 设备ID
    prop_name: 属性名称,如 power、brightness、temperature
    value: 属性值,类型取决于属性定义。常见值:power 为 "on"/"off",brightness 为 0-100,temperature 为数字

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
didYes
prop_nameYes
valueYes

Implementation Reference

  • MCP tool handler for 'set_property'. Defined as an async function decorated with @mcp.tool(). Sends an HTTP PUT request to /devices/{did}/props/{prop_name} with the value as JSON body. This is the primary entry point exposed to MCP clients.
    @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})
  • Core service-layer implementation of set_property. Uses the MiJia API to call device.set(prop_name, value) with timeout support, then emits a property_change event via WebSocket. Returns a dict with did, prop_name, and value.
    @staticmethod
    def set_property(user_id: int, did: str, prop_name: str, value, timeout=MIJIA_CALL_TIMEOUT) -> dict:
        api = api_pool.get_api(user_id)
        device = mijiaDevice(api, did=did)
        _call_with_timeout(device.set, prop_name, value, timeout=timeout)
        _emit_device_update(user_id, did, "property_change", {"prop_name": prop_name, "value": value})
        return {"did": did, "prop_name": prop_name, "value": value}
  • Flask REST API handler for PUT /devices/<did>/props/<prop_name>. Validates input with SetPropertySchema, calls DeviceService.set_property, and handles errors (DeviceSetError, TimeoutError).
    @devices_ns.route("/<did>/props/<prop_name>", methods=["PUT"])
    @auth_required
    @limiter.limit("30 per minute")
    def set_property(did, prop_name):
        """设置设备属性值
        ---
        tags:
          - 设备
        security:
          - cookieAuth: []
          - bearerAuth: []
        parameters:
          - in: path
            name: did
            type: string
            required: true
          - in: path
            name: prop_name
            type: string
            required: true
          - in: body
            name: body
            required: true
            schema:
              type: object
              required: [value]
              properties:
                value:
                  description: 属性值(类型取决于属性定义)
        responses:
          200:
            description: 设置成功
          400:
            description: 参数验证失败
        """
        try:
            data = set_prop_schema.load(request.get_json(silent=True) or {})
        except Exception as e:
            return error(f"输入验证失败: {e}", 400)
        try:
            result = DeviceService.set_property(get_current_user_id(), did, prop_name, data["value"])
            return success(result)
        except DeviceSetError as e:
            return _mijia_error_response(e)
        except TimeoutError as e:
            return error(str(e), 504)
        except Exception as e:
            return error(str(e), 500)
  • Schema definition for set_property input validation. Defines a single required field 'value' of type Raw.
    class SetPropertySchema(Schema):
        value = fields.Raw(required=True)
  • MCP tool registration via @mcp.tool() decorator on the set_property async function in the FastMCP server.
    @mcp.tool()
    async def set_property(did: str, prop_name: str, value) -> dict:
Behavior2/5

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

No annotations are provided, and the description does not disclose important behavioral traits such as side effects, authentication requirements, rate limits, or error handling for invalid property names or values. As a mutation tool, critical behaviors are omitted.

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 concise, with a clear purpose statement followed by a structured Args section. Every sentence adds value, though the Args format could be slightly more compact. Overall, it is efficient and front-loaded.

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 the lack of output schema and annotations, the description does not explain return values (e.g., success/failure) or prerequisites (e.g., device online, auth). For a mutation tool with three parameters and no structured guidance, the description is insufficiently complete.

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?

The input schema provides only types (string) with no descriptions (0% coverage). The description compensates effectively by explaining each parameter: did as device ID, prop_name with examples like 'power', 'brightness', 'temperature', and value with common types and example values ('on'/'off', 0-100).

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 it sets device property values to control devices, with concrete examples like '开灯、调亮度、设温度' (turn on light, adjust brightness, set temperature). It distinguishes from sibling tools such as get_property (read) and list_devices (list).

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

Usage Guidelines3/5

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

The description provides examples of when to use the tool (controlling devices by setting properties) but does not explicitly state when not to use it or mention alternatives for similar tasks like run_action or run_scene. The usage context is implied but not clearly delineated.

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