物联网设备协调器

使用模型上下文协议(MCP)和LangChain ReAct风格的代理协调多个物联网设备系列(Hue、Nest、Locks、Sony TV)的操作。

  • by kjpou1
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 kjpou1/simulated-iot-mcp

使用说明

🏡 模拟物联网MCP编排器

该项目演示了如何使用 模型上下文协议(MCP) 与LangChain ReAct风格的代理合作。每个设备生态系统都作为自己的MCP服务器运行,代理协调它们之间的工具调用。

✨ 示例用法

从命令行:

uv run main.py "Lock the front door and power on the TV and set the lights to netflix and chill"

🔄 代理编排流程

  1. 解析用户的自然语言请求。
  2. 从以下选项中选择合适的工具 多个MCP服务器.
  3. 按顺序调用每个工具(lock_door, power_on, set_color, set_brightness).
  4. 返回干净、人类可读的结果。

✅ 示例输出

The front door has been locked, the TV is powered on, and the living room lights have been set to a warm white color with a brightness level of 40% for a cozy "Netflix and chill" vibe. Enjoy your time!

📊 多服务器序列图

sequenceDiagram
    participant User
    participant LangChain_Agent
    participant Locks_Server
    participant SonyTV_Server
    participant Hue_Server

    User->>LangChain_Agent: "Lock the front door and power on the TV and set the lights to netflix and chill"
    LangChain_Agent->>Locks_Server: lock_door(door="front")
    Locks_Server-->>LangChain_Agent: { "status": "ok" }

    LangChain_Agent->>SonyTV_Server: power_on()
    SonyTV_Server-->>LangChain_Agent: { "status": "ok" }

    LangChain_Agent->>Hue_Server: set_color(room="living room", color="warm white")
    Hue_Server-->>LangChain_Agent: { "status": "ok" }

    LangChain_Agent->>Hue_Server: set_brightness(room="living room", level=40)
    Hue_Server-->>LangChain_Agent: { "status": "ok" }

    LangChain_Agent-->>User: "The front door has been locked, the TV is powered on, and the living room lights have been set..."