Cover image
Try Now
2025-03-20

模型上下文协议(MCP)的实现,该协议可以通过服务器量事件(SSE)传输实现MQTT操作。

3 years

Works with Finder

1

Github Watches

1

Github Forks

1

Github Stars

MQTTX SSE Server

An implementation of the Model-Context Protocol (MCP) that enables MQTT operations over Server-Sent Events (SSE) transport.

About MCP

The Model-Context Protocol (MCP) is a standardized protocol that allows AI assistants to interact with external tools and services. This server implements the MCP specification using SSE (Server-Sent Events) as the transport layer, providing MQTT broker connectivity capabilities.

Features

  • Implements MCP protocol version 2024-11-05
  • Uses SSE (Server-Sent Events) as the transport layer
  • Provides MQTT operations through MCP tools:
    • Connect to MQTT brokers
    • Subscribe to MQTT topics
    • Publish messages to MQTT topics
  • Real-time message delivery from subscribed topics
  • Session management for multiple clients

Getting Started

Prerequisites

  • Node.js (v14 or later)
  • npm

Installation

# Clone the repository
git clone https://github.com/yourusername/mqttx-sse-server.git
cd mqttx-sse-server

# Install dependencies
npm install

Running the Server

npm start

The server will start on port 4000 by default.

Configuring MQTTX

To use this MCP server with MQTTX, add the following configuration to your MQTTX settings:

{
  "mcpServers": {
    "mqttx-server": {
      "url": "http://localhost:4000/mqttx/sse"
    }
  }
}

MCP Protocol Implementation

This server implements the Model-Context Protocol with the following components:

  • SSE Connection: Establishes persistent connection for real-time updates
  • JSON-RPC API: Handles tool calls and responses according to MCP spec
  • Tools Interface: Provides MQTT functionality through standardized MCP tools
  • Session Management: Tracks client sessions and their MQTT connections

API Reference

SSE Connection

Establishes a persistent connection for receiving server events.

GET /mqttx/sse

Response events:

  • endpoint: Contains the URL for making JSON-RPC calls
  • heartbeat: Regular ping to keep the connection alive
  • message: Contains JSON-RPC responses

JSON-RPC Commands

All commands are sent to the message endpoint with your session ID:

POST /mqttx/message?sessionId=xxx

Initialize

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize"
}

List Tools

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/list"
}

MQTT Connect

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "mqttConnect",
    "arguments": {
      "host": "broker.example.com",
      "port": 1883,
      "clientId": "mqttx-client"
    }
  }
}

MQTT Subscribe

{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "tools/call",
  "params": {
      "name": "mqttSubscribe",
      "arguments": {
        "topic": "test/topic",
        "qos": 0
      }
  }
}

MQTT Publish

{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "tools/call",
  "params": {
      "name": "mqttPublish",
      "arguments": {
        "topic": "test/topic",
        "payload": "Hello MQTT!",
        "qos": 0,
        "retain": false
      }
  }
}

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Beniyam Berhanu
  • Therapist adept at identifying core issues and offering practical advice with images.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

    Reviews

    1 (1)
    Avatar
    user_AgfiunUu
    2025-04-16

    I've been using mqttx-mcp-sse-server by ysfscream and I'm thoroughly impressed. It's a powerful server solution that's incredibly easy to set up, thanks to the clear documentation on its [GitHub](https://github.com/ysfscream/mqttx-mcp-sse-server) page. The seamless integration and performance of this server in handling MQTT and SSE make it an essential tool for any application requiring reliable real-time data streaming. Highly recommend!