Skip to main content

bmahs-mcp-gateway

BMAHS(比马斯) 是一个开放的局域网硬件协议:每台设备上电即用自然语言「自我介绍」——我是谁、能做什么、安全边界在哪——让大模型智能体像接入 USB 设备一样,即插即用地发现、识别、按权限独占并安全地操作它们。

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。

快速开始

完整的下载、安装、MCP 客户端接入与排障说明见 USAGE.md(两个版本通用)。

# 扫描局域网内的 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  # 运行测试

发布到 PyPI 的完整流程与注意事项见 RELEASING.md

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.1.tar.gz (45.2 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.1-py3-none-any.whl (49.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bmahs_mcp_gateway-0.1.1.tar.gz
  • Upload date:
  • Size: 45.2 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.1.tar.gz
Algorithm Hash digest
SHA256 6fba34577c2aea7ff7e6309e3788b399649017f13569e6643654650b1dae4826
MD5 862374ff9cb11bc5cce269a0d6890db9
BLAKE2b-256 f57f6c7075177d4c8610e08069e8dace438e34c9b95a211f0c91d819da7d0129

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bmahs_mcp_gateway-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 49.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e80f4c520988bfd6373454dd7443e7c1fad421c9f6b116eb896bfc9be2e1d60c
MD5 945bb58e8016588d6b5b3bf0b2c6cf3d
BLAKE2b-256 9cda46a3a5fd9a357ed7594160cb039eb1d2f176d873fe2454f2768e8212c8a1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

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