代理事件总线
用于跨会话Claude Code通信和协调的MCP服务器。
概述
当运行多个Claude Code会话(在单独的终端或工作树中)时,每个会话都是隔离的。此MCP服务器为以下会话提供事件总线:
- 宣布出席 -了解其他正在进行的会话
- 广播状态 -共享进度更新和任务完成情况
- 协调工作 -信号依赖性和切换
- 发送通知 -支持自定义图标的系统通知
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ CC Session 1 │ │ CC Session 2 │ │ CC Session 3 │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
└────────────────────┼────────────────────┘
▼
┌───────────────────────────────────┐
│ agent-event-bus (localhost) │
└───────────────────────────────────┘安装
服务器
在此计算机上运行事件总线服务器:
git clone https://github.com/evansenter/agent-event-bus.git
cd agent-event-bus
make install-server安装:venv、LaunchAgent(自动启动)、CLI(~/.local/bin/agent-event-bus-cli),MCP服务器指向本地主机。
客户端
连接到另一台机器上运行的事件总线(例如,通过Tailscale):
git clone https://github.com/evansenter/agent-event-bus.git
cd agent-event-bus
make install-client REMOTE_URL=https://your-server.tailnet.ts.net/agent-event-bus/mcp安装CLI并配置MCP以指向远程服务器。将URL添加到您的shell配置文件中:
# In your shell profile (~/.extra, ~/.zshrc, etc.)
export AGENT_EVENT_BUS_URL="https://your-server.tailnet.ts.net/agent-event-bus/mcp"路径
确保 ~/.local/bin 在路径中: export PATH="$HOME/.local/bin:$PATH"
MCP工具
| 工具 | 说明 |
|---|---|
register_session | 注册会话,获取session_id+游标 |
list_sessions | 列出活动会话 |
list_channels | 列出带有用户数量的频道 |
publish_event | 将事件发布到频道 |
get_events | 事件投票(使用 resume=True 增量) |
unregister_session | 出口清理 |
notify | 系统通知 |
register_webhook | 为推送通知注册HTTP端点 |
list_webhooks | 列出已注册的webhooks |
unregister_webhook | 删除webhook |
频道
事件包括上下文的通道元数据。 所有会话查看所有事件 (广播模式)。
| 频道 | 上下文 |
|---|---|
all | 常规广播(默认) |
session:{id} | 直接消息(触发通知) |
repo:{name} | 特定于存储库 |
machine:{name} | 机器特定 |
命令行界面
对于shell脚本和钩子:
# Register (returns session_id)
SESSION_ID=$(agent-event-bus-cli register --name "my-feature" --client-id "$$" --json | jq -r .session_id)
# Publish and notify
agent-event-bus-cli publish --type "done" --payload "Finished" --channel "repo:my-project"
agent-event-bus-cli notify --title "Build" --message "Complete" --sound
# Poll for events (incremental)
agent-event-bus-cli events --session-id "$SESSION_ID" --resume --order asc
# Cleanup
agent-event-bus-cli unregister --session-id "$SESSION_ID"网络钩子
将事件推送到HTTP端点,而不是轮询。事件发布时,Webhooks被异步调用。
主控程序
# Register a webhook for all events
register_webhook(url="https://your-server.com/events")
# Filter by channel (prefix matching supported)
register_webhook(url="https://...", channel="session:")
# Filter by event type
register_webhook(url="https://...", event_types=["task_completed", "help_needed"])
# With HMAC signature verification
register_webhook(url="https://...", secret="your-shared-secret")
# List and manage
list_webhooks()
unregister_webhook(webhook_id=1)命令行界面
# Register
agent-event-bus-cli webhook register --url https://your-server.com/events
agent-event-bus-cli webhook register --url https://... --channel "session:" --secret "my-secret"
# List
agent-event-bus-cli webhook list
# Remove
agent-event-bus-cli webhook unregister 1有效载荷
Webhooks收到一个带有JSON正文的POST:
{
"event_id": 123,
"event_type": "task_completed",
"payload": "Finished building feature X",
"session_id": "abc-123",
"timestamp": "2026-01-31T08:00:00",
"channel": "repo:my-project"
}如果a secret 已配置,请求包括 X-Event-Bus-Signature 头球
X-Event-Bus-Signature: sha256=通过使用您的密钥计算原始请求体的HMAC-SHA256进行验证。
多机设置
运行一台服务器,通过Tailscale(或任何VPN)从多台机器连接。
服务器计算机:
make install-server编辑 ~/Library/LaunchAgents/com.evansenter.agent-event-bus.plist,添加到 EnvironmentVariables:
HOST
0.0.0.0然后重新启动: make restart
注:make install-server覆盖plist。要保持此设置,请编辑scripts/com.evansenter.agent-event-bus.plist(取消注释HOST行)。
客户端计算机:
make install-client REMOTE_URL=https://your-server.tailnet.ts.net/agent-event-bus/mcp然后添加到您的shell配置文件中:
export AGENT_EVENT_BUS_URL="https://your-server.tailnet.ts.net/agent-event-bus/mcp"新的Claude Code会话将有完整的 mcp__agent-event-bus__* 工具访问中央服务器。
发展
make dev # Install with dev dependencies
./scripts/dev.sh # Run in foreground with auto-reload
make check # Format + lint + test通知
需要 terminal-notifier 对于自定义图标: brew install terminal-notifier
数据
所有数据 ~/.claude/contrib/agent-event-bus/: data.db, agent-event-bus.log, agent-event-bus.err
相关
- claude会话分析 -历史会话分析
- 点文件 -
/parallel-work命令和钩子
