Skip to main content
Glama
ousqi

mcp-tuya-close-door

by ousqi

@osqi/mcp-tuya-close-door

本地运行的 stdio MCP 服务,仅提供一个经过安全确认的 Tuya 卷闸门关门接口。它直接通过局域网连接设备,不依赖 Tuya Cloud、Home Assistant 或 Frigate。

Node.js 20+。此工具只代表本地设备接受了指令,不保证门已物理关闭;应由后续摄像头/视觉 skill 复核。

安全机制

  • 仅公开 tuya_close_door 一个 MCP 工具。

  • 每次调用必须传入 {"confirmation": true}

  • 未同时配置并验证 TUYA_CLOSE_DPSTUYA_CLOSE_VALUE 时,关门功能默认禁用。

  • 下发前会读取本地 DPS 状态;若配置的 DPS 不存在则拒绝执行。

  • 不要提交 .env,也不要在日志、提示词或 issue 中暴露设备 ID、Local Key 或局域网地址。

Related MCP server: eufy-lock-codes

安装

发布后可全局安装:

npm install -g @osqi/mcp-tuya-close-door

或由 MCP host 通过 npx 启动:

npx -y @osqi/mcp-tuya-close-door

可执行命令为:

mcp-tuya-close-door

它只使用标准输入/输出传输 MCP 消息;不要将诊断信息写入 stdout,也不需要开放 HTTP 端口。

配置

复制模板并限制文件权限:

cp .env.example .env
chmod 600 .env
TUYA_DEVICE_ID=你的设备ID
TUYA_LOCAL_KEY="你的16位LocalKey"
TUYA_HOST=192.168.1.50
TUYA_VERSION=3.4
TUYA_PORT=6668

# 仅在独立验证实际关门映射后填写:
TUYA_CLOSE_DPS=6
TUYA_CLOSE_VALUE=false

TUYA_LOCAL_KEY 必须加引号:若密钥包含 #,未加引号时 dotenv 会把后半部分当作注释。

变量

必填

说明

TUYA_DEVICE_ID

本地 Tuya 设备 ID。

TUYA_LOCAL_KEY

设备的 16 位 Local Key。

TUYA_HOST

设备的局域网 IP/主机名;不包含协议或端口。

TUYA_VERSION

本项目只接受已验证的 3.4

TUYA_PORT

设备端口,通常为 6668,范围为 1–65535

TUYA_CLOSE_DPS

经独立验证的关门 DPS 编号。须与 value 一起设置。

TUYA_CLOSE_VALUE

对应关门值,必须是 JSON 标量,例如 false1"close"

未确认 DPS 映射时,请不要填写最后两个变量。可使用仓库中未发布的 scripts/inspect-tuya.mjs 做只读检查,并在官方 App 中人工确认物理门与 DPS 的对应关系。

获取 Tuya 本地参数

本 MCP 运行时只连接局域网设备,但首次取得设备元数据的官方路径通常需要 Tuya Developer Platform 的 App 账户授权。不同 OEM、固件和网关设备的支持情况不同;不要根据产品名称猜测 DPS、值或协议版本。

本 MCP 变量

Tuya 名称

推荐来源

TUYA_DEVICE_ID

Device ID / devId

Developer Platform 的设备列表或设备详情。

TUYA_LOCAL_KEY

local_key

授权项目的设备详情/API。

TUYA_HOST

ip

路由器/DHCP 客户端列表,或设备详情。

TUYA_VERSION

LAN 协议版本

本地只读探测的成功结果。

TUYA_PORT

本地 TCP 端口

常见默认值为 6668,但须实际验证。

TUYA_CLOSE_DPS / TUYA_CLOSE_VALUE

数字 DPS 与值

本地观察与独立物理验证。

Device ID 和 Local Key

  1. 登录 Tuya Developer Platform,创建或选择与 Smart Life/Tuya Smart 账户同一区域的项目。

  2. 进入 Devices → Link Tuya App Account → Add App Account,用 App 扫码并确认授权。

  3. Devices → All Devices 中选择目标设备,复制 Device ID

  4. 通过 Debug Device 或授权后的设备详情 API 取得 local_key、当前 ip 和在线状态。

  5. Device ID 填入 TUYA_DEVICE_ID,将 local_key 原样加双引号填入 TUYA_LOCAL_KEY

Smart Life App 通常不能直接显示 Local Key。删除重加设备、恢复出厂或重新配网后,Local Key 和 IP 可能变化,必须重新取得并验证。不要将 Local Key、平台 Access ID/Secret 或令牌写入日志、issue 或聊天消息。

官方参考:

IP、端口和协议版本

在路由器/DHCP 客户端列表中按设备 MAC 或名称查找当前 IP,填入 TUYA_HOST。建议为设备保留 DHCP 租约。主机变量只填 IP/主机名,例如 192.168.1.50,不要填写 http://:6668

填入已知的 Device ID、Local Key、IP 和端口后,可运行只读探测:

node scripts/inspect-tuya.mjs

该脚本会尝试本地协议并读取 DPS;不会调用 set() 或发送开关门指令。若输出 protocolVersion: 3.4dps,设置:

TUYA_VERSION=3.4
TUYA_PORT=6668

本 MCP 只接受本项目已验证的 3.4。若探测仅在其他版本成功,请勿强行绕过限制。

确认关门 DPS 与值

仅发现某个 DPS 存在,不能证明它是“关门”。安全流程:

  1. 保持 TUYA_CLOSE_DPSTUYA_CLOSE_VALUE 未设置,让 MCP 关门功能保持禁用。

  2. 运行 node scripts/inspect-tuya.mjs,保存 DPS 基线。

  3. 确认门体活动区域安全后,通过官方 App 对已确认的目标门做一次人工操作。

  4. 可同时运行 node scripts/listen-tuya.mjs,观察 App 操作引起的 DPS 变化;它只监听,不会控制门。

  5. 只有经独立物理验证确认“此 DPS + 此 JSON 值”确实为目标门关门操作后,才写入 .env

部分设备限制并发 LAN 连接;监听时不要长期运行多个本地客户端。监听输出可能暴露运行状态,不应公开。

TUYA_CLOSE_VALUE 是 JSON 标量,以下值类型不同:

TUYA_CLOSE_VALUE=false
TUYA_CLOSE_VALUE=1
TUYA_CLOSE_VALUE='"close"'

最后一项才是 JSON 字符串 "close"。更新 .env 后重启 MCP 服务。

Hermes / MCP Host 示例

推荐直接由 host 注入环境变量,而非依赖当前工作目录的 .env

{
  "mcpServers": {
    "tuya-close-door": {
      "command": "npx",
      "args": ["-y", "@osqi/mcp-tuya-close-door"],
      "env": {
        "TUYA_DEVICE_ID": "你的设备ID",
        "TUYA_LOCAL_KEY": "你的16位LocalKey",
        "TUYA_HOST": "192.168.1.50",
        "TUYA_VERSION": "3.4",
        "TUYA_PORT": "6668",
        "TUYA_CLOSE_DPS": "6",
        "TUYA_CLOSE_VALUE": "false"
      }
    }
  }
}

全局安装时,将 command 改为 mcp-tuya-close-door

MCP 工具

tuya_close_door

向已配置的设备发送一次本地关门指令。

{ "confirmation": true }

未传确认或非 true 值会被拒绝。命令接受成功仅表示本地 Tuya 设备接受请求;请用摄像头或其他独立方式验证门已关闭。

开发与发布

npm ci
npm test
npm pack --dry-run

确认 tarball 不包含 .env 后,再发布公开 scoped 包:

npm login
npm publish --access public

建议为 npm 账户启用 2FA。发布后可使用:

npx -y @osqi/mcp-tuya-close-door

License

MIT

Available Tools

1 tool
tuya_close_doorA

Send the configured local close command only after explicit confirmation.

ParametersJSON Schema
NameRequiredDescriptionDefault
confirmationYes

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full behavioral burden. It discloses the confirmation-gated behavior and that the command is local, but it does not mention possible side effects, failure modes, or whether the action is reversible. This is a meaningful but incomplete behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence of ten words, front-loads the action, and has no redundant phrasing. Every word contributes to understanding the tool's purpose and the key invocation condition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a one-parameter command tool, the description is mostly sufficient, but it omits details about error handling, what happens if confirmation is false, and the nature of the 'configured local close command.' An agent can likely call it correctly, but not with full confidence about consequences.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has no parameter descriptions, but the description explains the core meaning of the single 'confirmation' boolean: the close command should only be sent after explicit confirmation. This adds semantic value beyond the schema and implies that confirmation must be true to trigger the action.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific action ('Send') and object ('configured local close command'), which clearly maps to the tool's purpose of closing a door. It does not differentiate from siblings, but no siblings exist, so this is not a meaningful gap.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrase 'only after explicit confirmation' directly tells the agent when it is appropriate to invoke the tool: if and only if the user has explicitly confirmed. It does not discuss alternatives, but with no sibling tools this is acceptable context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev0.1.1
    • First observedtuya_close_door

TDQS

A4.2/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of confusion or overlapping purposes. The tool is trivially distinct and unambiguous.

Naming Consistency5/5

The single tool follows a clear snake_case verb_noun convention with a vendor prefix (tuya_close_door), matching the server name. There are no competing conventions to create inconsistency.

Tool Count5/5

One tool is exactly appropriate for a server whose stated purpose is a single specific action: closing a door via Tuya. The narrow scope justifies the minimal count, and the tool clearly earns its place.

Completeness5/5

For the declared domain of closing a door, the tool fully covers the action and even embeds the explicit confirmation requirement into its behavior. A status or dry-run tool would be a minor enhancement, not an obvious gap.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables 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
  • A
    license
    Not graded
    quality
    B
    maintenance
    A local MCP server for managing Eufy smart-lock access codes across rental properties, with safety features like dry-run planning and explicit confirmation for write operations.
    AGPL 3.0
  • F
    license
    Not graded
    quality
    C
    maintenance
    An MCP approval gate that ensures agents execute only human-approved, hash-verified actions, providing fail-closed consent for consequential operations.
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables safely inspecting and configuring Hikvision cameras via a local MCP server, with permission enforcement, read-only diagnostics, and supervised mutation flows.
    MIT