5.4 KiB
| name | description | version | author | tags | |||||
|---|---|---|---|---|---|---|---|---|---|
| code-intelligence | Code intelligence MCP servers — codegraph, codebase-memory-mcp (CBM). Install, configure, use for code analysis. GFW-aware. | 1.1.0 | 小唯 |
|
Code Intelligence — 代码知识图谱 MCP 工具
本系统装配了多个代码智能 MCP 服务器,为 AI 代理提供代码级知识图谱能力。与织忆(语义/对话记忆)互补:CBM/Codegraph 管代码理解,织忆管用户记忆。
已配置工具
| 工具 | 语言 | 核心能力 | 存储 |
|---|---|---|---|
| codegraph | Node.js(npm 包 @colbymchenry/codegraph,v1.5.0) |
代码知识图谱(已配 Hermes,单一主工具 codegraph_explore) |
~/.openclaw/workspace/.codegraph/ + npm global bin |
| codebase-memory-mcp (CBM) | 纯 C(v0.9.0) | tree-sitter 158语言 → 函数/类/调用链/路由图谱 | ~/.cache/codebase-memory-mcp/ |
⚠️ codegraph 是 npm 包,不是 Go 二进制(2026-08-06 修正):旧版本文档误记为 Go、存储 ~/.cache/codegraph/。真实情况:npm 全局包,二进制进 npm global bin。重装命令:
npm install -g @colbymchenry/codegraph # 二进制进 npm global bin(which codegraph 验证) hermes mcp test codegraph # 验证 stdio 连接 + 工具发现v1.5.0 精简为单一主工具
codegraph_explore(旧 0.9.4 有 6 个工具:search/context/callers/callees/impact/node)。配置要求platform_toolsets.cli含mcp-codegraph(否则 MCP 工具被过滤)。config.yaml 里command: codegraph+args: [serve, --mcp]。⚠️ 查询前必须先建索引(2026-08-08 实测):
codegraph_explore报 "isn't indexed with codegraph (no .codegraph/ directory)" = 该项目没跑过 init。每个要查询的项目先:codegraph init -i /path/to/project # 建 .codegraph/ 索引(~135K 节点 8.7s,实测)之后
codegraph_explore才能返回符号/调用链/影响范围。查询时projectPath参数是必填的(指向项目目录或其子目录)。
安装新的代码智能 MCP 服务器
流程
- 下载源码 → 推送到本地 Gitea(见
references/gitea-workflow.md) - 安装 binary →
~/.local/bin/ - 配置 MCP → 配到 Hermes / OpenCode / OpenClaw
- 存记忆 →
memory_write记住安装位置和版本
GFW 规避(GitHub 下载慢/超时)
遇到 git clone / curl 下载 GitHub 超时:
1. 试 gh-proxy.com(https://gh-proxy.com/https://github.com/...)
→ git clone --depth 1 https://gh-proxy.com/https://github.com/user/repo.git
→ 或下载 zip:gh-proxy.com 路径 + /archive/refs/heads/main.zip
2. 保底:直接用 GitHub 直链(部分时候能通)
3. 先用代理下到 /tmp,再 git init + push Gitea
配置到各客户端
Hermes:
hermes mcp add <name> --command /home/muc/.local/bin/<binary>
# 如果交互式确认,echo "Y" | hermes mcp add ...
OpenCode:
自动被 codebase-memory-mcp install -y 识别,写入 ~/.config/opencode/opencode.json
OpenClaw:
自动被安装脚本识别,写入 ~/.openclaw/openclaw.json
手动配置 YAML(Hermes config.yaml):
mcp_servers:
<name>:
command: /path/to/binary
args: []
enabled: true
timeout: 120
使用模式
索引项目
codebase-memory-mcp cli index_repository --repo-path /path/to/repo
# 或在 Hermes 里让代理自动索引
实测索引性能(2026-07-30):
| 项目 | 文件 | 节点 | 边 | 时间 |
|---|---|---|---|---|
~/.hermes(配置/脚本) |
~2000 | 146,012 | 622,921 | ~30s |
/tmp/memoryweave(织忆 Go 代码) |
~500 | 5,331 | 20,403 | ~10s |
自动化生命周期(装完工具让它自己跑)
安装一个新代码智能工具后,按以下步骤让它自动为你工作:
| # | 步骤 | 为什么 | 示例(CBM) |
|---|---|---|---|
| 1 | 看门狗监控 | 进程挂了自动重启 | 加入 health-watchdog.sh 的 PROC_PATTERNS |
| 2 | 自动索引 cron | 每天刷新索引,不用手动 | 每日凌晨3点 no-agent 脚本跑 index_repository |
| 3 | 创建 skill | 遇场景自动调用工具 | cbm-code-analysis skill + SOUL.md 触发词表 |
| 4 | 注册 MCP | Hermes 会话中可直接用 | hermes mcp add |
| 5 | 存记忆 | 下个会话还记得 | memory_write 写版本/路径/索引项目 |
| 6 | Gitea 镜像 | GitHub 不可达时有备份 | git push 到 Gitea |
常见查询
| 场景 | 命令 |
|---|---|
| 项目概览 | get_architecture |
| 找函数/类 | search_graph(name_pattern=".*Handler.*", label=Function) |
| 调用链追踪 | trace_path(function_name="ProcessOrder", direction="inbound") |
| 读源码 | get_code_snippet(qualified_name="pkg.orders.OrderHandler") |
| Cypher 查询 | query_graph(query="MATCH (f:Function)-[:CALLS]->(g) RETURN f.name") |
| 变更影响分析 | detect_changes |
| 图结构查看 | get_graph_schema |
| 文本搜索 | search_code(pattern="error.*timeout") |
与织忆配合
代码理解 → 用 CBM 查代码图谱 → 结果存织忆
用户记忆 → 织忆管对话/偏好 → CBM 查代码
工具参考
见 references/codebase-memory-mcp.md — 详细安装记录、工具列表、版本信息。