插入式MCP服务器
基于TypeScript的模型上下文协议(MCP)服务器,用于Plugwise智能家居与自动网络发现的集成。
✨ 主要特点
- 🤖 AI代理模式:通过内置AI代理进行自然语言控制
- 📡 JSON-RPC支持:用于脚本编写和自动化的程序化API
- 🔍 自动网络扫描:发现网络上的所有Plugwise集线器
- 🔐 凭据管理:从.env文件安全地存储集线器密码
- 🔌 设备控制:控制恒温器、开关和智能插头
- 🌡️ 温度管理:设置温度、预设值和时间表
- 📊 能源监测:读取功耗和传感器数据
- 🏠 多中心支持:同时管理多个网关
- 🔄 实时更新:获取当前设备状态和测量值
🚀 快速开始
通过npm安装(推荐)
全局安装以与任何MCP客户端一起使用:
npm install -g plugwise-mcp-server或者直接与npx一起使用(无需安装):
npx plugwise-mcp-server从源安装
git clone https://github.com/Tommertom/plugwise-mcp-server.git
cd plugwise-mcp-server
npm install
npm run build先决条件
- Node.js 17或更高版本
- npm或纱线
- Plugwise网关(Adam、Anna、Smile P1或Stretch)
快速测试
使用模拟模式在没有真实硬件的情况下测试安装:
# Test all read operations
npm run test:read-only -- --mock
# Test protocol features
npm run test:features -- --mock或者使用真正的硬件:
# Set up gateway credentials
echo "PLUGWISE_HOST=192.168.1.100" > .env
echo "PLUGWISE_PASSWORD=your-gateway-password" >> .env
# Run tests
npm run test:read-only看 快速测试指南 更多选择。
启动服务器
选项1:标准MCP服务器 (15+专用工具)
通过npm安装时:
plugwise-mcp-server从源代码运行时:
npm start选项2:AI代理模式 (单一自然语言工具)
# Interactive mode with prompt
npm run agent "List my devices"
npm run agent "Set living room to 21 degrees"
# Interactive with verbose debugging
npm run agent "What's the power usage?" -- -v
# MCP server mode (no arguments)
npm run agent
# JSON-RPC mode (for scripting)
npm run agent -- --jsonrpc
echo '{"jsonrpc":"2.0","method":"execute","params":{"instruction":"List devices"},"id":1}' | npm run agent -- --jsonrpc看 代理文件 和 JSON-RPC模式 了解详情。
🔌 将MCP服务器添加到客户端
Plugwise MCP服务器可以与任何支持标准I/O(stdio)作为传输介质的MCP客户端一起工作。从以下选项中选择:
- 标准模式:15+用于直接设备控制的专用工具
- 代理模式:单人
manage_plugwise具有自然语言界面的工具
克劳德桌面版
标准模式 (15+工具):
{
"mcpServers": {
"plugwise": {
"command": "npx",
"args": ["-y", "plugwise-mcp-server@latest"],
"env": {
"HUB1": "abc12345",
"HUB1IP": "192.168.1.100",
"HUB2": "def67890",
"HUB2IP": "192.168.1.101"
}
}
}
}代理模式 (自然语言):
{
"mcpServers": {
"plugwise-agent": {
"command": "node",
"args": ["/path/to/plugwise/dist/cli/plugwise-agent-cli.js"],
"env": {
"OPENAI_API_KEY": "sk-...",
"PLUGWISE_AGENT_MODEL": "gpt-4o-mini"
}
}
}
}克莱恩
要配置Cline以使用Plugwise MCP服务器,请编辑 cline_mcp_settings.json 文件。您可以通过单击Cline窗格顶部的MCP服务器图标,然后单击配置MCP服务器按钮来打开或创建此文件。
{
"mcpServers": {
"plugwise": {
"command": "npx",
"args": ["-y", "plugwise-mcp-server@latest"],
"disabled": false,
"env": {
"HUB1": "abc12345",
"HUB1IP": "192.168.1.100",
"HUB2": "def67890",
"HUB2IP": "192.168.1.101"
}
}
}
}光标
要配置Cursor以使用Plugwise MCP服务器,请编辑以下文件之一 .cursor/mcp.json (仅配置特定项目)或文件 ~/.cursor/mcp.json (使MCP服务器在所有项目中可用):
{
"mcpServers": {
"plugwise": {
"command": "npx",
"args": ["-y", "plugwise-mcp-server@latest"],
"env": {
"HUB1": "abc12345",
"HUB1IP": "192.168.1.100",
"HUB2": "def67890",
"HUB2IP": "192.168.1.101"
}
}
}
}Visual Studio代码副本
要配置单个项目,请编辑 .vscode/mcp.json 工作区中的文件:
{
"servers": {
"plugwise": {
"type": "stdio",
"command": "npx",
"args": ["-y", "plugwise-mcp-server@latest"],
"env": {
"HUB1": "abc12345",
"HUB1IP": "192.168.1.100",
"HUB2": "def67890",
"HUB2IP": "192.168.1.101"
}
}
}
}要使服务器在您打开的每个项目中都可用,请编辑您的用户设置:
{
"mcp": {
"servers": {
"plugwise": {
"type": "stdio",
"command": "npx",
"args": ["-y", "plugwise-mcp-server@latest"],
"env": {
"HUB1": "abc12345",
"HUB1IP": "192.168.1.100",
"HUB2": "def67890",
"HUB2IP": "192.168.1.101"
}
}
}
}
}Windsurf编辑器
要配置Windsurf编辑器,请编辑文件 ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"plugwise": {
"command": "npx",
"args": ["-y", "plugwise-mcp-server@latest"],
"env": {
"HUB1": "abc12345",
"HUB1IP": "192.168.1.100",
"HUB2": "def67890",
"HUB2IP": "192.168.1.101"
}
}
}
}环境变量
服务器从环境变量中读取集线器密码。您可以通过两种方式提供这些:
选项1:MCP配置(推荐) 添加 env 字段直接指向您的MCP客户端配置,如上述示例所示。
选项2:.env文件 创建一个 .env 在项目根目录中创建文件或设置系统范围的环境变量:
# Hub passwords (8-character codes from gateway stickers)
HUB1=abc12345
HUB2=def67890
# Optional: Known IP addresses for faster discovery and auto-loading
HUB1IP=192.168.1.100
HUB2IP=192.168.1.101安全说明:使用MCP配置时 env 字段中,凭据被安全地传递给服务器进程。为了增强安全性,请考虑使用 .env 通常被排除在版本控制之外的文件。
快速测试
# Automatically discover and connect to your hubs
node scripts/workflow-demo.js📡 MCP工具
网络发现
connect
连接到Plugwise网关。
// Connect to specific hub
await mcpClient.callTool('connect', { host: '192.168.1.100' });
// Manual connection
await mcpClient.callTool('connect', {
host: '192.168.1.100',
password: 'abc12345'
});设备管理
get_devices
获取所有设备及其当前状态。
const result = await mcpClient.callTool('get_devices', {});
// Returns all devices, zones, sensors, and their current values气候控制
set_temperature
设置恒温器温度设定点。
await mcpClient.callTool('set_temperature', {
location_id: 'zone123',
setpoint: 21.0
});set_preset
更改恒温器预设模式。
await mcpClient.callTool('set_preset', {
location_id: 'zone123',
preset: 'away' // Options: home, away, sleep, vacation
});设备控制
control_switch
打开或关闭开关/插头。
await mcpClient.callTool('control_switch', {
appliance_id: 'plug123',
state: 'on' // 'on' or 'off'
});网关管理
set_gateway_mode:设置网关模式(家庭、外出、度假)set_dhw_mode:设置家用热水模式(自动、增压、舒适、关闭)set_regulation_mode:设置加热调节模式delete_notification:清除网关通知reboot_gateway:重新启动网关(小心使用)
MCP资源
plugwise://devices:作为资源访问所有设备的当前状态
MCP提示
setup_guide:获取全面的分步设置说明
🧪 测试
全面的只读测试套件
npm run test:all这将对所有只读MCP操作进行完整测试:
- ✅ 服务器健康检查
- ✅ MCP协议初始化
- ✅ 集线器的网络扫描
- ✅ 网关连接和信息检索
- ✅ 设备状态读取
- ✅ 资源和提示
安全:仅测试读取操作,从不更改设备状态。
看 测试文档 了解详情。
完整的工作流演示
node scripts/workflow-demo.js这表明:
- ✅ 使用.env密码进行网络扫描
- ✅ 无凭据自动连接
- ✅ 设备发现和列表
- ✅ 多中心管理
网络扫描测试
node scripts/test-network-scan.js完整的MCP测试套件
node scripts/test-mcp-server.js用于中心发现的Bash脚本
./scripts/find-plugwise-hub.sh🏗️ 支持设备
网关
- 亚当:支持OpenTerm的智能家居中心(恒温器控制、地暖)
- 安娜:独立恒温器网关
- 微笑P1:能源监测网关(电力、天然气、太阳能)
- 伸展:用于连接Circle智能插头的传统集线器
联网设备
- 吉普:带照度检测的运动传感器
- 丽莎:散热器阀(需要轮毂)
- 汤姆/地板:地暖控制器
- 柯恩:散热器阀(需要一个塞子作为中介)
- 插头:带电源监控的智能插头(Zigbee)
- Aqara插头:第三方Zigbee智能插头
- 圆形:传统圆形/圆形+插头(仅通过Stretch)
📖 文档
🔧 发展
发展模式
使用热重载运行:
npm run dev构建
将TypeScript编译为JavaScript:
npm run build项目结构
plugwise/
├── src/mcp/ # TypeScript source
│ ├── server.ts # MCP server with tools
│ ├── plugwise-client.ts # Plugwise API client
│ └── plugwise-types.ts # Type definitions
├── build/mcp/ # Compiled JavaScript
├── docs/ # Documentation
├── scripts/ # Test scripts
│ ├── workflow-demo.js
│ ├── test-network-scan.js
│ ├── test-mcp-server.js
│ └── find-plugwise-hub.sh
├── .env # Hub credentials
├── package.json
└── tsconfig.json🔐 安全
- 密码存储:将密码存储在
.env仅文件(从不在代码中) - Git忽略:
.env在...里.gitignore防止泄露秘密 - 网络安全:Plugwise使用HTTP基本身份验证(不是HTTPS)
- 将网关保持在安全的本地网络上 - 使用VPN进行远程访问 - 为物联网设备考虑单独的VLAN
- API访问:API完全控制您的供暖系统-相应地限制访问
🐛 故障排除
扫描过程中未找到集线器
- 检查
.env文件具有HUB1,HUB2等定义 - 验证密码是否正确(区分大小写,检查网关标签)
- 确保网关已通电并连接到网络
- 确认您与集线器位于同一网络上
- 尝试:
ping测试连接性
连接错误
- 验证IP地址是否正确
- 检查防火墙没有阻塞端口80
- 手动连接测试:
curl http:///core/domain_objects - 确保网关不会因请求而过载
🤝 集成示例
使用Claude代码
claude mcp add --transport http plugwise-server http://localhost:3000/mcp与VS代码副本一起使用
添加到 .vscode/mcp.json:
{
"mcpServers": {
"plugwise": {
"type": "http",
"url": "http://localhost:3000/mcp"
}
}
}使用MCP检查器
npx @modelcontextprotocol/inspector连接到: http://localhost:3000/mcp
📊 示例工作流
晨间日常
// Connect to hub
await mcpClient.callTool('connect', { host: '192.168.1.100' });
// Set home mode
await mcpClient.callTool('set_preset', {
location_id: 'living_room',
preset: 'home'
});
// Warm up bathroom
await mcpClient.callTool('set_temperature', {
location_id: 'bathroom',
setpoint: 22.0
});能源监测
const devices = await mcpClient.callTool('get_devices', {});
for (const [id, device] of Object.entries(devices.data)) {
if (device.sensors?.electricity_consumed) {
console.log(`${device.name}: ${device.sensors.electricity_consumed}W`);
}
}多中心管理
// List all hubs
const hubsList = await mcpClient.callTool('list_hubs', {});
// Get devices from each hub
for (const hub of hubsList.hubs) {
await mcpClient.callTool('connect', { host: hub.ip });
const devices = await mcpClient.callTool('get_devices', {});
console.log(`Hub ${hub.ip}: ${Object.keys(devices.data).length} devices`);
}📚 文档
迁移指南
建筑与设计
实施指南
快速参考
测试与开发
发布和设置
🌟 鸣谢
基于优秀 python插件 图书馆。
建筑图案灵感来自 sonos ts mcp.
📄 许可证
MIT许可证-有关详细信息,请参阅许可证文件
🚀 版本
当前版本: 1.0.2
- ✅ 完全支持MCP协议
- ✅ 自动网络扫描
- ✅ 多中心管理
- ✅ 完整的设备控制
- ✅ 全面的文件
- ✅ 结构迁移规划
