tuya-infrared-mcp
An MCP server that enables AI assistants to control devices via Tuya infrared remote control, supporting actions like toggling power and setting modes through natural language.
README
Tuya Infrared MCP Server
English | 中文
A Model Context Protocol (MCP) server that allows AI assistants to control devices through Tuya infrared remote control.
Features
- 🎮 Control devices via Tuya infrared remote control
- 🔌 MCP protocol support (Streamable HTTP)
- 🌐 RESTful API with health check endpoint
- ⚙️ Easy configuration via environment variables
- 🔒 Secure credential management
Prerequisites
- Node.js >= 14.0.0
- Tuya IoT Platform account
- Tuya infrared remote control device
- Learned IR codes for your target device
Quick Start
1. Install Dependencies
npm install
2. Configure Environment Variables
Copy .env.example to .env and fill in your credentials:
cp .env.example .env
Edit .env:
TUYA_BASE_URL=https://openapi.tuyacn.com
TUYA_ACCESS_ID=your_access_id_here
TUYA_ACCESS_SECRET=your_access_secret_here
TUYA_DEVICE_ID=your_device_id_here
TUYA_REMOTE_ID=your_remote_id_here
TUYA_CATEGORY_ID=13
KEY_SWITCH=your_switch_key_here
KEY_MODE_15MIN=your_mode_key_here
PORT=3036
3. Run Server
npm start
Server will run on http://localhost:3036
How to Get Tuya Credentials
Step 1: Create Tuya IoT Platform Account
- Go to Tuya IoT Platform
- Register and create a new project
- Choose "Custom Development"
- Select data center (e.g., China)
Step 2: Get API Credentials
- Go to your project dashboard
- Navigate to "Overview" → "Authorization Key"
- Copy
Access IDandAccess Secret
Step 3: Enable Infrared API Service
- Go to "Service API" tab
- Search for "Infrared Remote Control" (万能红外开放能力)
- Enable the service
Step 4: Link Your Device
- Add your Tuya infrared remote to Tuya Smart App
- Go to project "Devices" tab
- Click "Link Tuya App Account"
- Link your Tuya Smart App account
- Your device will appear in the device list
Step 5: Get Device Information
Use the test script to get device info:
const { TuyaContext } = require('@tuya/tuya-connector-nodejs');
const context = new TuyaContext({
baseUrl: 'https://openapi.tuyacn.com',
accessKey: 'your_access_id',
secretKey: 'your_access_secret'
});
// Get device list
const devices = await context.request({
path: '/v1.0/devices',
method: 'GET'
});
console.log(devices);
Step 6: Learn IR Codes
- Use Tuya Smart App to learn IR codes from your device's remote
- Use API to get learned keys:
// Get remote list
const remotes = await context.request({
path: `/v1.0/infrareds/${DEVICE_ID}/remotes`,
method: 'GET'
});
// Get learned keys for a remote
const keys = await context.request({
path: `/v1.0/infrareds/${DEVICE_ID}/remotes/${REMOTE_ID}/keys`,
method: 'GET'
});
console.log(keys);
MCP Configuration
For Claude Desktop / Claude Code
Add to your MCP configuration file:
{
"mcpServers": {
"tuya-infrared": {
"transport": {
"type": "streamable-http",
"url": "http://localhost:3036/mcp"
}
}
}
}
For Remote Access
If running on a server:
{
"mcpServers": {
"tuya-infrared": {
"transport": {
"type": "streamable-http",
"url": "http://your-server-ip:3036/mcp"
}
}
}
}
Note: Make sure to open port 3036 in your firewall.
API Endpoints
Health Check
GET /health
Response:
{
"status": "ok",
"service": "tuya-infrared-mcp"
}
MCP Endpoint
POST /mcp
Content-Type: application/json
Available MCP Tools
send_infrared
Send infrared signal to control your device.
Parameters:
action(string): Action typeswitch: Toggle power switchmode_15min: Change to 15-minute mode
Example:
// In AI assistant
send_infrared({ action: "switch" })
send_infrared({ action: "mode_15min" })
Limitations
- Infrared signal requires line-of-sight
- Distance limitation (typically 1-3 meters)
- Remote control must be powered on
- Cannot work through walls or obstacles
Troubleshooting
"Sign Invalid" Error
- Check if your Access Secret is correct
- Make sure you linked your Tuya Smart App account to the project
"API Not Subscribed" Error
- Enable "Infrared Remote Control" service in your project
Connection Timeout
- Check if port 3036 is open
- Verify server is running
- Check firewall settings
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- Built with Tuya IoT Platform
- Based on Model Context Protocol
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。