list_scenes
List all scenes in your Xiaomi smart home, with optional filtering by home ID and cache refresh.
Instructions
列出所有米家场景。
Args:
home_id: 按家庭ID过滤
refresh: 是否强制刷新缓存Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| home_id | No | ||
| refresh | No |
Implementation Reference
- mcp_server/server.py:103-116 (handler)MCP tool handler for 'list_scenes'. Decorated with @mcp.tool(), defined as async function that sends GET /scenes/ request with optional home_id and refresh query params.
@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_server/server.py:1-10 (registration)MCP server setup. The FastMCP instance 'mcp' is created at the top of the file, and @mcp.tool() decorator on list_scenes registers it as an MCP tool.
import os from urllib.parse import quote import httpx from mcp.server.fastmcp import FastMCP mcp = FastMCP( "mijia-control", instructions="米家智能家居设备控制 MCP Server。用于控制灯光、空调、扫地机等米家智能设备。", ) - mcp_server/server.py:23-26 (helper)The _request helper function used by list_scenes to make HTTP requests to the backend API.
async def _request(method: str, path: str, *, json_data: dict | None = None, params: dict | None = None): async with httpx.AsyncClient(timeout=30) as client: resp = await client.request(method, f"{_BASE_URL}{path}", json=json_data, params=params, headers=_headers()) return resp.json() - mcp_server/server.py:103-116 (schema)Input types are defined via function signature: home_id (str | None) and refresh (bool | False). Output is dict (the raw JSON response from backend).
@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) - app/services/scene_service.py:10-29 (helper)Backend service layer that the API endpoint calls - SceneService.list_scenes handles caching and refreshing scene data from the Xiaomi/Miija API.
def list_scenes(user_id: int, home_id: str = None, refresh: bool = False) -> list[dict]: if refresh: return SceneService._refresh_scenes(user_id) query = SceneCache.query.filter_by(user_id=user_id) if home_id: query = query.filter_by(home_id=home_id) cached = query.all() if not cached: return SceneService._refresh_scenes(user_id) return [ { "scene_id": s.scene_id, "name": s.name, "home_id": s.home_id, } for s in cached ]