mcp2mqtt logo

mcp2mqtt

Community
mcp2everything

本项目通过将 MCP 协议转换为 MQTT 协议,我们能够利用强大的大型语言模型(LLMs),就能轻松操控您的智能家居、机器人或其他硬件设备。

Publishermcp2everything
Repositorymcp2mqtt
LanguagePython
Forks
60
Stars
372
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    mcp2mqtt exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    372 stars and 60 forks from the linked repository.

mcp2mqtt: 连接物理世界与AI大模型的桥梁

English | 简体中文

系统架构

工作流程

项目愿景

mcp2mqtt 是一个将物联网设备接入AI大模型的项目,它通过 Model Context Protocol (MCP) 和 MQTT 协议将物理世界与 AI 大模型无缝连接。最终实现:

  • 用自然语言控制你的硬件设备
  • AI 实时响应并调整物理参数
  • 让你的设备具备理解和执行复杂指令的能力
  • 通过MQTT协议实现设备间的互联互通

主要特性

  • 智能MQTT通信

    • 支持MQTT协议的发布/订阅模式
    • 支持多种MQTT服务器(如Mosquitto、EMQ X等)
    • 支持QoS服务质量保证
    • 支持主题过滤和消息路由
    • 实时状态监控和错误处理
  • MCP 协议集成

    • 完整支持 Model Context Protocol
    • 支持资源管理和工具调用
    • 灵活的提示词系统
    • 通过MQTT实现命令的发布与响应

配置说明

MQTT配置

yaml
mqtt:
  broker: "localhost"  # MQTT服务器地址
  port: 1883  # MQTT服务器端口
  client_id: "mcp2mqtt_client"  # MQTT客户端ID
  username: "mqtt_user"  # MQTT用户名
  password: "mqtt_password"  # MQTT密码
  keepalive: 60  # 保持连接时间
  topics:
    command:
      publish: "mcp/command"  # 发送命令的主题
      subscribe: "mcp/response"  # 接收响应的主题
    status:
      publish: "mcp/status"  # 发送状态的主题
      subscribe: "mcp/control"  # 接收控制命令的主题

命令配置

yaml
commands:
  set_pwm:
    command: "CMD_PWM {frequency}"
    need_parse: false
    data_type: "ascii"
    prompts:
      - "把PWM调到最大"
      - "把PWM调到最小"
    mqtt_topic: "mcp/pwm"  # MQTT发布主题
    response_topic: "mcp/pwm/response"  # MQTT响应主题

MQTT 命令和响应

命令格式

命令使用简单的文本格式:

  1. PWM 控制:

    • 命令:PWM {值}
    • 示例:
      • PWM 100(最大值)
      • PWM 0(关闭)
      • PWM 50(50%)
    • 响应:CMD PWM {值} OK
  2. LED 控制:

    • 命令:LED {状态}
    • 示例:
      • LED on(打开)
      • LED off(关闭)
    • 响应:CMD LED {状态} OK
  3. 设备信息:

    • 命令:INFO
    • 响应:CMD INFO {设备信息}

错误响应

如果发生错误,响应格式将为: ERROR: {错误信息}

支持的客户端

mcp2mqtt 支持所有实现了 MCP 协议的客户端,以及支持MQTT协议的物联网设备:

客户端类型特性支持说明
Claude Desktop完整支持推荐使用,支持所有 MCP 功能
Continue完整支持优秀的开发工具集成
Cline资源+工具支持多种 AI 提供商
MQTT设备发布/订阅支持所有MQTT协议的物联网设备

快速开始

1. 安装

Windows用户

下载 install.py

bash
python install.py

macOS用户

bash
# 下载安装脚本
curl -O https://raw.githubusercontent.com/mcp2everything/mcp2mqtt/main/install_macos.py

# 运行安装脚本
python3 install_macos.py

Ubuntu/Raspberry Pi用户

bash
# 下载安装脚本
curl -O https://raw.githubusercontent.com/mcp2everything/mcp2mqtt/main/install_ubuntu.py

# 运行安装脚本
python3 install_ubuntu.py

安装脚本会自动完成以下操作:

  • 检查系统环境
  • 安装必要的依赖
  • 创建默认配置文件
  • 配置Claude桌面版(如果已安装)

手动分步安装依赖

bash
windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
MacOS
curl -LsSf https://astral.sh/uv/install.sh | sh

主要依赖uv工具,所以当python和uv以及Claude或Cline安装好后就可以了。

基本配置

在你的 MCP 客户端(如 Claude Desktop 或 Cline)配置文件中添加以下内容: 注意:如果使用的自动安装那么会自动配置Calude Desktop无需此步。 使用默认配置文件:

json
{
    "mcpServers": {
        "mcp2mqtt": {
            "command": "uvx",
            "args": [
                "mcp2mqtt"
            ]
        }
    }
}

注意:修改配置后需要重启Cline或者Claude客户端软件

配置说明

配置文件位置

复制配置文件(config.yaml)可以放在位置: 用户主目录(推荐个人使用)

bash
# Windows系统
C:\Users\用户名\.mcp2mqtt\config.yaml

# macOS系统
/Users/用户名/.mcp2mqtt/config.yaml

# Linux系统
/home/用户名/.mcp2mqtt/config.yaml
  • 适用场景:个人配置
  • 需要创建 .mcp2mqtt 目录:
    bash
    # Windows系统(在命令提示符中)
    mkdir "%USERPROFILE%\.mcp2mqtt"
    
    # macOS/Linux系统
    mkdir -p ~/.mcp2mqtt

指定配置文件: 比如指定加载Pico配置文件:Pico_config.yaml

json
{
    "mcpServers": {
        "mcp2mqtt": {
            "command": "uvx",
            "args": [
                "mcp2mqtt",
                "--config",
                "Pico"  //指定配置文件名,不需要添加_config.yaml后缀
            ]
        }
    }
}

为了能使用多个mqtt,我们可以新增多个mcp2mqtt的服务 指定不同的配置文件名即可。 如果要接入多个设备,如有要连接第二个设备: 指定加载Pico2配置文件:Pico2_config.yaml

json
{
    "mcpServers": {
        "mcp2mqtt2": {
            "command": "uvx",
            "args": [
                "mcp2mqtt",
                "--config",
                "Pico2"  //指定配置文件名,不需要添加_config.yaml后缀
            ]
        }
    }
}

硬件连接

  1. 将你的设备通过网络连接到mqtt服务器
  2. 也可以用tests目录下的responder.py来模拟设备

运行测试

启动设备模拟器

项目在 tests 目录中包含了一个设备模拟器。它可以模拟一个硬件设备,能够:

  • 响应 PWM 控制命令
  • 提供设备信息
  • 控制 LED 状态

启动模拟器:

bash
python tests/responder.py

你应该能看到模拟器正在运行并已连接到 MQTT 服务器的输出信息。

启动客户端Claude 桌面版或Cline

从源码快速开始

  1. 从源码安装
bash
# 通过源码安装:
git clone https://github.com/mcp2everything/mcp2mqtt.git
cd mcp2mqtt

# 创建虚拟环境
uv venv .venv

# 激活虚拟环境
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate

# 安装开发依赖
uv pip install --editable .

MCP客户端配置

在使用支持MCP协议的客户端(如Claude Desktop或Cline)时,需要在客户端的配置文件中添加以下内容: 直接自动安装的配置方式 源码开发的配置方式

使用默认演示参数:

json
{
    "mcpServers": {
        "mcp2mqtt": {
            "command": "uv",
            "args": [
                "--directory",
                "你的实际路径/mcp2mqtt",  // 例如: "C:/Users/Administrator/Documents/develop/my-mcp-server/mcp2mqtt"
                "run",
                "mcp2mqtt"
            ]
        }
    }
}

指定参数文件名

json
{
    "mcpServers": {
        "mcp2mqtt": {
            "command": "uv",
            "args": [
                "--directory",
                "你的实际路径/mcp2mqtt",  // 例如: "C:/Users/Administrator/Documents/develop/my-mcp-server/mcp2mqtt"
                "run",
                "mcp2mqtt",
                "--config", // 可选参数,指定配置文件名
                "Pico"  // 可选参数,指定配置文件名,不需要添加_config.yaml后缀
            ]
        }
    }
}

2. 用户主目录(推荐个人使用)

bash
# Windows系统
C:\Users\用户名\.mcp2mqtt\config.yaml

# macOS系统
/Users/用户名/.mcp2mqtt/config.yaml

# Linux系统
/home/用户名/.mcp2mqtt/config.yaml
  • 适用场景:个人配置
  • 需要创建 .mcp2mqtt 目录:
    bash
    # Windows系统(在命令提示符中)
    mkdir "%USERPROFILE%\.mcp2mqtt"
    
    # macOS/Linux系统
    mkdir -p ~/.mcp2mqtt

3. 系统级配置(适合多用户环境)

bash
# Windows系统(需要管理员权限)
C:\ProgramData\mcp2mqtt\config.yaml

# macOS/Linux系统(需要root权限)
/etc/mcp2mqtt/config.yaml
  • 适用场景:多用户共享配置
  • 创建目录并设置权限:
    bash
    # Windows系统(以管理员身份运行)
    mkdir "C:\ProgramData\mcp2mqtt"
    
    # macOS/Linux系统(以root身份运行)
    sudo mkdir -p /etc/mcp2mqtt
    sudo chown root:root /etc/mcp2mqtt
    sudo chmod 755 /etc/mcp2mqtt

程序会按照上述顺序查找配置文件,使用找到的第一个有效配置文件。根据你的需求选择合适的位置:

  • 开发测试:使用当前目录
  • 个人使用:建议使用用户主目录(推荐)
  • 多用户环境:使用系统级配置(ProgramData或/etc)
  1. 运行服务器:
bash
# 确保已激活虚拟环境
.venv\Scripts\activate

# 运行服务器(使用默认配置config.yaml 案例中用的LOOP_BACK 模拟串口,无需真实串口和串口设备)
uv run src/mcp2mqtt/server.py
或
uv run mcp2mqtt
# 运行服务器(使用指定配置Pico_config.yaml)
uv run src/mcp2mqtt/server.py --config Pico
或
uv run mcp2mqtt --config Pico

文档

Installation

TypingMind
Prerequisites:

Node.js 18+

{
  "mcpServers": {
    "mcp2everything-mcp2mqtt": {
      "command": "uvx",
      "args": [
        "mcp2mqtt"
      ]
    }
  }
}

Use mcp2mqtt MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once mcp2mqtt is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add mcp2mqtt as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the mcp2mqtt MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "mcp2everything-mcp2mqtt": {
      "command": "npx",
      "args": [
        "-y",
        "mcp2mqtt"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the mcp2mqtt MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the mcp2mqtt MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use mcp2mqtt to help me with this task?
mcp2mqtt
Sure. I read it.
Here is what I found using mcp2mqtt.

Frequently asked questions

What is the mcp2mqtt MCP server used for?

mcp2mqtt is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use mcp2mqtt MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use mcp2mqtt with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use mcp2mqtt MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With mcp2mqtt connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect mcp2mqtt MCP to TypingMind?

mcp2mqtt runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does mcp2mqtt MCP provide in TypingMind?

mcp2mqtt exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use mcp2mqtt MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If mcp2mqtt requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇