SmartThings MCP Server
Enables control and monitoring of SmartThings smart home devices through natural language, supporting switches, sensors, refrigerators, and other IoT devices with real-time status queries and command execution.
README
SmartThings MCP Server (Python)
A production-ready, Dockerized MCP (Model Context Protocol) server for controlling and querying SmartThings devices via Personal Access Token (PAT).
Features
- ✅ Fully Async: Efficient async/await implementation with proper resource management
- ✅ Comprehensive Logging: Detailed logging for debugging and monitoring
- ✅ Type Safety: Full type hints and Pydantic validation
- ✅ Error Handling: Structured error handling with meaningful messages
- ✅ Optimized API Calls: Direct device lookups to minimize API requests
- ✅ Docker Best Practices: Non-root user, health checks, minimal image size
- ✅ Resource Cleanup: Proper HTTP client lifecycle management
Project Structure
.
├── Dockerfile # Production-ready Docker image
├── docker-compose.yml # Docker Compose configuration
├── .dockerignore # Docker build exclusions
├── .env.example # Environment variable template
├── requirements.txt # Python dependencies
├── app/
│ ├── __init__.py
│ ├── main.py # MCP server and tool definitions
│ └── smartthings.py # SmartThings API client
└── README.md # This file
Setup
1. Get a SmartThings Personal Access Token (PAT)
- Visit https://account.smartthings.com/tokens
- Click "Generate new token"
- Give it a name (e.g., "MCP Server")
- Select required scopes:
devices(read and execute)locations(read)
- Copy the generated token
2. Configure Environment
cp .env.example .env
# Edit .env and add your SMARTTHINGS_PAT
3. Build and Run
Using Docker
# Build the image
docker build -t smartthings_mcp:latest .
# Run with stdio transport
docker run --rm -i \
-e SMARTTHINGS_PAT=$SMARTTHINGS_PAT \
-e SMARTTHINGS_LOCATION_ID=$SMARTTHINGS_LOCATION_ID \
smartthings_mcp:latest
Using Docker Compose
# Build and run
docker compose build
docker compose run --rm smartthings-mcp python -m app.main
Local Development
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export SMARTTHINGS_PAT="your_pat_here"
# Run the server
python -m app.main
Available Tools
list_locations()
List all SmartThings locations accessible with the current PAT.
Returns: List of location objects with locationId, name, and metadata.
list_rooms(locationId?)
List all rooms in a SmartThings location.
Parameters:
locationId(optional): The location ID. Falls back toSMARTTHINGS_LOCATION_IDenv var or first available location.
Returns: List of room objects with roomId, name, and metadata.
list_devices(locationId?, roomId?)
List all SmartThings devices, optionally filtered by location and/or room.
Parameters:
locationId(optional): Filter devices by locationroomId(optional): Filter devices by room
Returns: List of device objects with deviceId, label, capabilities, and metadata.
device_status({ deviceId?, name? })
Get the current status of a SmartThings device.
Parameters:
deviceId(optional): The unique device ID (preferred for efficiency)name(optional): Device name/label to search for (slower, searches all devices)
Returns: Device information with current status and flattened summary.
Note: Provide at least one of deviceId or name.
switch_device({ deviceId?, name?, command, component? })
Turn a SmartThings switch device on or off.
Parameters:
deviceId(optional): The unique device ID (preferred)name(optional): Device name/label to search forcommand(required): Either"on"or"off"component(optional): Device component (default:"main")
Returns: Device information and command execution result.
fridge_status({ deviceId?, name? })
Get detailed status of a SmartThings refrigerator/fridge device.
Parameters:
deviceId(optional): The unique device IDname(optional): Device name/label to search for
Returns: Refrigerator-specific status summary including:
- Power state
- Refrigerator and freezer temperatures
- Door open/closed state
- Ice maker status
- Defrost mode
- All temperature, door, ice, humidity, and energy-related attributes
Note: If neither parameter is provided, automatically searches for devices with "fridge" or "refrigerator" in the name.
device_health(deviceId)
Get the health status of a SmartThings device.
Parameters:
deviceId(required): The unique device ID
Returns: Device health information including online/offline state.
Architecture Improvements
Async Design
- All tools are fully async for better concurrency
- Uses a single HTTP client with connection pooling
- Proper cleanup on shutdown via lifespan handler
Error Handling
- Pydantic validation for all inputs
- Structured error messages
- Graceful fallbacks (e.g., health check returns "unknown" instead of failing)
Performance Optimizations
- Direct device GET endpoint when using
deviceId(avoids listing all devices) - Efficient device search with early exit
- Connection reuse across all requests
Security
- Runs as non-root user in Docker
- Minimal attack surface (no exposed ports)
- Token never logged
Logging
- Comprehensive logging at INFO and DEBUG levels
- Structured log format with timestamps
- Request/response logging for debugging
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
SMARTTHINGS_PAT |
✅ Yes | - | SmartThings Personal Access Token |
SMARTTHINGS_LOCATION_ID |
❌ No | - | Default location ID for room queries |
SMARTTHINGS_BASE_URL |
❌ No | https://api.smartthings.com/v1 |
SmartThings API base URL |
MCP_TRANSPORT |
❌ No | stdio |
MCP transport method |
Development
Running Tests
# Install dev dependencies
pip install pytest pytest-asyncio httpx
# Run tests
pytest
Logging Levels
Set the log level via environment:
# Debug level (verbose)
export LOG_LEVEL=DEBUG
# Info level (default)
export LOG_LEVEL=INFO
# Warning level (quiet)
export LOG_LEVEL=WARNING
Code Style
This project follows:
- PEP 8 style guide
- Type hints for all functions
- Docstrings for all public APIs
Troubleshooting
"SMARTTHINGS_PAT is required"
- Ensure you've set the
SMARTTHINGS_PATenvironment variable - Check that your PAT has the correct scopes
"No locations found"
- Verify your PAT has
locations:readscope - Check that you have at least one location in your SmartThings account
"Device not found"
- Use
list_devices()to see available devices - Ensure the device name or ID is correct (case-insensitive for names)
- Check that the device is in the specified location/room if filters are applied
HTTP Timeout Errors
- Increase timeout in
smartthings.py(default: 15s) - Check network connectivity to SmartThings API
License
MIT License - feel free to use and modify as needed.
Contributing
Contributions welcome! Please:
- Add tests for new features
- Update documentation
- Follow existing code style
- Ensure all tests pass
Changelog
v2.0.0 (Current)
- ✅ Full async/await implementation
- ✅ Comprehensive logging and error handling
- ✅ Optimized API calls with direct device lookups
- ✅ Docker best practices (non-root user, health checks)
- ✅ Pydantic validation for all inputs
- ✅ Proper resource cleanup
- ✅ Complete type hints and docstrings
v1.0.0 (Original)
- Basic MCP server implementation
- Synchronous tool functions
- Basic error handling
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。