MCP Hub (mcp-hub)
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MCP 消息集线器(mcp-hub)
多 Agent 注册、心跳、路由与消息转发的轻量集线器,按 MCP 标准协议(JSON-RPC 2.0 / Streamable HTTP)提供服务,纯 asyncio 异步实现。目标场景是监测平台里的多智能体协作:报告 Agent、OCR Agent、告警 Agent 各自注册上线,通过集线器互相投递任务与事件。
特性
MCP 标准协议:
POST /mcp走 JSON-RPC 2.0,支持initialize/tools/list/tools/call/ping;GET /mcp是 SSE 长连接,用于服务端推送。Agent 注册表:唯一 id、显示名、版本、能力标签、主题订阅、自定义元数据。
心跳与离线判定:Agent 定期
hub_heartbeat,超过heartbeat_timeout未心跳自动置为离线;离线超过保留期自动清理。三种投递:点对点(
agent_id)、主题(topic:xxx)、广播(*)。双通道接收:有 SSE 连接实时推送;没有连接也能用
hub_fetch_messages拉取(消息先入有界队列,不会丢在半路)。管理接口:在线 Agent 列表、详情、待投递消息、强制下线、统计、Prometheus 指标。
Webhook 事件:注册 / 上线 / 离线 / 注销 / 发送事件可推送监测平台。
可测试:26 个单测覆盖注册表、路由、MCP 协议与管理接口,全部走 ASGI,无外部依赖。
结构清晰:协议层、业务层、传输层分离,注释与类型标注完整,便于后续扩展。
Related MCP server: mcp-switchboard
架构
Agent A ──POST /mcp (tools/call)──┐
Agent B ──POST /mcp───────────────┤ ┌──────────────┐
Agent C ──GET /mcp (SSE)◄────────┼───────►│ MCP 协议层 │
│ │ server.py │
监测平台 ──GET /admin/*───────────┘ └──────┬───────┘
│
┌──────────────────────────┼──────────────────────────┐
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ AgentRegistry │ │ MessageBus │ │ Router │
│ 注册/心跳/主题 │ │ 队列 + SSE │ │ 点对点/主题/广播 │
└─────────────┘ └─────────────┘ └─────────────┘
│ ▲ │
└────────── Hub(生命周期 / reaper / 指标 / Webhook)──┘目录结构
mcp_hub/
├── config.py 配置(环境变量 MCP_HUB_*)
├── logging_setup.py 日志(文本 / JSON)
├── models.py Pydantic 模型:Agent、Envelope、DeliveryReport、统计
├── registry.py Agent 注册表 + 心跳超时 + 主题订阅
├── bus.py 有界消息总线(待投递队列 + SSE sink)
├── router.py 路由:direct / topic / broadcast
├── metrics.py 指标 + Prometheus 文本
├── events.py Webhook 事件分发
├── hub.py 服务容器与后台 reaper
├── mcp/
│ ├── protocol.py JSON-RPC / MCP 常量与编解码
│ ├── session.py MCP 会话管理
│ ├── tools.py 8 个 hub_* 工具
│ └── server.py /mcp 的 POST / GET(SSE) / DELETE
├── api/
│ ├── admin.py /admin/* 管理接口
│ └── app.py FastAPI 装配
└── sdk/client.py Agent 侧客户端(含 SSE 监听与心跳循环)
tests/ 26 个测试
examples/ 多 Agent 演示 + 常驻 Agent 模板快速开始
# 1. 创建虚拟环境并安装
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # Linux / macOS
pip install -e ".[dev]"
# 2. 启动集线器(默认 127.0.0.1:8765)
python -m mcp_hub
# 或指定参数
python -m mcp_hub --host 0.0.0.0 --port 8765 --log-level INFO
# 3. 另开一个终端,跑多 Agent 演示
python examples/multi_agent_demo.py访问 http://127.0.0.1:8765/docs 可以看到管理接口的交互式文档。
让别的智能体接入(本机常驻)
登录自启:
powershell -NoProfile -ExecutionPolicy Bypass -File deploy\install_autostart.ps1(在「启动」文件夹放一个隐藏窗口快捷方式,免管理员;卸载用deploy\uninstall_autostart.ps1)通用客户端:
clients\hub-agent.ps1(PowerShell 零依赖,支持 register / heartbeat / send / fetch / poll / list)操作卡:把
docs/AGENT_ONBOARDING.zh.md里对应的一段整段粘给其他智能体即可
# 示例:注册一个叫 doubao 的 Agent,然后给它发消息
powershell -File clients\hub-agent.ps1 register -AgentId doubao -SpecFile clients\examples\doubao.json
powershell -File clients\hub-agent.ps1 send -AgentId doubao -Target minimax -PayloadFile clients\examples\task.json
powershell -File clients\hub-agent.ps1 fetch -AgentId minimaxMCP 协议
端点
方法 | 路径 | 用途 |
POST |
| JSON-RPC 请求( |
GET |
| SSE,接收服务端推送( |
DELETE |
| 结束会话 |
会话 id 通过响应头 Mcp-Session-Id 下发,客户端后续请求带回该头即可。协议版本协商支持 2025-06-18 / 2025-03-26 / 2024-11-05,未知版本回落到最新。
工具
工具 | 说明 | 关键参数 |
| 注册 / 更新 Agent,并绑定当前会话 |
|
| 刷新心跳 |
|
| 注销并丢弃待投递消息 |
|
| 发送消息 |
|
| 查看 Agent 列表 |
|
| 拉取待投递消息(会移除) |
|
| 主题订阅管理 |
|
示例:手工调一次 MCP
# 1) 握手,记下响应头里的 Mcp-Session-Id
curl -s -D- -X POST http://127.0.0.1:8765/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}'
# 2) 注册(带上第一条拿到的 session id)
curl -s -X POST http://127.0.0.1:8765/mcp \
-H "Content-Type: application/json" -H "Mcp-Session-Id: <sid>" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"hub_register","arguments":{"agent_id":"agent-a"}}}'
# 3) 查看在线 Agent
curl -s http://127.0.0.1:8765/admin/agents推送格式
服务端通过 SSE 下发 MCP 标准 logging 通知,消息信封在 params.data 里:
event: message
data: {"jsonrpc":"2.0","method":"notifications/message","params":{
"level":"info","logger":"mcp-hub","data":{
"id":"...","ts":1795...,"sender":"agent-a","target":"agent-b",
"message_type":"direct","payload":{"task":"ocr"}}}}投递语义
消息先写入目标 Agent 的有界队列(默认 200 条),队列满时丢弃最旧的一条并记
dropped。如果目标 Agent 当前有 SSE 连接,同时推入推送队列,实时送达;推送不会移除队列里的副本,所以「SSE 收到」和「
hub_fetch_messages拉到」只能二选一,不能混用同一条消息——推荐二选一:实时用 SSE,离线用拉取。广播默认不含发送者(
MCP_HUB_BROADCAST_INCLUDE_SENDER=1可改)。点对点投递只要目标 Agent 注册过就会入队——即使心跳过期(显示离线),消息也会保留到它下次拉取;只有从未注册或已被清理的
agent_id才计入dropped。广播与主题只投给当前在线的 Agent。
心跳与离线
Agent 每 N 秒 hub_heartbeat → registry.last_seen = now
reaper 每 min(5, timeout/4) 秒扫描 → now - last_seen > heartbeat_timeout → 置 offline + 发事件
offline 超过 offline_retention(默认 600s)→ 从注册表删除判定结果会体现在 /admin/agents 的 online 字段与 /admin/metrics 的 mcp_hub_agents_online。
管理接口
方法 | 路径 | 说明 |
GET |
| 健康检查 |
GET |
| Agent 列表(含待投递数) |
GET |
| 单个 Agent 详情 |
GET |
| 查看待投递消息(不移除) |
DELETE |
| 强制下线并删除 |
GET |
| 汇总统计 |
GET |
| Prometheus 文本指标 |
GET |
| 脱敏运行配置 |
配置了 MCP_HUB_ADMIN_TOKEN 后,以上接口都需要请求头 X-Admin-Token。
接入监测平台
指标抓取:
GET /admin/metrics直接给 Prometheus / VictoriaMetrics 抓,已包含在线数、消息吞吐、队列积压、SSE 连接数。事件推送:配置
MCP_HUB_WEBHOOK_URLS=http://platform/api/hub-events,会收到:事件
时机
data 关键字段
agent_registered首次注册
agent_id、capabilities、topicsagent_updated重复注册
同上
agent_offline心跳超时
agent_id、reason、pending_messagesagent_unregistered主动注销 / 管理端踢下线
agent_id、reason、pending_droppedmessage_sent每次发送
message_id、delivered、dropped业务约定:建议把项目编号、测点类型、报告类型放进 Agent 的
metadata,把业务事件名作为payload.type(如report.request/alarm.raised),平台侧就能按主题订阅并落库。
配置
环境变量 | 默认值 | 说明 |
|
| 监听地址 |
|
| 建议心跳间隔(下发给 Agent 参考) |
|
| 心跳超时(秒) |
|
| 离线保留时长(秒),0 表示不清理 |
|
| 每 Agent 待投递队列上限 |
| 空 | 管理接口令牌 |
|
| 广播是否含发送者 |
| 空 | Webhook 地址,逗号分隔 |
|
| 日志级别 / JSON 日志 |
生产部署建议
单进程运行:状态(注册表、队列)在内存里,不要开多 worker;需要横向扩展时,把注册表与总线换成 Redis / NATS 实现即可(接口已经收在
registry.py/bus.py)。对外暴露时:
--host 0.0.0.0+ 设置MCP_HUB_ADMIN_TOKEN,前面挂 Nginx/Caddy 做 TLS 与限流;SSE 需要关闭代理缓冲(proxy_buffering off)。容器化:
python -m mcp_hub作为入口,健康检查打/admin/health。
已知限制
会话与 Agent 的绑定关系在内存中,重启后 Agent 需要重新
initialize+hub_register。SSE 与拉取共用同一个待投递队列(见「投递语义」),同一消息不会被两路各消费一次。
没有实现 MCP 的 resources / prompts / sampling(返回空列表),只做工具与推送。
未做鉴权(除管理接口),内网部署更合适;需要时可在
/mcp前加一层令牌校验。
开发与测试
pip install -e ".[dev]"
pytest -q # 26 passed代码风格:类型标注 + 中文注释,模块职责单一;新增工具只需在 mcp/tools.py 里加 schema 与 handler。
许可证
MIT,见 LICENSE。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Agent communication platform for agent to agent messaging via MCP. Messages, channels, skills.
Real-time chat hub for AI agents — Claude Code, Cursor, Cline, Codex over MCP or REST.
- aXDeprecatedio.github.ax-platform
Agent-native collaboration network: orchestrate a team of long-running agents from any MCP client.
Discover MCP servers and A2A agents; verify, message, post, follow, react, and receive webhooks.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceMCP-native agent-to-agent messaging hub for AI swarms. Agents communicate via channels and DMs through MCP protocol — zero SDKs needed. Includes web UI, semantic search, analytics dashboard. Single Go binary, local-first.2Apache 2.0
- AlicenseNot gradedqualityCmaintenanceA real-time inter-agent switchboard, delivered as one centralized streamable-HTTP MCP server. Any MCP-capable agent can message, coordinate, and stay ambiently aware of others.1AGPL 3.0
- AlicenseNot gradedqualityDmaintenanceA shared MCP hub that enables multiple coding-agent CLIs to register, discover, and communicate asynchronously via a standalone daemon. It provides MCP tools for agent registration, session management, non-blocking messaging, and cursor-based event reading.3 npm1MIT
- AlicenseNot gradedqualityBmaintenanceMCP server for universal multi-agent communication, enabling agents to register, send/receive messages, manage tasks, and coordinate via role-based routing with project isolation.6 npmISC