智能家居控制服务器

SmartThings MCP是一个支持OAuth2和持久HTTPS隧道的智能家居自动化服务器,提供设备控制、场景管理和规则更新功能。

  • by masltov-creations
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 masltov-creations/smartthings-mcp

使用说明

SmartThings MCP

现在是完全自动化的东西。

适用于SmartThings的实用MCP服务器,具有OAuth2、持久的HTTPS隧道支持和为您完成无聊工作的设置自动化。

通过人类+人工智能协作构建(人类思维,人工智能编码)。

从这里开始(60秒)

git clone https://github.com/masltov-creations/smartthings-mcp && cd smartthings-mcp && ./scripts/setup.sh

然后授权一次:

https://<your-domain>/oauth/start

什么设置为您处理

./scripts/setup.sh 是主要工作流,可以安全地重新运行。

它可以:

  • 配置Cloudflare或ngrok隧道设置
  • 写入/更新 .env 默认值
  • 收集SmartThings OAuth客户端凭据
  • 安装依赖项并构建
  • 安装/刷新systemd服务(服务器+隧道)
  • 可选择安装 SKILL.md 对于OpenClaw
  • 可选配置和验证 mcporter
  • 等待当地/公共卫生准备就绪
  • 可选择在授权后等待OAuth e2e通过

设置要求您做什么

  • 隧道提供商(cloudflare 或 ngrok)
  • ngrok域+认证令牌(如果选择了ngrok)
  • SmartThings client_id + client_secret
  • 可选的OpenClaw技能安装
  • 可选的 mcporter 注册/验证
  • 可选网关上游管理

提供商访问检查表

  1. 安装SmartThings命令行界面:https://developer.smartthings.com/docs/sdks/cli/
  2. 登录: smartthings login
  3. 在SmartApp中创建OAuth:https://developer.smartthings.com/docs/connected-services/oauth-integrations/
  4. 使用这些精确值:
  • 目标URL: https://<your-domain>/smartthings
  • 重定向URI: https://<your-domain>/oauth/callback
  • 范围: r:locations:* r:devices:* x:devices:* r:scenes:* x:scenes:* r:rules:* w:rules:*
  1. 出现提示时,将凭据粘贴到安装程序中。
  2. 授权地点: /oauth/start.

ngrok链接:

  • 域:https://dashboard.ngrok.com/domains
  • authtoken:https://dashboard.ngrok.com/get-started/your-authtoken

快速验证

curl -sS http://127.0.0.1:8080/healthz?e2e=1
npx -y mcporter list smartthings --schema

如果 e2e.status 是 pass,你在做生意。

技能(法学硕士)

使用 SKILL.md 作为操作员指南:

  • 刀具路径
  • 渐进式披露
  • 输出格式化合同
  • 编写安全确认流程

安装程序可以在检测到OpenClaw时自动安装此程序。

工具亮点

读取/查询

  • list_locations
  • list_devices
  • list_devices_with_room_temperatures
  • get_device_details
  • get_device_status
  • get_device_statuses (一次通话中的批量状态)
  • list_scenes
  • list_rules
  • get_rule_details

写入/控制

  • send_device_command (先确认)
  • send_device_command_and_verify (首选:命令+状态验证)
  • execute_scene (先确认)
  • update_rule (先确认)

快速查询示例

# Device + room temperature summary (fast path)
npx -y mcporter call --server smartthings --tool list_devices_with_room_temperatures

# Device inventory
npx -y mcporter call --server smartthings --tool list_devices

# Device details
npx -y mcporter call --server smartthings --tool get_device_details deviceId=<uuid>

# Bulk status for many devices in one MCP call
npx -y mcporter call --server smartthings --tool get_device_statuses deviceIds='["<uuid1>","<uuid2>"]'

# Command + verify in one call (preferred for automations)
npx -y mcporter call --server smartthings --tool send_device_command_and_verify \
  deviceId=<uuid> \
  commands='[{"component":"main","capability":"switch","command":"on"}]' \
  expectations='[{"componentId":"main","capability":"switch","attribute":"switch","equals":"on"}]'

OpenClaw+mcporter

注册服务器:

npx -y mcporter config add smartthings https://<your-domain>/mcp --scope home

列出工具:

npx -y mcporter list smartthings --schema

可选集成

如果你想要一个具有命名上游的共享端点:

MCP_GATEWAY_ENABLED=true ./scripts/setup.sh

管理上游:

./scripts/manage-upstreams.sh
./scripts/setup.sh upstreams

网关终结点:

  • POST /mcp-gateway

常见操作

更新运行时安装并重新启动:

cd /home/$USER/apps/smartthings-mcp && git pull --ff-only origin main && npm run build && sudo systemctl restart smartthings-mcp

安全地重新运行安装程序:

cd /home/$USER/apps/smartthings-mcp && ./scripts/setup.sh

手动安装工作区技能:

install -Dm644 SKILL.md ~/.openclaw/workspace/skills/smartthings-mcp/SKILL.md

故障排除(快速点击)

  • redirect_uri could not be validated 重定向URI必须完全匹配 https://<your-domain>/oauth/callback.

  • dial tcp 127.0.0.1:8080: connect: connection refused 服务已关闭/正在重新启动。检查 systemctl status smartthings-mcp.

  • 406 /SSE错误 MCP端点预期 Accept: text/event-stream 用于手动通话。

  • 401 来自SmartThings API 重新运行 /oauth/start 以及完整的授权。

  • 温度问题很慢 使用 list_devices_with_room_temperatures 和 get_device_statuses 在每个设备状态循环之前。

安全说明

  • 保守秘密 .env从不使用git。
  • OAuth令牌刷新是服务器端自动进行的。
  • 执行主机/来源检查。
  • 代理层在写入操作之前应要求明确确认。

建筑(高级)

MCP client -> SmartThings MCP -> SmartThings APIs
                      |
                OAuth2 + token refresh
                      |
      optional public tunnel (Cloudflare/ngrok)

许可证

麻省理工学院