relay
Supports read-only SQLite conversation databases as rescue sources, with configurable table and column mappings.
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.
relay-mcp
多模型、多会话开发的接力协议 MCP server。 状态存放在仓库文件中,由 R 系列机检规则(R1–R13)与可执行验收共同守门。
中文
概述
relay-mcp 让不同模型(Claude / Codex / Gemini / Cursor 等)在同一仓库上安全接力:上一个会话的进度、决策、待办与踩坑全部写入 START / SPEC / DECISIONS / TASKS / LOG,下一个会话从文件恢复上下文,而不是依赖聊天记录。
零运行时依赖(仅
node:内置模块),Node ≥ 22,无构建步骤15 个 MCP 工具,
node src/index.mjs即为 stdio server规范即检查:R 系列规则全部由
relay_verify机检;出场绿闸同时要求可执行验收真实通过入口文件单源投影:
AGENTS.md必需,CLAUDE.md/GEMINI.md按需生成
安装
本仓库不通过 npm 分发(2026-11-18 决策冻结;npm 上的 relay-mcp 属他人)。使用 git clone 或 Agent Plugins 插件包:
git clone https://github.com/KentQi/relay-mcp.git
cd relay-mcp
node src/index.mjs # stdio MCP server(也可由客户端拉起)不支持插件包的客户端,在它的 mcpServers 配置里加入(把 /abs/path 换成仓库绝对路径):
{
"mcpServers": {
"relay-mcp": {
"command": "node",
"args": ["/abs/path/relay-mcp/src/index.mjs"],
"cwd": "/abs/path/relay-mcp"
}
}
}重启客户端后,工具名为 mcp__relay-mcp__relay_*。
如需随客户端启动检查更新,将 args 改为 ["/abs/path/relay-mcp/scripts/relay-mcp-autoupdate.mjs"]。启动器只在主工作树的 main 干净且没有本地独有提交时执行快进;fetch 后固定 before/upstream 两个 SHA,以 git update-ref <new> <old> 做后端无关的原子 CAS,再用 read-tree -m -u 拒绝覆盖并发本地编辑。发布前写事务 journal;若进程在 ref 与工作树之间被强杀,下次启动会在冷却判断之前检查 journal,无法证明 HEAD/index/worktree 同端点时拒绝启动。SHA-1、SHA-256 与 files/reftable ref 后端使用同一条 Git 原生发布路径。已迁移的安装可能还保留旧启动器和备份,当前注册路径应指向仓库内的启动器。
Agent Plugins 插件包(v1.0.0)
仓库根目录同时是一个符合 Agent Plugins 1.0.0 的插件包,支持该标准的客户端可以直接把仓库目录当插件加载:
relay-mcp/
├── plugin.json # 清单:$schema + name/version/description/…(闭集字段)
├── mcp.json # stdio MCP server:node + ${PLUGIN_ROOT}/src/index.mjs
└── skills/
├── relay-protocol/SKILL.md # 可移植 Skill:relay 协议操作手册
└── relay-discipline/SKILL.md # 可移植 Skill:写代码时的行为纪律(绑定 R1–R13)mcp.json 使用插件变量:args: ["${PLUGIN_ROOT}/src/index.mjs"]、cwd: "${PLUGIN_ROOT}";PLUGIN_ROOT / PLUGIN_DATA 由客户端展开并注入子进程。静态校验(零依赖)与退出码:
node scripts/validate-plugin.mjs # 校验 plugin.json / mcp.json / skills/**/SKILL.md
node scripts/smoke-plugin.mjs # 51 断言:合规 + 真实 initialize/tools/list + 规范负例不支持插件包的客户端使用上面的 mcpServers 片段。
分发方式(npm 已冻结)
2026-11-18 决策冻结 npm 发布:npm 上的 relay-mcp 是另一个项目(derekluo 的 OpenAPI relay server),本仓库不再尝试占用该名字。分发只保留 git clone、Agent Plugins 插件包与 GitHub Release;package.json 已置 "private": true,从机器层阻止误发布,安装器、打包面与发布护栏已移除。历史发布记录见 CHANGELOG。
快速开始
场景 | 工具 |
新建项目 |
|
接入存量项目 |
|
存量目录标准化 |
|
每会话接力 |
|
preset:node(默认,含可运行代码骨架与测试)或 minimal(仅接力层)。
出场绿闸
出场前必须同时满足:
relay_verify全量 R 系列规则无 ERROR;任务的可执行验收真实通过(
test:路径运行node --test;逐字符命中manifest.acceptance.commands的test:<命令>经 shell 执行;项目声明scripts.test时运行npm test)。
任一条件不满足:不更新 TASKS/LOG、不提交、保留认领锁。
每个验收命令默认最多运行 180 秒,仓库属主可通过 manifest.acceptance.timeoutMs 调整毫秒数。批量完成各跑任务自己的 test:,共享一次项目级 npm test。
简报有界(T015):入场简报的每条 LOG 摘要硬上限 200 字符(负结果/交接提示 120),超长条目只截断展示并标注"全文见 LOG.md";总长超过 manifest.contextBudget(默认 6000)时追加显式告警而不裁剪任何段落(裁剪即静默降级)。
**事实底账(R10)**由引擎在出场时写入,|| 分隔机检段与验收、verify 汇总和耗时。受管模式用注册表的 baseSha 和同一 LOG 条目唯一的 worktree 成对 SHA 重算文件数与增删行数。分支应包含该提交,合并并删除分支后可用当前 Git 历史验证。单根模式按修改 LOG 的完成提交及其父代对账文件数。缺少独立证据、证据不唯一或只有 v1 事实行时,R10 报 WARN。机检字段不符时报 ERROR。manifest.facts.since 限定日期范围,旧历史只有在引入提交是 manifest.facts.baselineSha 的祖先时才豁免;提交时间与标题时间不作为信任锚。
历史校正证据(人工批准的历史回填)
旧版本引擎一次只能记一个完成任务,多任务交付会缺逐任务完成条目。补这种缺口时不手写普通完成条目(那与引擎产物不可区分),而是写成独立证据类型:
归档
docs/archive/LOG-*.md中标题task=T### 历史校正、model带(历史校正)后缀、正文恰有一条- 校正批准: decision=T### | evidence=<40位hex> | source=<文本>;DECISIONS.md追加一条标题以(T###)结尾、状态「现行」的批准条目,含- 历史校正批准: T001,T002 | 依据: <sha>;<证据> | 决定: …。
R9 与 doctor D8 只认这类校正:形状非法或未批准 → ERROR;校正被删除 → ERROR(不再回落成不阻断的 WARN)。校正标题不匹配完成语义,因此不进入 R10/R7 的对账窗口,也不写事实行/worktree 行。
任务级 worktree
启用 worktree 的项目中,relay_claim 返回两个根目录:
controlRoot:主工作树,维护 TASKS、LOG、认领锁与 worktree 注册表;
executionRoot:任务工作树(独立 checkout),代码、测试与任务分支提交在此进行,依赖需独立安装。
出场 = 双提交:executionRoot 提交任务分支代码,controlRoot 仅提交 TASKS.md / LOG.md;两者 SHA 都会输出,任一失败则不标完成、保留认领锁。
双根绿闸:controlRoot 跑全量 R 系列;executionRoot 跑任务树 R1/R2/R3/R4/R8;两侧 ERROR 合并阻断。
根错配保护:受管任务从 controlRoot 完成一律 isError(无空树例外);HEAD 无新提交的伪 SHA 同样拒绝。
成对证据(R5/R6):任务分支代码提交、controlRoot 完成提交、TASKS/LOG 已提交干净、LOG 记录
branch=与代码 SHA,四项缺一不可。注册表恢复(fail-closed):
缺失:先确认当前目录是否确为 relay 任务 worktree;是则用
git worktree list核对痕迹,并回到 controlRoot 重新relay_claim {worktree:true}重建登记;否则离开该 worktree,在 controlRoot 操作。损坏:
relay_claim/ 完成出场会拒绝继续,不会自动重建。先备份.relay/worktrees.json,再由人修复或删除损坏注册表,然后重新 claim 登记;cleanup 只报告并给出恢复指引。
验收通过 ≠ 已合并。 relay 不会自动 merge / rebase / push,也不会删除任务分支。人工整合:
git log --oneline main..relay/T003
git merge --no-ff relay/T003worktree 清理默认 dry-run:只删除已登记、已过期、非活跃、干净且不含 ignored 本地内容的目录。活跃性以 TASKS 的 [~] 活跃任务集为准,不以 registry 的 status=completed 替代;未提交、冲突、locked、路径越界、分支缺失均保留。.env、node_modules、构建产物等本地内容默认保留;任务分支始终保留。
配置
{
"worktree": {
"enabled": true,
"cacheDir": ".relay/worktrees",
"ttlHours": 24,
"autoCleanup": true
}
}enabled只认 JSON 布尔true;字符串"true"或数字1不生效。cacheDir必须是 controlRoot 内的相对路径;拒绝绝对路径、..、盘符、控制字符和.git前缀。ttlHours非法时回退 24;autoCleanup只有显式false才关闭。未知或拼错字段会被静默忽略,但
relay_doctor会点名未知键并给出最近似的已知键;旧 manifest 缺省关闭 worktree;relay_claim的worktree: true/false可单次覆盖。
抢救来源必须显式声明(缺省不扫描任何目录;7 天窗口、单份 8 MiB):
{
"rescue": {
"sources": [
{ "profile": "my-harness", "root": "~/.my-harness/agents" }
],
"profiles": [
{
"id": "my-harness",
"kind": "json-metadata",
"metaFile": "metadata.json",
"fieldMap": { "agentId": "agentId", "cwd": ["cwd", "workspaceRoot"] }
}
],
"maxAgeDays": 7,
"maxBytes": 8388608,
"autoLaunch": {
"enabled": true,
"command": ["your-agent-runner", "--prompt", "{{prompt}}", "--root", "{{root}}"],
"timeoutMs": 300000,
"maxOutputBytes": 1048576
}
}
}「在哪找、怎么读」全部由格式描述符声明:内置只有两份等价参考实现(记录型 / 元数据类型),核心引擎不认识任何具体 harness 的安装路径或字段名。加一个新 harness = 加一份描述(如上),不改核心代码。
sources每条是{ profile?, root }或裸路径;为空时不扫描任何目录(不读 home、不猜安装位置)。profiles支持三种kind:json-metadata、jsonl-message,以及sqlite-conversation(只读 SQLite 会话库,表名/列名全部声明)。maxAgeDays/maxBytes非法时回退默认。autoLaunch默认关闭;command是 argv 数组(不经 shell),支持{{prompt}}/{{root}}/{{task}}/{{rescueId}}/{{model}}占位符。worker 独立后台运行,状态写.relay/rescue/<id>/dispatch.json(原子发布);运行中或状态损坏时禁止 takeover/report/drop。
质量门预设(可选)
manifest.acceptance.commands 是人类逐条签字的外部命令白名单:把 CRAP、重复率、变异测试这类确定性质量门接进出场绿闸,而 relay 核心保持零依赖。
{
"acceptance": {
"commands": [
"npm run quality:complexity",
"npm run quality:duplication"
]
}
}示例命令是占位命名:替换为项目里真实存在、已锁版本的命令(也可以是工具自身 CLI)。relay 只按白名单执行,不负责安装;不存在或写错的命令会在出场门失败。
任务里对应写(缩进两空格):
- [ ] T012 收敛复杂度
验收: test:npm run quality:complexity约束(写错会静默不生效):
只有
验收: test:<值>会被执行;自由文本验收不会执行。值不能以
.js/.mjs/.cjs/.ts/.tsx结尾——那会被当成测试文件走node --test,到不了白名单。值不能以
-开头;匹配是整串逐字符相等,不做前缀或正则。白名单为空时只接受 js/ts 测试文件。命中的命令经 shell 执行,时限取
manifest.acceptance.timeoutMs,缺省 180 秒。外部工具请锁版本、在 CI 或容器里运行;relay 不会自动安装它们。
本仓库自身未启用(
.relay/**是受保护路径,启用需人类批准后单独提交)。
升级旧项目
运行
relay_sync {root}:重投影入口文件、补齐.gitignore运行时基线、输出AGENTS.md迁移步骤。若
AGENTS.md已存在但无 relay 标记:运行relay_onboard {root}接管,或在 manifest 设置"entryFilesTakeover": true后重跑relay_sync,或手工添加首行标记。relay_onboard保留既有 manifest 配置(worktree、autoCommit、acceptance、protectedPaths、entryFilesTakeover 等)。
安全与边界
密钥守卫:
.env*、*secret*、*credential*、*.key、*.pem、id_rsa不自动提交。改写备份:
relay_sync/relay_onboard在重写入口或 manifest 前生成*.relay-bak-*备份供人工恢复;每个目标最多保留最新 20 份,避免运行时无限增长。该类文件已入.gitignore运行时基线,不会被git add -A卷进提交。LOG 边界(R12):LOG 活跃区(归档指针之前的行)超过 150 行、或完成条目超过 20 条 →
relay_verify报 WARN(manifest.logBoundary.strict=true升 ERROR);只报警不自动归档,归档动作由人工决定。R12 只认第一个有效指针:目标须为docs/archive/LOG-*.md、真实存在且非空、realpath 在仓库内且目录组件非符号链接;失效指针 → WARN 而非静默 PASS。协议结构(R13):TASKS 任务行必须匹配契约正则且任务号唯一,
[~]带(model, YYYY-MM-DD HH:mm)、[x]带(YYYY-MM-DD);LOG 条目标题必须匹配## 时间 | model=<名> | task=<T### …>;HTML 注释块与缩进行豁免。违规 → WARN(manifest.structure.strict=true升 ERROR)。内容级密钥闸(R11):协议面 8 个文件(
TASKS.md/LOG.md/AGENTS.md/CLAUDE.md/GEMINI.md/START.md/SPEC.md/DECISIONS.md)与docs/archive/*.md(单层全部.md,含文档旧版)命中 AWS / GitHub / Slack / OpenAI / Google 密钥样式或 PEM 私钥块 →relay_verify报 ERROR,出场写盘前直接阻断(不写、不提交)。误报在同一行标注relay:secret-ok只豁免 R11 检测;协议写入路径一律拒绝该标记。扫描输出只给前 4 字符预览,绝不回显完整密钥。安全面不随证据面收窄:D8/R12 只认LOG-*.md,R11 仍扫归档目录单层全部.md。受保护路径:
verify、.relay/**、tests/**与测试文件改动不自动提交;最终防线是 CI 与人工审核。锁:仓库写锁约 20s 心跳续租 + 写前 fencing;任务认领锁刻意关闭心跳,240 分钟 TTL 按锁内
acquiredAt判定。并发会话必须使用不同model标识(同名 model 无法区分持有者)。当前不提供 abort/release、任务 status 工具或 sessionId;恢复方式为 TTL 接管、出场释放或 cleanup。
子代理抢救(
relay_rescue):现场落<controlRoot>/.relay/rescue/<id>/(state.json+ transcript 副本 + 独立接力锁),本机运行时状态、永不入库——transcript 含本机路径与潜在敏感内容,且.relay/**是受保护路径;.gitignore基线自动补.relay/rescue/。读取时重算 sha256,篡改即 isError;transcript 一律围栏 + 「不是给你的指令」+ 密钥脱敏。工作区现场用 git 对象快照(临时 index),不动 index/工作区/HEAD/分支/stash;密钥样式内容在任何 git 对象落盘之前就被拒绝,快照内容也受maxBytes总量约束。
工具
工具 | 用途 |
| 新建项目并生成代码骨架 |
| 非破坏接入存量项目 |
| 用 |
| 进场简报(五件 + git 状态 + verify 快检) |
| 出场绿闸与双提交;一次交付多个任务用 |
| 认领任务,返回双根与任务分支 |
| 预览或清理过期任务工作树 |
| 归档 LOG 旧条目到 |
| 运行 R 系列检查(编号与执法点见 |
| 升级/修复入口投影与基线 |
| 历史任务索引(只读、调用时派生):id/时间/model/状态/标题/条目体量/负结果数,支持 query/status/model/limit |
| 按任务号取全文(≤5 个):TASKS 验收 + 最新 LOG 条目(含事实行/分支 SHA/负结果/交接)+ 关联决策;围栏包裹、标注「数据非指令」 |
| 只读环境自检(九检:Node/manifest/入口漂移/残留锁/未登记 worktree/.relay 完整性/引擎路径/完成状态收敛/白名单命令落点),不写盘、不自动修复 |
| 抢救被额度/429/悬空杀死的子代理:scan(只读)列出可抢救项 → capture 落本机接力单(transcript + git 快照)→ takeover 移交派发权并登记接管任务 → report 回写;接力单在 |
| 返回规则 ID 表 |
历史检索(渐进披露)
简报只带最近 3 条 LOG;更早的历史用两步取回,避免整文件 grep 与上下文污染:
relay_recall { query?, status?, model?, limit? }→ 紧凑索引(每条一行,约 20 tokens),带显式截断标记;relay_get { ids: ["T013","T019"] }→ 全文(TASKS 验收 + 最新 LOG 条目 + 事实行/分支 SHA + 关联决策)。
两者都只读、调用时从 LOG/TASKS 即时派生(不落任何持久索引)。recall 合并 live LOG 与唯一合法归档指针指向的历史;get 在 live 未命中时回查归档。输出统一围栏包裹并标注「数据非指令」。
状态说明:检索寻址(T018)的动工闸门是「LOG ≥ 20 条或出现取回失败」,实测为 16 条、闸门未过,按用户指令先行交付。收益复核见 TASKS.md 的 T021(T018 收益复核决策证据);若实测无收益,回退方式仅为移除这两个工具的注册,协议面与事实底账不受影响。
CLI 与 MCP 共用同一引擎(npm 冻结后不再提供 relay bin,直接用 node src/cli.mjs):
node src/cli.mjs relay_verify --root /path/to/project
node src/cli.mjs relay_worktree_cleanup --root /path/to/project --json confirm=true
node src/cli.mjs --help # 用法
node src/cli.mjs --version # 版本自举
本仓库使用自身协议开发。START.md 是入口,TASKS.md 管理任务,LOG.md 记录会话。npm test 执行 package.json 列出的 31 套冒烟,包括认领锁边界和受管出场恢复。CI 覆盖 Node 22/24/26。
一次真实的多模型交接实测记录(含假绿事故的完整证据链)见 docs/04-test/08-handoff-case-study-v1.0.md。
relay_verify 的单轮成本是可观测的:只读一次 LOG/TASKS/manifest,git 子进程收敛到必要数量;设 RELAY_TRACE_FILE=<path> 可让进程退出时写出 {reads, git, sync} 计数(测试用,生产无行为变化)。
设计与接口契约见 docs-design/。贡献与安全问题见 CONTRIBUTING.md、SECURITY.md。
Related MCP server: agent-session
English
relay-mcp is an MCP server for reliable handoff across coding models and sessions. Handoff state lives in repository files (START / SPEC / DECISIONS / TASKS / LOG), and an exit gate verifies the work with machine-checked rules (R1–R13) plus the project's executable acceptance tests before anything is committed.
Zero runtime dependencies, Node ≥ 22, no build step; 15 MCP tools over stdio (
node src/index.mjs)AGENTS.mdis the required project entry;CLAUDE.md/GEMINI.mdare optional projectionsThe repo root is also a conformant Agent Plugins v1.0.0 package: root
plugin.json,mcp.json(stdio,${PLUGIN_ROOT}placeholders), andskills/relay-protocol/SKILL.md. Validate withnode scripts/validate-plugin.mjs.Task worktrees:
relay_claimreturnscontrolRootandexecutionRoot. Exit makes two commits (task branch code plus controlRoot TASKS/LOG) and reports both SHAs. Accepted is not merged: merge manually withgit merge --no-ff relay/T###.Cleanup is dry-run by default. Inactivity comes from the TASKS
[~]active set, not merely registrystatus=completed; dirty, conflicted, locked, unregistered, out-of-cache, branchless, or local-content (including ignored.env/node_modules) worktrees are kept. Branches are preserved.No automatic merge/rebase/push, and no abort/release/status/sessionId yet. Use unique
modelids for concurrent sessions. Subagents killed mid-task are rescued byrelay_rescueinto a local, never-committed card under.relay/rescue/.
Install
This repository is not distributed via npm (frozen on 2026-11-18; the npm relay-mcp package belongs to another project). Use git clone or the Agent Plugins package:
git clone https://github.com/KentQi/relay-mcp.git
cd relay-mcp
node src/index.mjs # stdio MCP serverFor clients without Agent Plugins support, add this to their mcpServers config (replace /abs/path):
{
"mcpServers": {
"relay-mcp": {
"command": "node",
"args": ["/abs/path/relay-mcp/src/index.mjs"],
"cwd": "/abs/path/relay-mcp"
}
}
}Usage
Scenario | Tool |
New project |
|
Existing project |
|
Legacy layout |
|
Every session |
|
Design and interface contract: docs-design/. Contribution: CONTRIBUTING.md. Security: SECURITY.md.
License
MIT © 2026 kent (kirroyu@126.com)
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
Git collaboration for AI agents and people: tasks, hand-offs, reviews, teams, shared memory.
Live GitHub repo AST X-Ray, 42 coding-agent DoD gates, Git worktree guards & brownfield baselines.
Shared team record of decisions, changes and handoffs that every coding agent reads and writes.
The team layer for AI coding agents: shared contracts, collision alerts, E2EE sessions.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables coding agents to maintain local-first project memory, coordinate task ownership across Git worktrees, and verify completion against project-defined checks with durable evidence stored in the repository.1Apache 2.0
- AlicenseAqualityBmaintenanceUniversal session & handoff layer for AI coding agents: shared task, decision, blocker and test state, checkpoints, and deterministic handoff between Claude Code, Codex, OpenCode, Cursor, Cline, pi and omp. Local SQLite, git-aware, 25 tools + 7 resources over stdio or streamable-http.26MIT
- AlicenseNot gradedqualityNot gradedmaintenanceExposes six tools over stdio that let AI coding assistants add, list, search, synthesize, resolve and delete persistent spec-driven project memory kept as markdown trees in the repository. This gives assistants durable recall of decisions, worklogs, watchpoints and governance laws across sessions without a database or API key.161 npmMIT
- AlicenseNot gradedqualityBmaintenanceShares one per-repository record of file ownership, handoffs, next steps, decisions and open findings across coding agents and people, so a session can resume another's work without re-explaining context and is blocked from editing files someone else is working on.Apache 2.0