智能设备控制服务器

SmartThings MCP服务器是一个用于控制SmartThings设备的模型上下文协议服务器,支持OAuth和PAT两种认证方式。

  • by asleep-ai
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 asleep-ai/smartthings-mcp

使用说明

SmartThings MCP服务器

用于控制SmartThings设备的模型上下文协议(MCP)服务器。

快速开始

# 1. Install
uv pip install -e .

# 2. Create OAuth app (requires SmartThings CLI)
brew install smartthingscommunity/smartthings/smartthings  # or: npm install -g @smartthings/cli
smartthings login
smartthings apps:create  # Select OAuth-In App, save client_id/secret

# 3. Configure
export SMARTTHINGS_CLIENT_ID=your_client_id
export SMARTTHINGS_CLIENT_SECRET=your_client_secret

# 4. Authenticate (opens browser)
python -m smartthings_mcp.oauth_setup

# Done! Tokens auto-refresh every 24 hours

替代:使用个人访问令牌(每天过期)

export SMARTTHINGS_TOKEN=your_token  # Get from: https://account.smartthings.com/tokens

身份验证方法

方法 设置时间 令牌到期 自动刷新
OAuth 5分钟(一次性) 24小时 ✅ 自动
专利审查高速路 1分钟 24小时 ❌ 手动再生

推荐:使用OAuth进行持续使用,使用PAT进行快速测试。

OAuth设置详细信息

先决条件

需要SmartThings CLI(web UI将于2022年停产):

# macOS
brew install smartthingscommunity/smartthings/smartthings

# npm
npm install -g @smartthings/cli

# Or download: https://github.com/SmartThingsCommunity/smartthings-cli/releases

创建OAuth应用程序

smartthings login
smartthings apps:create

出现提示时:

  • 应用程序类型: OAuth应用内 (API_ONLY)
  • 显示名称: SmartThings MCP
  • 重定向URI: http://localhost:8080/callback
  • 范围: r:devices:*, x:devices:*, r:locations:*

保存client_id和client_secret (只显示一次!)

运行安装程序

export SMARTTHINGS_CLIENT_ID=your_client_id
export SMARTTHINGS_CLIENT_SECRET=your_client_secret
python -m smartthings_mcp.oauth_setup

令牌保存到 ~/.config/smartthings-mcp/tokens.json 并自动刷新。

配置

包裹会自动加载 .env 文件(如果它存在于您的项目目录中)。

创建 .env 文件:

SMARTTHINGS_CLIENT_ID=your_client_id
SMARTTHINGS_CLIENT_SECRET=your_client_secret

或者直接使用环境变量(不需要.env文件)。

故障排除

“找不到OAuth令牌” → Run python -m smartthings_mcp.oauth_setup

端口8080正在使用中 → 停止其他服务或修改OAuth应用程序中的重定向URI

令牌刷新失败 → 重新运行安装程序以获取新令牌

PAT每天到期 → 切换到OAuth或重新生成https://account.smartthings.com/tokens

许可证

麻省理工学院