tuya-bulb-mcp
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
tuya-bulb-mcp
Local MCP server for Tuya / Smart Life Wi-Fi lighting. Connect an MCP-compatible AI client to a bulb directly over your local network with TinyTuya. No Tuya Cloud calls are needed at runtime.
Features
Local control with outgoing LAN connections; stdio communication with the MCP client.
Four MCP tools for status, power, and colour/brightness/temperature.
Bounded writes to supported datapoints DP20–24; no generic datapoint writer.
Verified power writes and state-change verification via ACK or read-back.
Idempotent requests return an already-set result without redundant writes.
Interactive setup, read-only device compatibility verification, and a local baseline.
Compatibility: This implementation is built for a single compatible Tuya light_ty bulb with the DP20–24 mapping. It is not a generic Tuya device controller. Firmware and datapoint layouts vary; read-only verification is required before any physical writes.
Related MCP server: mcp-server-tuya
Requirements
Python 3.10+ (3.11 recommended)
Bulb paired in Smart Life / Tuya and accessible from this computer on the LAN
Device ID, local IPv4 address, protocol version (3.3 or 3.4) and 16-character local key
The local key can be obtained through the Tuya IoT Platform after creating a project and linking your Smart Life account. Locate the bulb under the linked project's devices and retrieve its device ID and local key. The local IPv4 address and protocol version can be found through LAN discovery or your router. Tuya's cloud interface and credential retrieval requirements can change. Cloud access may be required to obtain the key, but is not required for runtime control.
Before starting: Keep the bulb powered and reachable on the same LAN, and have its device ID and 16-character local key available. Do not paste the key into chat, a GitHub issue or a client MCP configuration.
Quick start
First-time setup, in order:
Pair your compatible bulb in the Smart Life / Tuya app and keep it reachable on the same LAN.
Obtain its device ID and 16-character local key from the linked Tuya IoT project. The optional LAN scan can help find its IP and protocol version.
Run the commands for your OS below. The setup wizard asks for the device details and verifies the bulb read-only before saving local configuration.
Add the MCP server to your AI client's configuration using the example in MCP client integration, then connect or reload that client.
Ask the connected assistant for the bulb's status first; see First-use examples.
Windows (PowerShell):
git clone https://github.com/canyrtcn/tuya-bulb-mcp.git
cd tuya-bulb-mcp
py -3.11 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
.\.venv\Scripts\python.exe setup_wizard.py --scanLinux / macOS:
git clone https://github.com/canyrtcn/tuya-bulb-mcp.git
cd tuya-bulb-mcp
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python setup_wizard.py --scanThe scan is optional. If it finds nothing, run the wizard without --scan and enter the device details manually. Network isolation may prevent discovery. The wizard prompts for the local key securely when run interactively; it never needs the key as a command-line argument.
The wizard:
Prompts for device details and a hidden local key.
Reads device status without writing datapoints, checking the DP20–24 mapping.
Captures the initial state and device identity into Git-ignored baseline_state.json if no baseline exists.
Saves the Git-ignored .env with an optional identity guard only after successful verification.
It does not overwrite an existing baseline. A different-device or legacy baseline without an identity must be backed up and manually removed before creating a new one. To migrate a legacy baseline safely, rename baseline_state.json to baseline_state.backup.json in the local project directory, then run the wizard again with the same configured device; the new baseline will be captured from a fresh read-only status response. Both filenames are Git-ignored. Do not copy an old device's baseline into a new device installation. An incompatible or unreachable bulb leaves the previous .env unchanged. If the bulb is in scene/music mode, switch to white/colour in the app before setup. The --no-verify option bypasses verification and still saves configuration; do not use state-changing tools before confirming compatibility.
The network scan may create an ignored snapshot.json file. Avoid the separate TinyTuya wizard here because it can persist additional credentials in local files. Never share the local key in chat or version control.
Configuration
Variable | Description |
TUYA_BULB_DEVICE_ID | Device identity |
TUYA_BULB_IP | Local IPv4 address; a DHCP reservation is recommended |
TUYA_BULB_VERSION | 3.3 or 3.4 |
TUYA_BULB_LOCAL_KEY | Secret local device key |
TUYA_BULB_EXPECTED_DEVICE_ID | Optional identity guard, enforced by the server |
Re-pairing or factory reset may rotate the key. When configuring a different bulb, review or delete the local baseline before capturing its initial state.
MCP client integration
The MCP server uses JSON-RPC over stdio and does not listen for incoming HTTP traffic. TinyTuya makes outgoing LAN connections to the device (typically TCP 6668).
Hermes Agent: In the mcp_servers section of ~/.hermes/config.yaml, use paths appropriate for your installation:
mcp_servers:
tuya-bulb:
command: "C:/path/to/tuya-bulb-mcp/.venv/Scripts/python.exe"
args: ["C:/path/to/tuya-bulb-mcp/tuya_bulb_mcp_server.py"]
timeout: 120Use the venv bin/python on Linux/macOS. In Hermes, run /reload-mcp after changing config, and check with hermes mcp test tuya-bulb. Only edit or reload a client's configuration when you explicitly intend to change that installation; testing a separate checkout does not require editing an existing MCP registration.
Claude Desktop or other stdio clients:
{
"mcpServers": {
"tuya-bulb": {
"command": "C:/path/to/tuya-bulb-mcp/.venv/Scripts/python.exe",
"args": ["C:/path/to/tuya-bulb-mcp/tuya_bulb_mcp_server.py"]
}
}
}Replace example paths with your actual Python and server locations. Do not place device credentials in the client configuration. The optional agent skill helps compatible agents select tools directly, but is not required to use the MCP server.
First-use examples
After your MCP client detects the four tools, try these requests in the AI client chat (not in PowerShell):
What you say | What the MCP server does |
"What's the current bulb status?" | Calls |
"Turn on the bulb." / "Turn off the bulb." | Calls |
"Set the bulb to blue." | Uses |
"Set brightness to 40%." | Uses |
"Set the colour temperature to 70%." | Uses |
"Restore the saved baseline." | Uses |
The baseline is the first verified setup snapshot, not a factory reset; restoring it can change the light. The specific AI client decides how to translate chat requests into MCP tool calls.
Tools
Tool | Purpose |
get_status() | Read power, mode, brightness, temperature, colour and raw datapoints |
turn_on() / turn_off() | Change DP20 only when necessary and verify the power state |
set_state(...) | Set mode, colour, HSV values, white brightness, temperature or restore baseline |
State parameters:
Parameter | Supported values |
mode | white or colour |
color | red, orange, yellow, green, cyan, blue, purple, pink or white |
hue | 0–360 |
saturation, value | 0–100% |
brightness | 1–100% |
temperature | 0–100% (warm to cool) |
preset | baseline |
Examples: set_state(color="blue"), set_state(brightness=40), set_state(preset="baseline").
The baseline restores the first verified setup snapshot for the configured device, not factory defaults. If absent, legacy, invalid or for another device, restoration fails without writing. The device firmware may switch to white mode after brightness/temperature updates, so the server orders writes for compatible firmware. If the device is in scene/music mode, set_state(mode="white") or set_state(mode="colour") can exit it; colour/brightness/temperature changes are deferred until the device has exited that mode. The baseline preset may exit scene/music only when no DP22/23/24 changes are needed.
Brightness and temperature requests use whole-number percentages mapped to DP22/23 in steps of 10; a raw value such as 475 cannot be requested directly through the percentage API. The captured baseline stores and restores raw datapoints without rounding.
Verification uses ACK or fresh status where appropriate. An unverified write is reported as an error; no automatic recovery writes are sent. A failed sequence might have partially changed the device.
Safety and troubleshooting
Keep
.env,baseline_state.json, and scan/credential files out of Git. The.gitignorealso covers dated scan dumps andbaseline_state.backup.json, but ignore rules do not protect against explicitly forced commits; inspectgit statusbefore publishing.Never paste a device local key into public bug reports or screenshots. If a key is exposed, rotate it through the device's supported pairing flow.
No arbitrary datapoint write tool is provided; only DP20–24 are written. DP25/26/34 are not modified.
Device compatibility must be checked before writing; optional identity guard prevents misconfigured targets.
If scanning fails, check Wi-Fi isolation and router device listings.
If status fails, check the key, version, IP address and supported DP scheme.
If baseline restore fails, complete read-only setup and verify the baseline identity. Back up and manually delete an old/unidentified snapshot before recapturing.
Versions 3.3 and 3.4 are the validated configuration targets; other TinyTuya-supported versions require explicit compatibility work.
On Windows, .env inherits its directory ACLs. Keep installation in a user-only folder and review permissions on shared machines.
If tools are absent, check venv and client paths, MCP configuration and reload/restart.
Project layout
tuya_bulb_mcp_server.py — stdio MCP server
setup_wizard.py — read-only setup and compatibility check
tuya_config.py — shared, minimal
.envparserbaseline_state.example.json — sample snapshot format (not real device state)
skills/tuya-bulb-mcp/SKILL.md — optional agent guidance
Credits and license
MIT © 2026 Can Yurtaçan. Built on TinyTuya and the MCP Python SDK.
This server cannot be deployed
Maintenance
Related MCP Connectors
Control your existing Philips lights, Sonos speakers, Roborock vacuums and other supported devices through Port OS cloud. Give ChatGPT, Claude and other MCP-compatible assistants access to the devices you connect. Turn off the living room lights, play music on your speakers, adjust the thermostat, run a vacuum in a room, check a camera snapshot or find a connected tracker. Available actions depend on your linked provider accounts and each device’s supported capabilities. Port OS runs in the cloud; no local server is required. You choose the account, device and capability permissions each assistant receives. Device operations require user OAuth; public tool discovery does not grant device access. Port OS is in alpha. Setup: https://portoperatingsystem.com/docs/getting-started/ Support: https://portoperatingsystem.com/contact/
Use AI models for chat, image, and video generation from Claude Code and other MCP hosts.
Connect any AI agent to 1,000+ apps and 27,000+ actions through one remote MCP server (OAuth).
Automate 1,000+ services from any MCP-compatible AI agent: build Applets, run actions and queries.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables control and monitoring of Home Assistant smart home devices through MCP protocol. Automatically manages authentication tokens and provides simplified tools for device discovery, switch control, and light brightness adjustment.MIT
- AlicenseAqualityFmaintenanceEnables AI assistants to control Tuya/Smart Life smart home devices via tools like on/off, brightness, color, and custom commands.1061 PyPI1MIT
- AlicenseNot gradedqualityCmaintenanceEnables control of local Xiaomi smart home devices via MCP, allowing reading real-time status and setting properties through natural language, without relying on the Xiaomi cloud.MIT
- AlicenseAqualityBmaintenanceEnables controlling smart bulbs over IP with power, brightness, and color adjustments, plus real-time state queries and a mock mode for testing.7ISC