modelscope·@jango-blockchained/advanced-homeassistant-mcp
暂无描述。
一种标准化协议,用于AI助手与Home Assistant进行交互,提供安全、类型化且可扩展的接口来控制智能家居设备。
Model Context Protocol (MCP) 服务器作为AI模型(如Claude, GPT等)与Home Assistant之间的桥梁,使AI助手能够:
bash
git clone https://github.com/your-repo/homeassistant-mcp.git
cd homeassistant-mcp npm install
npm run build
bash
npm start -- --stdio
npm start -- --http
npm start -- --stdio --http
通过环境变量或.env文件配置服务器:
dotenv
PORT=3000 NODE_ENV=development
EXECUTION_TIMEOUT=30000 STREAMING_ENABLED=true
USE_STDIO_TRANSPORT=true USE_HTTP_TRANSPORT=true
DEBUG_MODE=false DEBUG_STDIO=false DEBUG_HTTP=false SILENT_STARTUP=false
CORS_ORIGIN=*
MCP服务器采用分层架构构建:
工具是向MCP服务器添加功能的主要方式。每个工具:
示例工具注册:
typescript import { LightsControlTool } from "./tools/homeassistant/lights.tool.js"; import { ClimateControlTool } from "./tools/homeassistant/climate.tool.js";
// 注册工具 server.registerTool(new LightsControlTool()); server.registerTool(new ClimateControlTool());
当使用HTTP传输时,服务器提供JSON-RPC 2.0 API:
POST /api/mcp/jsonrpc - 执行一个工具GET /api/mcp/stream - 连接到SSE流以获取实时更新GET /api/mcp/info - 获取服务器信息GET /health - 健康检查端点typescript import { createClaudeToolDefinitions } from "./mcp/index.js";
// 生成Claude兼容的工具定义 const claudeTools = createClaudeToolDefinitions([ new LightsControlTool(), new ClimateControlTool() ]);
// 与Claude API一起使用 const messages = [ { role: "user", content: "打开客厅的灯" } ];
const response = await claude.messages.create({ model: "claude-3-opus-20240229", messages, tools: claudeTools });### 游标集成
要将 Home Assistant MCP 服务器与 Cursor 一起使用,请在您的 .cursor/config/config.json 文件中添加以下内容:
json { "mcpServers": { "homeassistant-mcp": { "command": "bash", "args": ["-c", "cd ${workspaceRoot} && bun run dist/index.js --stdio 2>/dev/null | grep -E {"jsonrpc":"2.0" "], "env": { "NODE_ENV": "development", "USE_STDIO_TRANSPORT": "true", "DEBUG_STDIO": "true" } } } }
此配置:
{"jsonrpc":"2.0" 的行,确保输出干净的 JSON-RPC 消息如果您在使用 MCP 服务器与 Cursor 时遇到“无法创建客户端”错误:
确保您在 Cursor 配置中使用了正确的命令和参数
bun run build 确保服务器已构建确保服务器正确地将 JSON-RPC 消息输出到 stdout: bash bun run dist/index.js --stdio 2>/dev/null | grep -E {"jsonrpc":"2.0" > json_only.txt
然后检查 json_only.txt 以验证它只包含有效的 JSON-RPC 消息。
确保您的系统上安装了 grep(大多数系统默认应该可用)
尝试使用以下命令重新构建服务器: bash bun run build
通过在环境变量中设置 DEBUG_STDIO=true 启用调试模式
如果问题仍然存在,您可以尝试:
MIT
欢迎贡献!请随时提交 Pull Request。
MCP(Model Context Protocol)服务器是我为 Home Assistant 设计的轻量级集成工具,提供灵活的设备管理和自动化接口。它设计得快速、安全且易于使用。使用 Bun 构建以实现最大性能。
我选择 Bun 作为运行时有几个关键优势:
⚡ 极快的性能
🎯 一站式解决方案
🔋 内置功能
💾 资源高效
🔄 Node.js 兼容性
克隆我的仓库: bash git clone https://github.com/jango-blockchained/homeassistant-mcp.git cd homeassistant-mcp
设置环境: bash
chmod +x scripts/setup-env.sh
./scripts/setup-env.sh
NODE_ENV=production ./scripts/setup-env.sh
./scripts/setup-env.sh --force
.env 文件并填写您的 Home Assistant 详细信息HASS_TOKEN(长期访问令牌)./docker-build.sh
docker compose up -d
我的 Docker 构建脚本 (docker-build.sh) 支持不同的配置:
bash ./docker-build.sh
bash ./docker-build.sh --speech
onerahmet/openai-whisper-asr-webservicerhasspy/wyoming-openwakewordbash ./docker-build.sh --speech --gpu
一座通过串行通信将物理硬件设备与人工智能大语言模型连接起来的桥梁,允许用户使用自然语言命令控制硬件。
一种多功能的模型上下文协议服务器,使人工智能助手能够管理日历、跟踪任务、处理电子邮件、搜索网络以及控制智能家居设备。
暂无描述。
暂无描述。
暂无描述。
暂无描述。