Files
tao-memory-mcp/README.md
2026-03-15 13:08:00 +08:00

236 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Tao Memory MCP Server (Go)
面向 MCP 的“道场记忆”服务SSE + JSONRPC 2.0,支持移动端、异步响应、灵感/日记/周月季半年年炼化与归档剪枝。
---
## 功能总览
- **MCP 协议**SSE + `/mcp/message` 异步响应POST 返回 202
- **鉴权**Header Bearer 或 `?token=`
- **工具体系**:检索、灵感、日记、周/月/季/半年/年总结、归档剪枝、代码巡检提案
- **存储结构**六级流转YEAR/H1|H2/Q/Month/Wxx
- **归档剪枝**:月度归档至 `_Archive`,检索默认跳过归档
---
## 目录结构(六级流转)
```
knowledge_ocean/
2026/
H1_Upper/
Q1/
03_March/
W11/
2026-03-14_Saturday.md
Week_Summary.md
Month_Summary.md
Semiannual_Summary.md
H2_Lower/
...
Year_Summary.md
Inspirations/
Idea_1710400000.md
_Archive/
2026/03/...
_Proposals/
proposal_20260314_150405.md
```
---
## MCP 端点
- **SSE**`/mcp/sse?token=...&client=...`
- **消息**`/mcp/message?token=...&client=...`
- **统一入口**`/mcp``/mcp/`
- `GET /mcp` → SSE
- `POST /mcp` → 自动判定 SSE 或 JSONRPC
> `client` 用于区分多端连接,避免同一 token 抢占 SSE 通道。
**特性:**
- `POST /mcp/message` 只返回 `202 Accepted`
- 所有 JSONRPC 响应通过 SSE `event: message` 返回
- CORS 可配置(默认不放行;设置 `TAO_CORS_ORIGINS=*` 才全放开)
---
## 工具清单
### 1) query_memory
全文检索(默认不搜索归档)
- `q` (string)
- `mode` (exact|causal, 默认 exact)
- `related_terms` (array<string>) 仅 mode=causal
- `include_archive` (bool, 默认 false)
**causal 输出标注:** `[命中: 关键词]` / `[关联: 关键词]`
---
### 2) get_week_data / record_summary
- `get_week_data(weekOffset)`:获取周素材
- `record_summary(content, weekOffset)`:写入 `Week_Summary.md`
- 若缺少 `### 📅 时空坐标`,自动套“炼丹笔记”模板
---
### 3) capture_idea
捕获灵感并**双写**
- 写入 `Inspirations/Idea_*.md`YAML Frontmatter + tags
- 同时写入当天日记category=idea
参数:
- `content` (string)
- `tags` (array<string>, 可选;默认 Unsorted)
---
### 4) record_daily
写入当日日记(不会进入灵感库)
参数:
- `content` (string)
- `karma` (int, 默认 1)
---
### 5) 月/季/半年/年炼化
- `get_month_data` / `record_month_summary`
- `get_quarter_data` / `record_quarter_summary`
- `get_semiannual_data` / `record_semiannual_summary`
- `get_year_data` / `record_year_summary`
产物:
- `Month_Summary.md`
- `Quarter_Summary.md`
- `Semiannual_Summary.md`
- `Year_Summary.md`
---
### 6) housekeep_memory
归档剪枝(按月)
参数:
- `target_month` (YYYY-MM)
逻辑:
- 校验 `Month_Summary.md` 存在且大小≥100字节且包含 `###`
- 将该月 `Wxx/` 目录及非 Month_Summary 文件移动到 `_Archive/YYYY/MM/`
- 生成 `ARCHIVED.txt`
- `query_memory` 默认跳过 `_Archive`
---
### 7) inspect_and_propose
检视代码与灵感,生成补丁建议清单(不自动应用)
参数:
- `repo_path` (可选,默认 `/root/.openclaw/workspace/tao_mcp_go`)
行为:
- `git pull`(需 `TAO_ALLOW_GIT_PULL=true` 才会执行,失败不阻断)
- `repo_path` 必须在 `TAO_ALLOWED_REPOS` 白名单内
- 扫描 `Inspirations``#Todo/#Fix`
- 生成 `_Proposals/proposal_<timestamp>.md`
- 当日日记记录摘要
---
## 配置项(安全建议)
- **TAO_AUTH_TOKEN**:必填;不设置则启动失败
- **TAO_ALLOW_ANON**:是否允许匿名访问(默认 false
- **TAO_CORS_ORIGINS**:允许的来源列表,逗号分隔;`*` 为全放开
- **TAO_DEBUG**:是否输出请求体日志(默认 false
- **TAO_SEARCH_ROOT**:检索根目录(必须在 MEMORY_ROOT 下)
- **TAO_SEARCH_MAX_FILES**:检索文件上限(默认 2000
- **TAO_ALLOWED_REPOS**inspect_and_propose 允许的仓库白名单(逗号分隔)
- **TAO_ALLOW_GIT_PULL**:是否允许 inspect_and_propose 执行 git pull默认 false
- **TAO_ENDPOINT_TOKEN_ECHO**:若为 trueSSE endpoint 事件会回显 token用于不带 Header 的客户端;默认 false
---
## OpenClaw 接入(示例)
**Base URL**
```
https://mcp.good.xx.kg
```
**Auth Token**
```
YOUR_TOKEN_HERE
```
**Instructions粘贴**
```
你接入的是 Tao-Memory-Pro MCP。
【语义判断(先判类型)】
- 若内容包含“观点/架构/设计/方案/原理/模型/机制/灵感/idea”或明显是抽象总结/新想法 → 视为“灵感”
- 若内容是当天发生的事务、进度、琐事、对话摘录 → 视为“日记”
- 若内容在请求“总结/复盘/归档/检索” → 视为“操作指令”
【优先级规则】从上到下匹配,命中即停止:
1) “灵感” → capture_idea
- tags: 自动生成 2~4 个标签
2) “周总结/本周复盘/weekly” → record_summary
3) “月总结/月度/monthly” → record_month_summary
4) “季总结/季度/quarterly” → record_quarter_summary
5) “半年总结/上半年/下半年/half-year” → record_semiannual_summary
6) “年度/年报/yearly” → record_year_summary
7) “归档/清理/剪枝/整理/月度清理” → housekeep_memory要求 YYYY-MM
8) “查找/搜索/回忆/翻找/找一下” → query_memory
- 提到“历史/很久以前/归档/旧记录” → include_archive=true
- 提到“关联/因果/相关/对比/溯源” → mode=causal + related_terms
9) “随手记/日记/今天/记录一下/写一条” → record_dailykarma=1
【冲突处理】
- 同时满足灵感与日记:优先灵感
- 同时包含检索与归档:优先问目标月份或关键词
- 不确定时:先反问澄清,不调用工具
【输出风格】
- 工具调用后只返回结果路径或简短确认,不展开解释
【自动标签规则(用于 capture_idea
- 若内容含MCP/SSE/JSON-RPC/协议 → tags 加 ["协议","MCP"]
- 若含AnyTLS/TUIC/QUIC/延迟/带宽 → tags 加 ["网络协议","性能"]
- 若含:架构/模块/重构/设计 → tags 加 ["架构设计"]
- 若含:日志/排障/错误/异常 → tags 加 ["故障排查"]
- 若含:部署/Docker/systemd → tags 加 ["运维部署"]
- 若含:搜索/索引/向量/检索 → tags 加 ["检索系统"]
- 若含:安全/鉴权/token → tags 加 ["安全"]
- 若含:任务/待办/计划 → tags 加 ["待办"]
若匹配不足 2 个标签,则补充通用标签:["灵感","技术"]
```
---
## 编译与运行
```bash
cd /root/.openclaw/workspace/tao_mcp_go
go build -o tao-mcp
./tao-mcp
```
## Systemd
```bash
systemctl restart tao-mcp-go
systemctl status tao-mcp-go
```
---
## 备注
- SSE 已设置 `X-Accel-Buffering: no`
- MCP 协议版本:`2025-06-18`
- `TAO_ENDPOINT_STYLE=message` 避免 `/mcp/mcp` 叠加