AgentHistoryMCP
AgentHistoryMCP is a local, read-only MCP server that unifies conversation history across 15+ AI coding agents for cross-tool search and seamless context handoff.
get_handoff_context: Build a budgeted handoff pack from a project’s recent sessions across other agents, including initial request, latest turns, touched files, and provenance.search_history: Full-text search pure dialog across agents in Chinese, English, and code identifiers, with filters for roles, agents, project, and result limit.list_sessions: List indexed sessions filtered by project/agent, with sorting and pagination.read_session: Live-read paginated dialog from original session files, supporting tree branches and optional compact tool-call details.list_projects: List discovered local projects with root paths, Git remotes, active agents, and session counts.get_agents_status: Inspect installed agents and adapter health, and optionally trigger an incremental index refresh.Keeps original files read-only, redacts common secrets, excludes verbose tool outputs, and isolates untrusted historical text.
Parses GitHub Copilot CLI workspace.yaml and events.jsonl session event streams, making Copilot CLI conversations available for project history search and cross-agent handoff.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@AgentHistoryMCP pick up my last Codex session for this project"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
agent-history-mcp
跨 AI Coding Agent 的统一本地历史检索与无缝上下文交接 MCP Server
简体中文 · English
为什么做 agent-history-mcp?
当你在一个项目上同时使用多个 AI Coding Agent —— 比如先在 Codex CLI 里讨论架构、改完第一轮代码,接着切到 Claude Code、Cursor、Gemini CLI、Antigravity 或 Pi 继续开发时,每个工具的对话历史都各自锁在私有目录和不同格式里,上下文瞬间断层。
agent-history-mcp 提供一个统一、纯本地、只读原始数据的 MCP Server:
所有客户端接入同一套 6 个只读 MCP 工具,无需为每个工具单独配置同步脚本。
切换工具后只需一句:“接手我刚才在 Codex 里关于这个项目的工作继续开发”,当前 Agent 即可毫秒级定位项目关联文件,现场直读最新纯对话,无缝续写。
偏好零常驻 MCP 开销的 Skill 形态? 查看独立项目 agent-history-skills —— 打包为单文件零依赖本地引擎,支持
npx skills add luo0629/agent-history-skills一键安装。
Related MCP server: voyager-mcp
架构一览
工作原理(三步极简闭环):
首次查询按需打标:不常驻后台、不主动偷扫硬盘;首次查询项目 A 时,为其他工具里未登记的会话文件记录轻量“项目标签卡片”(
project_id→ 原始文件路径)。增量秒级更新:之后在任意工具新开或续聊,下次查询仅花 ~20ms 对账新增/变更的少数文件,已打标的老文件完全不重扫。
现场直读纯对话:
get_handoff_context与read_session直接按卡片定位原始会话文件,现场读取最新纯user/assistant对话(彻底跳过冗长tool_result),不复制正文副本。
实测性能提升
基于真实 Windows 本机多工具历史库实测(1,540 个会话文件,含 1.7 GB Codex JSONL/ZST 与 965 MB Cursor state.vscdb):
实测维度 | 优化前(全量消息副本 + | 优化后(项目卡片 + 现场直读 + B-Tree) | 提升效果 |
965 MB Cursor 库查询 |
| 主键 B-Tree 范围索引 + 单会话 | 消除超时,毫秒级定位 |
冷启动同步吞吐 | 10.8s 处理 10 个文件 | 6.0s 处理 33 个文件(覆盖 6 工具 105 会话) | 吞吐量提升 3.3× |
Cursor 消息信噪比 | 15,569 条(混杂大量 | 3,372 条纯对话(92 个会话) | 冗余噪音减少 78.3% |
本地缓存正文副本 | 完整复制 | 零 | 随时可删重建,极轻占用 |
核心特性
零正文副本、不存
tool_result:~/.agent-history/index.db只存轻量项目标签目录卡片与纯对话 FTS5 倒排索引;读取与交接直接从原始文件现场直读。一处接入,全工具打通:基于 4 大可复用存储原型基类,开箱覆盖 15+ 主流 CLI 与 IDE Coding Agent。
专为“切换工具”打造的交接能力:
get_handoff_context自动排除当前工具(exclude_agent),按字符预算精准提取目标项目的初始需求、最新几轮对话与改动文件列表。中英文 + 代码标识符混合检索:利用 Node 原生
Intl.Segmenter("zh-CN")分词 + 驼峰/下划线切分 + SQLite FTS5 BM25 与时间衰减排序。零 C++ 编译依赖、跨平台零踩坑:基于 Node.js 22.5+ 内置
node:sqlite、原生Intl.Segmenter与纯 JSfzstd,告别node-gyp。隐私与安全优先:100% 本地离线只读、自动脱敏常见 API Key/Token、自动跳过本 MCP 自身调用防套娃,并用
<historical_session_data>隔离不可信历史文本。
支持的 AI Coding Agent
CLI 工具
工具 |
| 支持方式与特色能力 |
Codex CLI |
| JSONL 流解析,透明解压 |
Claude Code |
| 解析主会话与 |
Gemini CLI |
| 兼容 JSON / JSONL 对话、 |
Pi |
| 完整保留 DAG 多分支与 |
OpenCode |
| 只读白名单 SQLite 表,严格隔离凭据与认证表 |
Aider |
| 自动关联已发现项目根目录的 |
GitHub Copilot CLI |
| 解析 |
IDE 与桌面端工具
工具 |
| 支持方式与特色能力 |
Cursor |
| B-Tree 范围索引直读 |
Antigravity |
| 直达解析 |
VS Code Copilot Chat |
| 兼容新旧 JSONL / JSON 会话,自动反查 |
Cline |
| 支持 VS Code / Cursor / Windsurf 多宿主任务历史解析 |
Roo Code |
| 同构支持多宿主任务目录与对话记录解析 |
Kiro IDE |
| 双版本解析链:同时兼容 1.x |
Augment / Auggie |
| 探测本地 |
Windsurf Cascade |
| 诚实探测加密 |
通用导入兜底
工具 |
| 支持方式与特色能力 |
Universal Import |
| 将任意工具导出的 MD / JSON / JSONL / HTML 放入导入目录即可统一检索 |
快速开始
环境要求:Node.js
>= 22.5.0(内置node:sqlite,零外部数据库与编译工具依赖)
方式一:CLI 工具一行命令安装(自动拉取最新版本)
# Claude Code(全局生效)
claude mcp add agent-history -s user -- npx -y agent-history-mcp@latest
# Codex CLI(自动写入 ~/.codex/config.toml)
codex mcp add agent-history -- npx -y agent-history-mcp@latest
# Gemini CLI(全局生效)
gemini mcp add -s user agent-history -- npx -y agent-history-mcp@latest方式二:通用 mcpServers JSON(Cursor / Antigravity / Windsurf / Cline / Roo Code / Kiro / Augment)
将以下片段放入对应工具的 MCP 配置文件即可:
{
"mcpServers": {
"agent-history": {
"command": "npx",
"args": ["-y", "agent-history-mcp@latest"]
}
}
}OpenCode (~/.config/opencode/opencode.json)
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"agent-history": {
"type": "local",
"command": ["npx", "-y", "agent-history-mcp@latest"],
"enabled": true
}
}
}VS Code / GitHub Copilot Chat (.vscode/mcp.json)
{
"servers": {
"agent-history": {
"type": "stdio",
"command": "npx",
"args": ["-y", "agent-history-mcp@latest"]
}
}
}Codex CLI (~/.codex/config.toml)
[mcp_servers.agent-history]
command = "npx"
args = ["-y", "agent-history-mcp@latest"]git clone https://github.com/luo0629/agent-history-mcp.git
cd agent-history-mcp
npm install && npm run build && npm linkMCP 工具列表(6 个统一只读工具)
工具名 | 核心用途 |
| 一键组装目标项目的跨工具交接包(支持 |
| 跨工具中英文 + 代码标识符全文检索(仅搜纯对话,零 |
| 按项目 / Agent / 时间列出历史会话卡片 |
| 按卡片定位原始文件,现场直读分页或指定分支的纯对话 |
| 列出本机所有已聚合项目及活跃工具分布 |
| 五维探测所有适配器健康状态,并支持手动触发增量同步 |
内置诊断 CLI
无参数运行默认启动 STDIO MCP Server;传入子命令即可作为本地诊断工具使用:
npx -y agent-history-mcp@latest doctor # 一键体检所有 15+ 工具与索引统计
npx -y agent-history-mcp@latest sync --full # 对超大历史库执行一次全量离线索引
npx -y agent-history-mcp@latest projects # 查看已聚合的本地项目列表
npx -y agent-history-mcp@latest search "VideoPipeline 工作流" # 本地验证中英文 + 代码混合检索
npx -y agent-history-mcp@latest handoff "D:/Project/Verso" --exclude claude # 预览跨工具交接上下文包
npx -y agent-history-mcp@latest print-config # 打印各客户端即拷即用配置高级配置与隐私保护
空字符串的 dataDir 表示启用自动发现(绝不会被当作当前工作目录)。
{
"general": {
"databasePath": "~/.agent-history/index.db",
"autoDiscover": true,
"readOnlySources": true,
"syncDebounceSeconds": 3,
"maxContextChars": 20000
},
"agents": {
"codex": { "enabled": true, "dataDir": "" },
"claude": { "enabled": true, "dataDir": "" },
"cursor": { "enabled": true, "dataDir": "" },
"universal_import": { "enabled": true, "dataDir": "~/.agent-history/imports" }
},
"privacy": {
"redactSecrets": true,
"excludeProjects": [],
"excludePatterns": ["*.env", "*secret*", "*credential*"]
}
}原始文件只读:绝不修改任何工具的原始会话文件;
index.db随时可删并自动重建。自动密钥脱敏:返回前遮蔽常见 API Key、GitHub Token、Bearer Token、数据库连接串密码及私钥块。
凭据黑名单:严格跳过
.env、auth.json、oauth_creds.json及数据库认证表。Prompt Injection 隔离:历史正文统一包裹在
<historical_session_data ...>标签内。
开发与测试
npm run typecheck # TypeScript 严格类型检查
npm run build # 编译输出 dist/
npm test # 运行 25 项单元与真实 STDIO MCP 集成测试相关项目:agent-history-skills
如果你使用支持 Agent Skills 的工具(如 Claude Code、Codex CLI、Cursor、Antigravity、Pi、OpenCode 等),且希望平时零常驻工具 Schema 占用并内置跨工具交接 SOP,可以使用独立发布的 agent-history-skills(单文件自包含引擎,零 npm install,数据目录完全独立于 ~/.agent-history-skill/):
npx skills add luo0629/agent-history-skills选型建议 | agent-history-mcp(本项目) | |
适用场景 | 无 Shell 权限、希望 | 追求零常驻上下文占用、希望内置交接 SOP 与一键 Skill 分发的工具 |
License
本项目基于 MIT License 开源。
Available Tools
6 toolsget_agents_statusGet Agents & Adapters StatusARead-onlyIdempotent
Discover installed AI Coding Agents on this machine, inspect adapter health/compatibility (installed, data_found, readable, supported, indexed), and optionally trigger an incremental index refresh.
Inputs: agent, refresh.
get_handoff_contextGet Cross-Agent Handoff ContextARead-onlyIdempotent
Retrieve a compact, budgeted handoff context pack from the most recent sessions of a project across other AI Coding Agents (e.g. switching from Codex to Claude Code). Returns initial request, latest turns, touched files, and provenance.
Inputs: project_path (required), max_sessions, exclude_agent, source_agents, +1 more.
list_projectsList Discovered ProjectsARead-onlyIdempotent
List all local projects discovered across AI Coding Agents with canonical root paths, Git remotes, active agents, and session counts.
Inputs: include_unknown.
list_sessionsList Agent SessionsARead-onlyIdempotent
List indexed sessions across AI Coding Agents, optionally filtered by project path and agent_ids, sorted by recent activity.
Inputs: sort, limit, agents, offset, +1 more.
read_sessionRead Session Dialog (Live)ARead-onlyIdempotent
Read paginated user/assistant dialog turns live from the original session file (supports tree branches for Pi/Claude; verbose tool outputs are omitted).
Inputs: session_id (required), agent, limit, offset, +2 more.
search_historySearch Cross-Agent Dialog HistoryARead-onlyIdempotent
Full-text search across pure user/assistant dialog turns (Chinese, English, and camelCase/snake_case code identifiers) across all discovered AI Coding Agents. Tool outputs are excluded for high signal-to-noise ratio.
Inputs: query (required), limit, roles, agents, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool maps to a distinct operation: agent discovery/health, project listing, session listing, single-session reading, cross-agent full-text search, and a compact handoff pack. The only near-neighbor pair is get_handoff_context vs read_session, but one aggregates recent turns across sessions while the other pages through one session file, and the descriptions make that split explicit.
All names follow a consistent verb_noun snake_case pattern (get_, list_, search_, read_). The verbs accurately signal the operation type, making the set predictable to scan.
Six tools is well-scoped for a read-only cross-agent history server; each one covers a distinct stage of the discover-to-retrieve workflow with no filler.
The lifecycle is covered end to end: discover agents, list projects, list sessions, read or search turns, and package a handoff. Minor gaps remain — index refresh is buried as an optional flag on get_agents_status rather than its own tool, and there is no way to surface omitted tool outputs or per-session metadata without a full read, though both appear to be deliberate design choices.
Maintenance
Related MCP Connectors
One searchable history across every AI coding tool, with secret scanning and a shared task board.
Shared memory for coding agents. Stop re-explaining your codebase every session.
Sync coding-agent sessions and resume them in any other agent: Claude Code, Codex, Cursor, more.
Your coding agents' past sessions as memory: search them, open the turn, see where agents failed, rules, git blame for session
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to search and retrieve past coding-tool conversations across Claude Code, Claude Desktop, Codex, and Cursor through a local, read-only index.2MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI coding agents to query a unified local index of all their sessions through native tools, supporting session summaries, full-text search, listing, message timelines, and handoff context packages for another agent.8MIT
- AlicenseBqualityCmaintenanceEnables inspection of the local session stores kept by Codex, Claude Code, Antigravity, OpenCode, Freebuff and Grok through a single read-only interface, exposing recent sessions, individual session events, and full-history search. It also generates a one-call markdown handoff brief covering the goal, files touched, last observed state, blocker and suggested next steps, so a different agent or operator can resume work without cloud services or manual context copying.4MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to search a single local SQLite full-text index of past Claude Code and Codex sessions, Obsidian notes and attachments, GitHub activity, and imported Claude/ChatGPT chats, plus project timelines and recent items. It also lets one agent hand off a session briefing to another so work can continue in a different tool without re-explaining context.MIT