mcp-agent-relay
A durable MCP-native job relay that enables agents to dispatch work to each other and wakes a running Claude session via a channel when a job completes, eliminating fragile tmux-based approaches.
README
mcp-agent-relay
A durable, MCP-native job relay. Agents dispatch work to each other; a Claude Code
session is woken — via a channel — the moment a job finishes.
No tmux send-keys, no file-watching daemon, no point-to-point socket to keep alive.
Status: v0.1 — research preview. The store, MCP facade, and worker are covered by 63 tests. The "wake a running session" channel rides on a Claude Code research-preview feature (see caveats).
The problem it solves
When one agent hands work to another, two hard parts hide behind "just send a message":
- Durability. If the relay process dies mid-job, the job and its result must survive — no lost work, no double-execution, no "did that actually run?".
- The trigger. An interactive CLI session (Claude Code) can't be called like a server.
The old answer was a daemon that injected keystrokes into the terminal with
tmux send-keys. Fragile, invisible, easy to break.
mcp-agent-relay answers both with one design: a file-durable job store behind a standard
MCP facade, plus a channel that pushes a "job done" signal straight into a running session.
The asymmetry it leans on: a server (e.g. Codex) is driven by a worker; an interactive session (Claude) is woken by a channel. Same relay, two ends.
Architecture
agent A (MCP client) RELAY (durable, file-backed) worker / executor
│ dispatch(to,task, │ │
│ request_id) │ enqueue → dedup by request_id │
├──────────────────────────►│ job_id (atomic write + lock) │
│ job_id │ │
│◄──────────────────────────┤ │
│ poll(job_id) │ claim (lease + fencing token) ───►│ runTurn()
│ │ complete(result) BEFORE replying │ e.g. `codex exec`
│◄──── result ──────────────┤◄───────────────────────────────────┤
│ │
│ ⟵ channel: "job done" pushed into agent A's running session ⟵
Four layers, each independently testable:
| Layer | File | What it owns |
|---|---|---|
| Store | lib/relay-jobs.mjs |
durable queue: atomic writes, interprocess lock, leases, fencing tokens, request_id dedup, TTL sweep, write-safety (needs_recovery) |
| Facade | server.mjs |
MCP stdio server: register_agent / dispatch / poll + inbox resources + the channel |
| Worker | lib/relay-worker.mjs |
claims jobs, runs them with heartbeat + cooperative cancel, completes durably |
| Executor | lib/codex-executor.mjs |
the default runTurn — runs a Codex turn via the codex CLI. Swappable. |
Install
As a Claude Code plugin
claude plugin marketplace add <your-org>/mcp-agent-relay
claude plugin install mcp-agent-relay
The plugin declares the relay MCP server in .mcp.json; Claude Code auto-connects
it at session start.
As a raw MCP server (any MCP client)
// .mcp.json in your project
{
"mcpServers": {
"relay": {
"command": "node",
"args": ["/path/to/mcp-agent-relay/server.mjs"],
"env": { "RELAY_AGENT": "claude-main" }
}
}
}
No build step, no runtime dependencies — Node ≥ 18.18 and the standard library only.
Usage
Dispatch and poll (the async base)
dispatch returns a job_id immediately and is idempotent by request_id:
// tool: dispatch
{ "to": "codex", "task": { "prompt": "review the diff" }, "request_id": "req-1" }
// → { "job_id": "relay-…", "deduped": false, "state": "queued" }
// tool: poll
{ "job_id": "relay-…" }
// → { "found": true, "state": "completed", "result": { … }, "attempts": 1 }
Run a worker (the execution side)
The worker claims queued jobs and runs them. The default executor shells out to codex exec:
# drain once and exit
node worker.mjs --agent codex --once
# long-running loop, allowed to run write jobs
node worker.mjs --agent codex --allow-writes --interval 1000
Write jobs are deny-by-default (--allow-writes to opt in). A write job whose lease expires
is parked as needs_recovery — never silently re-run.
The channel (no more tmux)
To have a running Claude session woken when a job it dispatched finishes:
RELAY_AGENT=claude-main claude --dangerously-load-development-channels server:relay
When a terminal job (from === RELAY_AGENT) finishes, or a new job lands in this agent's inbox
(to === RELAY_AGENT), the server emits notifications/claude/channel. It arrives as
<channel source="relay">…</channel> and Claude acts on it — typically by calling poll.
Injection-safe: the channel content is a minimal envelope (job_id, state) telling Claude
to poll for the result. The untrusted job payload is never placed in the channel content.
Swap the executor
The worker calls a runTurn(cwd, { prompt, model, write, signal }) function. The default
(lib/codex-executor.mjs) runs codex exec -s read-only|workspace-write … and returns the
final message via --output-last-message. To target a different backend, pass your own
runTurn when constructing the worker — the relay, channel, and durability guarantees are
unchanged.
Requirements & caveats
- Node ≥ 18.18. No runtime dependencies.
- Default executor needs the
codexCLI onPATH. Swap it (above) to run anything else. - The channel is a Claude Code research preview: needs Claude Code ≥ 2.1.80, Anthropic auth
(not Bedrock/Vertex), and the
--dangerously-load-development-channelsflag. The relay is fully usable without the channel —polland the inbox resource are always the source of truth; the channel is a wake-up signal, not the system of record. - Single machine, v0.1. The store is file-backed and coordinated by an interprocess lock. Multi-machine (shared substrate + cross-agent auth) is a deliberate future phase, not a redesign — the routing model (identity + inbox + claim) already accounts for it.
Development
node --test # 63 tests: store, facade + channel, worker
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。