Skip to main content

bmahs-mcp-gateway

BMAHS(比马斯)设备协议 ↔ MCP 网关:把局域网内按 bmahs/1.0 协议发布的硬件设备(解析侧兼容旧版 1–1.2 字段名)动态映射为 Model Context Protocol 工具,让大模型客户端可以直接发现、占用与操作这些设备。

特性

  • 零配置发现:UDP 组播(239.255.42.42:5354 / [ff02::4242]:5354)+ Bonjour/mDNS 双通道,设备上线即被识别;也支持 BMAHS_STATIC_DEVICES 静态设备表(适配不支持组播的环境)。
  • 动态工具映射:设备的动作清单(ops)自动映射为 MCP 工具,含参数 Schema 与 any_of 预检,无需为每类设备写适配代码。
  • 协议级占用安全:控制前自动 occupy、自动携带 token、任务结束/进程退出自动 release,token 不写入 UDP/TXT/日志。
  • 标准错误信封:设备错误按 §4.7 信封(ok/action/code/error/retryable)透传给模型,error 为自然语言中文。
  • 两种接入模式:stdio(单客户端,MCP 客户端直接拉起)与 Streamable HTTP(多客户端共享一个网关进程,可选 Bearer Token 鉴权)。

安装

pip install bmahs-mcp-gateway            # stdio 模式,最小依赖
pip install "bmahs-mcp-gateway[http]"    # 需要 Streamable HTTP 共享模式时

或使用 uvuv add bmahs-mcp-gateway。要求 Python ≥ 3.10。

快速开始

# 扫描局域网内的 BMAHS 设备
bmahs-mcp discover

# 联调:对设备执行一个动作
bmahs-mcp ctl 客厅灯 on
bmahs-mcp ctl 客厅灯 brightness --arg level=80

# 启动 MCP 网关(stdio,供 MCP 客户端连接;默认子命令)
bmahs-mcp serve

# 以 Streamable HTTP 共享模式启动(多客户端同时连接)
bmahs-mcp http --host 0.0.0.0 --port 9530 --token 换成你的令牌

在 MCP 客户端(ZCode / Claude Desktop 等)中配置 stdio 接入:

{
  "mcpServers": {
    "bmahs": {
      "command": "bmahs-mcp",
      "args": ["serve"]
    }
  }
}

HTTP 模式的端点为 http://<host>:9530/mcp;设置了 --token 后客户端须携带 Authorization: Bearer <token>

环境变量

变量 说明
BMAHS_AGENT_ID 网关在协议中的智能体 id(默认自动生成)
BMAHS_STATIC_DEVICES 静态设备表,如 tcp://192.168.1.10:9527,逗号分隔
BMAHS_BONJOUR_BROWSE 0 关闭 mDNS 浏览通道(默认开)
BMAHS_AUTO_OCCUPY / BMAHS_AUTO_OCCUPY_TTL / BMAHS_MAX_LEASE 自动占用策略与租约上限
BMAHS_CALL_TIMEOUT / BMAHS_QUERY_INTERVAL / BMAHS_EXPIRE_SEC 调用超时、设备表刷新与过期时间
BMAHS_HTTP_HOST / BMAHS_HTTP_PORT / BMAHS_HTTP_PATH / BMAHS_HTTP_TOKEN HTTP 模式默认参数
BMAHS_LOG_LEVEL 日志级别(日志一律走 stderr,不污染 stdio 协议通道)

协议

BMAHS 协议要点:UDP 组播一报文一 JSON(≤1400 字节)负责发现,TCP 一行 JSON + \n 负责控制,连接后先读设备 hello;网关在协议中承担「智能体」角色。完整协议文档见 docs/BMAHS.md

本地开发与构建

uv sync        # 安装依赖(含 dev 组)
uv build       # 在本目录构建 wheel + sdist
uv publish     # 发布到 PyPI(需配置 token)
uv run pytest  # 运行测试

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bmahs_mcp_gateway-0.1.0.tar.gz (44.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bmahs_mcp_gateway-0.1.0-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

Details for the file bmahs_mcp_gateway-0.1.0.tar.gz.

File metadata

  • Download URL: bmahs_mcp_gateway-0.1.0.tar.gz
  • Upload date:
  • Size: 44.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bmahs_mcp_gateway-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad5731441f07ecce4e1e0d15dc2cb306c97d2486253d0fadf37dc68ea34a16b0
MD5 eb985f47e047b65ceabf7b851541c231
BLAKE2b-256 0fb21b37ad9b0904469d717f6fc57e8fb22f562f4dcbb2f0fcab8ffc199cbcbd

See more details on using hashes here.

File details

Details for the file bmahs_mcp_gateway-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bmahs_mcp_gateway-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 49.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bmahs_mcp_gateway-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40b0f01a4d39fca8af37d6854b6d773fca037b54eaf5f34634e25fc1246f4b22
MD5 569bb819c016d17fead7d2594267b48e
BLAKE2b-256 6f1a4347c0c4564df7eb7de25b15bf313bfa3cc263bf28c89149edf73fc13637

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page