Control Xiaomi Mi Home smart devices through the Mi Home cloud service.
mihome-mcp
Welcome to your new Mastra project! We're excited to see what you'll build.
Miloco 兼容服务(实现说明)
本项目在 Mastra Studio(默认端口 4111)之外,额外启动了一个 miloco_server 风格的兼容 HTTP/WS 服务(默认端口 8787),用于对齐 xiaomi-miloco/miloco_server 的接口形态(/api/* + NormalResponse{code,message,data})并复用本仓库的 src/miot_kit。
如何运行
- 开发启动
pnpm run dev
- 访问
Mastra Studio:
http://localhost:4111
Miloco 兼容 API:
http://localhost:8787/api
环境变量
MILOCO_HTTP_ENABLED- 默认
true - 设为
false则不启动兼容服务
- 默认
MILOCO_HTTP_PORT- 默认
8787
- 默认
MILOCO_DATA_PATH- 默认
./.miloco-data - 用于保存 auth/miot/mcp/trigger/chat/model 等模块的本地数据(json 文件)
- 默认
JWT_EXPIRES_MINUTES- 默认
1440
- 默认
接口概览(/api 前缀)
Auth
POST /auth/registerGET /auth/register-statusPOST /auth/loginGET /auth/logoutGET /auth/languagePOST /auth/language
说明:
- 认证方式为 Cookie
access_token(JWT)。 logout会更新全局 invalidation 时间戳,使所有旧 token 失效(对齐 miloco_server 行为)。
MiOT
GET /miot/xiaomi_home_callback?code&state(HTML)GET /miot/login_statusGET /miot/user_infoGET /miot/device_listGET /miot/camera_listGET /miot/refresh_miot_all_infoGET /miot/refresh_miot_camerasGET /miot/refresh_miot_scenesGET /miot/refresh_miot_user_infoGET /miot/refresh_miot_devicesGET /miot/miot_scene_actionsGET /miot/send_notify?notify=...WS /miot/ws/video_stream?camera_id=...&channel=...
说明:
/device_list、/camera_list已对接MIoTClient.getDevices()并做了字段适配。/refresh_*会将数据缓存到MILOCO_DATA_PATH下的 json 文件。video_streamWS 已接入miot_kit/camera.ts的帧回调,当前直接推送二进制帧数据。
MCP
POST /mcpGET /mcpPUT /mcp/:config_idDELETE /mcp/:config_idPOST /mcp/reconnect/:config_idGET /mcp/clients/status
HA
POST /ha/set_configGET /ha/get_configGET /ha/automationsGET /ha/automation_actionsGET /ha/refresh_ha_automations
Trigger
POST /trigger/ruleGET /trigger/rules?enabled_only=PUT /trigger/rule/:rule_idDELETE /trigger/rule/:rule_idGET /trigger/logs?limit=POST /trigger/execute_actionsWS /trigger/ws/dynamic_execute_log?log_id=...
Model
POST /modelGET /modelPUT /model/:model_idDELETE /model/:model_idPOST /model/get_vendor_modelsGET /model/model_purposesGET /model/set_current_model?purpose=...&model_id=...POST /model/loadGET /model/get_cuda_info
Chat
WS /chat/ws/query?request_id=...&session_id=...GET /chat/history/:session_idGET /chat/historysDELETE /chat/history/:session_idGET /chat/history/search?keyword=...
目前已实现的功能(概述)
- HTTP/WS 兼容层
- Express + ws
NormalResponse返回结构- JWT Cookie 鉴权与全局 invalidation
- MiOT 基础能力
- OAuth2 callback 的最小落地
- devices/scenes/cameras 的拉取与本地缓存
- notify 发送
- video_stream WS:已接入
MIoTCameraManager推送帧数据
遗留部分(需要继续严格对齐)
以下内容当前为“接口存在但内部尚未完全对齐 miloco_server 的真实业务逻辑/数据来源”,后续会逐步补齐:
- MiOT 摄像头连接信息来源
video_stream需要ip/token/key等信息。- 当前仅在设备数据中存在这些字段时可用;后续需要补齐 LAN/mDNS 发现与 did 关联,或引入 miloco_server 等价的获取/存储链路。
- MCP 真连接与 tool 执行链路
- 当前 MCP 仅完成配置 CRUD 与状态占位。
- 需要实现:连接外部 MCP server、列 tools、call tool,并形成 tool executor(对齐 miloco_server
mcp_client_manager/tool_executor)。
- Trigger execute_actions 真执行与 WS 日志
- 当前执行结果为占位。
- 需要对接 tool executor + 动态日志推送。
- Chat WS query 的 agent/模型流式输出
- 当前为 echo/占位。
- 需要对接 Mastra Agent stream,并落盘 history。
- Model vendor models 拉取与目的场景联动
- 当前 vendor models 为占位。
- 需要对接真实 OpenAI-compatible API 并与 chat/trigger 使用同一套模型选择逻辑。
Getting Started
Start the development server:
pnpm run dev
Open http://localhost:4111 in your browser to access Mastra Studio. It provides an interactive UI for building and testing your agents, along with a REST API that exposes your Mastra application as a local service. This lets you start building without worrying about integration right away.
You can start editing files inside the src/mastra directory. The development server will automatically reload whenever you make changes.
Learn more
To learn more about Mastra, visit our documentation. Your bootstrapped project includes example code for agents, tools, workflows, scorers, and observability.
If you're new to AI agents, check out our course and YouTube videos. You can also join our Discord community to get help and share your projects.
Deploy on Mastra Cloud
Mastra Cloud gives you a serverle
Environment Variables
MILOCO_HTTP_ENABLEDEnable or disable the compatibility HTTP serviceMILOCO_HTTP_PORTPort for the compatibility serviceMILOCO_DATA_PATHPath for storing local auth, miot, and mcp dataJWT_EXPIRES_MINUTESJWT expiration time in minutesConfiguration
{"mcpServers": {"mihome": {"command": "npx", "args": ["-y", "@mizuka-wu/mihome-mcp"]}}}