SmartThings MCP Server

SmartThings MCP Server

Enables managing Samsung SmartThings devices, scenes, notifications, and routines through full CRUD operations on rules via the MCP protocol.

Category
访问服务器

README

SmartThings MCP Server

An MCP server for Samsung SmartThings, exposing devices, scenes, notifications and full CRUD on Rules (Routines) over streamable-HTTP.

Built with FastMCP. OAuth2 with automatic token refresh — no expiring Personal Access Tokens anywhere.

<p align="center"> <img src="docs/architecture.svg" alt="Architecture: MCP client to smartthings-mcp to the SmartThings Cloud API, and the Rules vs Routines limitation" width="100%"> </p>

Why

Most SmartThings MCP servers only read devices and fire scenes. This one also creates, updates, deletes and executes Rules, the automation engine behind Routines — which is what you actually need to let an LLM build home automations.

⚠️ Rules vs Routines — read this before filing a bug

Thing Visible via API? Manageable?
Rules created by this server (create_routine) ✅ ✅ full CRUD + execute
Routines created in the SmartThings phone app ❌ never ❌ app only

list_rules returning [] is expected if you have only ever created Routines in the mobile app. It is not an authentication failure. This is a documented Samsung platform limitation that no client can work around:

"Automatic routines ("rules") you create in the SmartThings app are a superset of what you can create with the Rules API. Routines created in the app will not appear when sending a GET request to https://api.smartthings.com/v1/rules/." — SmartThings docs

Tools

Group Tools
Devices list_devices, get_device_status, control_device
Scenes list_scenes, execute_scene
Locations list_locations
Notifications send_notification, create_alert_switch
Rules list_rules, get_rule, create_routine, update_routine, delete_routine, execute_routine

Scenes are read-only by design. SmartThings exposes no write scope for scenes (w:scenes is rejected outright), so scenes can be listed and executed but never authored through the API.

Listing and controlling devices

<p align="center"> <img src="docs/demo-devices.svg" alt="Example output of list_devices and control_device" width="100%"> </p>

Building an automation

<p align="center"> <img src="docs/demo-rules.svg" alt="Example lifecycle: create_routine, list_rules, execute_routine, delete_routine" width="100%"> </p>

Device names, IDs and rule IDs in these examples are fictional.

Setup

  1. Create an OAuth-In SmartApp with these scopes:

    r:devices:* x:devices:* r:scenes:* x:scenes:* r:locations:*
    r:rules:* w:rules:* x:rules:*
    
  2. Configure credentials:

    cp .env.example .env
    # fill in SMARTTHINGS_CLIENT_ID and SMARTTHINGS_CLIENT_SECRET
    
  3. Authorize once to mint the refresh token:

    python oauth_setup.py
    

    This opens a local loopback listener (default port 9444) and writes data/tokens.json. If your SmartThings app requires a public HTTPS callback instead, use oauth_capture.py with OAUTH_REDIRECT_URI set.

  4. Run it:

    docker compose up -d --build
    

    The server listens on http://localhost:8085/mcp.

Client configuration

{
  "mcpServers": {
    "smartthings": {
      "type": "http",
      "url": "http://localhost:8085/mcp"
    }
  }
}

The server is stateless streamable-HTTP: POST JSON-RPC with Accept: application/json, text/event-stream. No mcp-session-id header is required; responses are returned as SSE (event: message\ndata: {...}).

Writing rules

rule_json is a JSON string containing the Rules API actions array only — name and locationId are added by the tool. Schema: https://developer.smartthings.com/docs/rules/rules-api

A harmless rule, safe to use when validating execute_routine:

[{"if": {"equals": {"left": {"integer": 1}, "right": {"integer": 1}},
  "then": [{"sleep": {"duration": {"value": {"integer": 1}, "unit": "Second"}}}]}}]

A real rule — when one switch turns on, turn another off:

[{"if": {"equals": {
    "left": {"device": {"devices": ["<deviceId>"], "component": "main",
             "capability": "switch", "attribute": "switch"}},
    "right": {"string": "on"}},
  "then": [{"command": {"devices": ["<otherDeviceId>"],
            "commands": [{"component": "main", "capability": "switch", "command": "off"}]}}]}}]

⚠️ execute_routine runs the rule's actions for real, immediately. It does not simulate. If any of your devices are power switches for machines you care about, validate with the sleep rule above rather than a command action.

Authentication notes

OAuth2 only. data/tokens.json must contain all three of access_token, refresh_token, and a real future expires_at. A background keep-alive loop (KEEPALIVE_HOURS, default 12h) refreshes proactively so the refresh token never goes stale through disuse.

Personal Access Tokens are intentionally not supported. Since December 2024, SmartThings PATs expire 24 hours after creation, making them unusable for a long-running server. There is no PAT fallback and no PAT setting — every request, including all Rules calls, uses the auto-refreshing OAuth token.

Troubleshooting

401 on rules calls. In order:

  1. Check data/tokens.json has all three keys and a future expires_at.
  2. Confirm locationId is being sent — SmartThings returns a bare-HTML 401 (not a 400) when locationId is missing from /rules requests, which makes a simple missing-parameter bug look like an auth failure.
  3. Restart the container to force a refresh.
  4. Last resort: re-run oauth_setup.py.

Endpoint quirks (already handled — don't "correct" them back):

  • create: POST /rules?locationId=...
  • execute: POST /rules/execute/{ruleId}?locationId=... (not /rules/{id}/execute)

Container reports unhealthy. The MCP endpoint only answers POST, so an HTTP healthcheck against / returns 404. Use the TCP check in docker-compose.yml.

Env changes not taking effect. docker compose up -d --force-recreate — a plain docker restart will not re-read .env.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选