🕸️ CodeGraph MCP 安装指南
一句话总结:CodeGraph(
codegraph-ai/CodeGraph)给代码库构建语义图(函数、类、import、调用链),通过 42 个 MCP 工具暴露给 agent,用 tree-sitter 解析 38 种语言。OpenCode 和 Harness 都能接入。
是什么
CodeGraph 是给 AI agent 和开发者的跨语言代码智能。核心能力:
- 用 tree-sitter 解析 38 种语言,构建函数/类/import/调用链的语义图
- 通过 42 个 MCP 工具、VS Code 扩展、JetBrains 插件、持久化记忆层暴露
- agent 拿到结构化的代码理解,而不是去 grep 文件
内置排除:自动跳过约 47 个目录(node_modules、target、dist、build、out、.git、__pycache__、.venv 等)和敏感目录(.aws、.ssh、.gnupg、.kube、.docker),外加二进制/原生库/密钥扩展名 glob——防止把凭据嵌入 embedding。
附带:一套预置 agent 规则文件(codegraph-rules-for-agents),教 Claude、Cursor、Windsurf、Codex、Cline 优先用 CodeGraph 工具、而不是一上来就 grep / 多文件读取。Setup 是 cp <agent>/codegraph.md ~/<agent>/(每个 agent 一行,见该规则仓库 README)。
安装(OpenCode)
先装好 codegraph-server 可执行文件(官方下载或 npm i -g @astudioplus/codegraph-mcp),再在 ~/.config/opencode/opencode.json 加本地 MCP:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"codegraph": {
"type": "local",
"command": ["/path/to/codegraph-server", "--mcp"],
"enabled": true
}
}
}改完重启 OpenCode。服务器自动索引当前工作目录。
通用 MCP 配置写法:
command: <codegraph-server 路径>+args: ["--mcp"]。任一带 MCP 的客户端都可用同形配置。
安装(Harness / DSH)
Harness 走 Cordis 插件方式,在 $DSH_HOME/settings.yaml 里加一条 @deepseek-ai/dsh-mcp-client:
- id: mcp-codegraph
name: '@deepseek-ai/dsh-mcp-client'
config:
serverName: codegraph
transport: stdio
command: /path/to/codegraph-server
args: ['--mcp']启动后工具以 mcp__codegraph__<tool> 形式出现。
常用配置参数(MCP server flags)
| Flag | 默认 | 说明 |
|---|---|---|
--workspace <path> | 当前目录 | 要索引的目录(可重复,多项目) |
--exclude <dir> | — | 跳过的目录(可重复) |
--embedding-model <model> | bge-small | bge-small / jina-code-v2 / granite-97m / static(model2vec,索引快 ~100×,无需 ONNX) |
--profile <name> | all | 收窄暴露的 MCP 工具面(all/core/graph/memory/security) |
--graph-only | off | 跳过 embedding,只建图 + 结构工具,索引快 10-50× |
--max-files <n> | 5000 | 最大索引文件数 |
--profile很有用:完整 42 个工具会撑大 agent 的 prompt 上下文。聊天类 agent 用core(8 个),重构/结构分析用graph(17 个),知识库类用memory(14 个)。
附:VS Code / JetBrains(非 agent 可选)
- VS Code:
code --install-extension codegraph-0.21.0.vsix。分析引擎不打包,首次激活时询问是否下载并校验 checksum 装进~/.codegraph/bin(JetBrains 共用同一位置)。 - JetBrains:装插件,同一引擎走 LSP,提供 Code Vision / Symbols / Memories 窗口、图面板、一键 MCP 注册。
这两项是 IDE 使用方式,与 OpenCode / Harness 的 MCP 接入独立,按需参考。
状态记录
- 2026-10-03:初版。整理 OpenCode / Harness 接入、配置参数、agent 规则。未实测——按官方 README 整理,未在 OpenCode / Harness 里实际跑过。
🔗 相关
- Superpower 安装指南 · Comet 安装指南 · Playwright MCP 安装指南 — 同批安装指南
- 官方仓库:codegraph-ai/CodeGraph
- agent 规则:codegraph-rules-for-agents