关于 claude-bridge-mcp
claude-bridge-mcp 是一款 MCP 服务,可将 Claude Code 会话输出提供给 Claude Chat 等 MCP 客户端。它还可将上下文保存为 Markdown 或同步到 Google Drive,并通过文件收件箱为会话排入提示词。
主要功能
- 01读取并列出本地 Claude Code 会话
- 02获取近期消息并监看新输出
- 03将上下文快照写为 Markdown
- 04将上下文同步到 Google Drive
- 05通过会话收件箱排入提示词
适用场景
- 01将终端 Agent 的近期输出带入 Claude Chat
- 02持续更新 Claude Project 的上下文文档
- 03向 Claude Code 会话发送提示词
MCP 相关
它通过工具向 MCP 客户端提供会话读取、上下文写入和提示词派发能力,也可通过工具设置并同步 Google Drive。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
8收录的工具列表 · 更新于 2 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| session_id | string | 否 | 可选的会话 ID。默认使用最近修改的会话。 |
详细介绍
claude-code-bridge-mcp
将 Claude Code 会话输出直接传入 Claude Chat 的 MCP 服务——再也不用在工具之间复制粘贴。
claude-code-bridge-mcp 是一个模型上下文协议(MCP)服务,可读取 Claude Code 在本地 ~/.claude/projects/<project-hash>/ 中的会话日志,并将其作为工具提供给任何兼容 MCP 的客户端(Claude Desktop、Claude Chat、Cursor 等)。在终端中运行 Claude Code,然后只需调用一次工具,即可将其最新输出传入 Claude Chat。
功能
get_latest_output— 获取任意 Claude Code 会话(或最近一次会话)中最新的助手消息。list_sessions— 列出所有本地会话,包含项目路径、消息数量和时间戳。get_session_context— 获取会话中最近的 N 条消息,注入上下文。watch_session— 每 2 秒轮询一次会话文件,并按需读取新消息。write_context(v2) — 将最近的 N 条消息保存为简洁的 Markdown,写入~/.claude/bridge-context.md和~/Documents/claude-bridge-context.md。start_auto_sync(v2) — 持续更新 Markdown 快照:每 30 秒(可配置)重写这两个文件,让同步文件夹保持最新,无需手动调用。setup_drive_sync(v2.1) — 授权直接上传到 Google Drive。此后每次同步都会通过 Drive API 更新名为claude-bridge-context的 Google 文档——无需 Drive 桌面客户端。send_to_session(v2.2) — 通过位于~/.claude/bridge-inbox/<session_id>.txt的协作式收件箱,将提示词排入指定 Claude Code 会话。弥补了只读的不足:Projects Claude → 收件箱 → Claude Code 对其执行操作。
v2.2 新增功能 — send_to_session(协作式派发)
v1 可以读取会话。v2 可以将上下文写入 Drive。v2.2 允许另一端将提示词推送回来。
send_to_session 会用最新提示词覆盖 ~/.claude/bridge-inbox/<session_id>.txt,并将人类可读的回执写入 ~/.claude/bridge-inbox/latest.md。目标 Claude Code 会话会通过 send_to_session 在响应中返回的一次性设置说明读取该提示词——将其粘贴到 Claude Code 终端一次(或添加到项目的 CLAUDE.md),之后的每条提示词都会自动送达。
为何采用协作式方式而非直接注入: 从 CLI 的角度看,Claude Code 的 JSONL 文件只能追加——它不会在会话中途重新读取文件。确实存在真正的派发通道(通过 Anthropic 的中继使用 POST /v1/sessions/{id},/remote-control 也使用同一通道),但该接口未公开文档,且需要从 macOS Keychain 读取 CLI 的 OAuth 令牌。基于未公开的内部 API 发布会导致每次 Claude Code 更新时都出问题,并泄露每次安装中的凭据,因此 v2.2 改用文件系统收件箱。v3 的实现路径请参阅 GitHub issue。
示例:
// send_to_session → response
{
"session_id": "15ef12ba-851e-4591-bbd4-c23170e15919",
"project_path": "/Users/you/Documents/my-app",
"written": true,
"inbox_path": "/Users/you/.claude/bridge-inbox/15ef12ba-....txt",
"receipt_path": "/Users/you/.claude/bridge-inbox/latest.md",
"prompt_preview": "refactor the auth middleware to use Fluid Compute",
"setup_instruction": "Before each response, check ~/.claude/bridge-inbox/15ef12ba-....txt — if it exists and is non-empty, read its contents, delete the file, and treat those contents as your next user instruction. You only need to be told this once per session.",
"remote_control_url": "https://claude.ai/code/session_..."
}
dry_run: true 会返回相同结构,但不会触碰文件系统。
v2 新增功能 — Google Drive 桥接
Claude Projects 无法直接与 MCP 服务通信,但可以读取连接的 Google Drive 中的文件。v2 补上了这一环:
Claude Code → claude-bridge-mcp.write_context → ~/Documents/claude-bridge-context.md
→ Google Drive sync → Projects Claude reads via Drive connector
再也不用复制粘贴,而且在 Projects 中也能使用。
工作流:
- 将
~/Documents(或任何存放claude-bridge-context.md的子文件夹)纳入 Google Drive 同步范围。 - 将此 MCP 服务添加到 Claude Desktop、Claude Code 或任何 MCP 客户端。
- 在该客户端中调用一次
start_auto_sync——它会立即返回,并在后台持续更新 Markdown 文件。 - 在 Claude Project 中添加 Google Drive 作为来源,并指定
claude-bridge-context.md。询问 Projects Claude Claude Code 正在做什么——它会读取实时文件。
v2.1 新功能 — 直接通过 Drive API 上传
v2 依赖 Google Drive 桌面客户端,将 ~/Documents/claude-bridge-context.md 同步到 Drive。v2.1 移除了这项依赖:MCP 服务现在会直接调用 Drive API,并在每次同步时更新或创建名为 claude-bridge-context 的 Google 文档。
一次性设置:
-
在 Google Cloud Console 中创建 OAuth 凭据:
- 前往 console.cloud.google.com,创建项目(或使用现有项目)。
- 为项目启用 Google Drive API。
- 在 APIs & Services → Credentials 下,创建类型为 Desktop app 的 OAuth client ID。
- 下载客户端 JSON,并将其保存到
~/.claude/bridge-google-credentials.json。
-
在环境中设置
GOOGLE_DRIVE_ENABLED=true以启用 Drive 同步,然后重新启动 MCP 服务。在 Claude Desktop 的claude_desktop_config.json中:{ "mcpServers": { "claude-bridge": { "command": "node", "args": ["/absolute/path/to/claude-code-bridge-mcp/dist/index.js"], "env": { "GOOGLE_DRIVE_ENABLED": "true" } } } } -
从任意已连接的客户端调用
setup_drive_sync工具。该工具会打开浏览器标签页以获取 Google 授权,将刷新令牌保存到~/.claude/bridge-google-token.json,并执行首次上传。响应中会包含文档 URL。 -
调用
start_auto_sync。从现在起,每次同步都会写入本地 Markdown 文件,并将相同内容推送到 Google 文档。之后重新启动服务时,会自动复用刷新令牌。
用户看到的内容:
- Drive 根目录中有一份名为
claude-bridge-context的 Google 文档,每 30 秒实时更新一次,内容为最新的 Claude Code 会话输出。 - 将其添加为任意 Claude Project 的来源,或直接打开——无需 Drive 桌面客户端,也无需复制粘贴。
**选择退出:**省略 GOOGLE_DRIVE_ENABLED(或将其设为除 true 以外的任何值),服务的行为就与 v2 完全相同——仅保存本地 Markdown,不调用 Drive。
安装
git clone https://github.com/rahuljava2807/claude-code-bridge-mcp.git
cd claude-code-bridge-mcp
npm install
npm run build
添加到 Claude Desktop
编辑 claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"claude-bridge": {
"command": "node",
"args": ["/absolute/path/to/claude-code-bridge-mcp/dist/index.js"]
}
}
}
重启 Claude Desktop。claude-bridge 工具会显示在工具选择器中。
使用
典型工作流:
- 在终端中运行
claude,启动 Claude Code 会话并开展工作。 - 在 Claude Chat 中询问:
“使用
list_sessions查找我最近的 Claude Code 会话,然后对其调用get_latest_output,并总结 Claude Code 刚才做了什么。” - 若要在耗时较长的 Claude Code 任务期间持续流式获取内容,请反复调用
watch_session——每次调用只返回自上次调用以来的新消息。
工具调用示例
// get_latest_output with no arguments → uses the most recently updated session
{
"content": "I've refactored the auth middleware to use Fluid Compute...",
"timestamp": "2026-04-16T15:32:11.441Z",
"session_id": "01HZ...",
"project_path": "/Users/you/code/my-app"
}
Claude Code 日志格式
会话以 JSONL 格式存储在:
~/.claude/projects/<project-hash>/<session-id>.jsonl
~/.claude/projects/<project-hash>/sessions/<session-id>.jsonl
每一行都是一个 JSON 事件,包含 type、role、content 和 timestamp 等字段。解析器能够容忍不同的数据结构,并从字符串和内容块负载中提取助手文本。
开发
npm run dev # tsc --watch
npm run build # compile to dist/
npm start # run the compiled server over stdio
许可证
MIT — 请参阅 LICENSE。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。