CSG MCP Server
You can query a compiler-verified C/C++ code knowledge graph built from Coverity capture through 11 read-only MCP tools.
List translation units that truly participate in compilation, including full compiler arguments.
List all entities in a source file, sorted by line number.
Fuzzy-search symbols using FTS5 full-text search.
Get definition locations and entity details for symbols.
Query reverse call edges: which functions call a given function.
Query forward call edges: what functions a given function calls.
Analyze blast radius: functions affected by a change, grouped by propagation depth.
Find the shortest call path between two functions.
Retrieve Coverity static-analysis issues for a file with CID, checker, severity, location, and description.
Fetch a function-level CodeXM AST if exported during indexing.
Check index status, including TU/entity/call-edge/issue counts and build time.
Provides an LSP language server (csg-ls) that Neovim can be configured to use as a C/C++ language server, delivering go-to-definition, find references, hover (entity + compiler + defect counts), call hierarchy, and Coverity defect diagnostics backed by the prebuilt semantic graph database.
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., "@CSG MCP Server what's the blast radius if I change parse_packet?"
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.
Coverity Semantic Graph (CSG) — Server
基于 Coverity 真实编译捕获的编译器级 C/C++ 代码知识图谱服务端。 为 AI Agent(MCP 协议)与编辑器(LSP 协议)提供"编译器验证过"的代码语义查询, 解决 tree-sitter 系图谱工具拿不到真实编译文件、不理解编译器内置语义的问题。
配套 VSCode 插件见独立仓库:csg-vscode-extension。
架构
cov-build/--dir idir(任意编译器,含 GHS/IAR 模板)
→ csg-index:cov-manage-emit / cov-format-errors 出口解析 → SQLite 图库
→ csg-mcp:FastMCP stdio server,11 个只读查询工具(AI Agent 用)
→ csg-ls: LSP server(编辑器用,复用同一图库)查询与索引分离:MCP/LSP 只查预构建库,不起 cov 进程,毫秒级响应
CLI 为唯一数据出口:不解析 idir 内部未公开格式
一次建库、多端消费:AI Agent 与 VSCode 插件共享同一份编译器级事实
Related MCP server: Kivgraph
安装
pip install . # Python ≥ 3.10, mcp>=1,<2安装后得到 4 个命令:csg-index / csg-mcp / csg-ls / csg-agent-setup。
构建索引
# 真实模式(需 Coverity 许可)
csg-index --idir /path/to/idir --db ./graph.db \
--coverity-home /opt/coverity --ast-regex '^(main|parse_packet)$'
# 模拟模式(无 Coverity 环境,开发/测试)
python3 tests/mock_data.py mock_idir
csg-index --db ./graph.db --mock mock_idir接入 AI Agent(MCP)
csg-agent-setup --db ./graph.db --scope user --only claude,codex,opencodeClaude Code:写入
~/.claude.json(user)或.mcp.json(project)Codex CLI:写入
~/.codex/config.toml的[mcp_servers.csg]OpenCode:写入
~/.config/opencode/opencode.json的mcp段
也可手动配置:
// Claude Code / .mcp.json
{ "mcpServers": { "csg": { "command": "csg-mcp", "env": { "CSG_DB": "/abs/graph.db" } } } }# Codex CLI / ~/.codex/config.toml
[mcp_servers.csg]
command = "csg-mcp"
[mcp_servers.csg.env]
CSG_DB = "/abs/graph.db"接入编辑器(LSP)
CSG_DB=/abs/graph.db csg-ls # 任何 LSP 客户端均可接入VSCode:直接使用 csg-vscode-extension(已打包 vsix,设置
csg.dbPath即可)Neovim / 其他编辑器:将
csg-ls配置为 C/C++ 的 language server
LSP 提供(目标取代内置 C/C++ 插件的语义能力集):
定义/声明跳转、查找引用、悬停(实体+编译器+缺陷数)、调用层级、Coverity 缺陷诊断
符号补全(项目级 FTS 前缀匹配,resolve 显示位置与编译器)
大纲视图(documentSymbol)/ 全局符号搜索(Ctrl+T,workspaceSymbol)
签名帮助(基于已索引的 CodeXM AST 参数表)
MCP 工具(11 个,只读)
工具 | 功能 |
| 真实参与编译的 TU 及完整编译参数 |
| 文件内全部实体 |
| FTS5 符号模糊搜索 |
| 定义位置 |
| 编译器验证的调用边(反向/正向) |
| 变更影响面(按传播深度分层) |
| 最短调用路径 |
| Coverity 缺陷(CID/checker/严重级) |
| 函数级 AST(CodeXM 模型) |
| 索引状态 |
测试
python3 tests/test_pipeline.py # 15 项检查:mock 数据→索引→建库→查询→MCP
python3 tests/test_lsp.py # 12 项检查:definition/references/hover/callHierarchy/诊断格式校准(接入真实 idir 时必读)
src/csg/coverity.py 中的解析层按 Coverity 官方文档输出格式实现:
tus.json(cov-manage-emit list)、callees.json(find '.*' --print-callees)、
issues.json(cov-format-errors --json-output-v10,官方格式)。
--print-callees 原生为文本输出,本项目约定适配为 JSON。接入真实环境时:
在真实 idir 上运行
cov-manage-emit --dir idir find '.*' --print-callees > sample.txt;在
parse_entities中新增文本解析分支(或写脚本转成适配 JSON);对照
build-log.txt与官方文档校验--json-output-v10schema 差异;CI 中每次 Coverity 升级后重跑
tests/test_pipeline.py+ 真实抽样比对。
已知限制
--print-codexm为按函数导出,全程序图需基于 callees/definitions 拼装深层语义(数据流路径)建议用 CodeXM 自定义检查器补充为额外节点
解析层输出格式依赖 Coverity 版本,升级需回归测试
许可
本项目代码随附于仓库,Coverity 本身为商业软件,使用需自备许可。
Available Tools
11 toolsblast_radiusC
影响面分析:fn 变更会传播影响到哪些函数(按传播深度分层)。
Inputs: fn (required), max_depth. Returns: result
call_pathC
搜索 a 到 b 的最短调用路径。返回调用链数组,无路径返回 null。
Inputs: a (required), b (required), max_depth. Returns: result
file_issuesB
查询指定文件的 Coverity 静态分析缺陷(CID/checker/严重级/位置/描述)。
Inputs: file (required). Returns: result
get_astB
获取函数级 AST(CodeXM 模型 JSON)。需要索引阶段已导出该函数 AST。
Inputs: fn (required). Returns: result
get_definitionC
获取符号的定义位置(文件:行号)及实体信息。
Inputs: name (required). Returns: result
list_entitiesA
列出指定源文件中定义的全部实体(函数/变量/类型),按行号排序。
Inputs: file (required). Returns: result
list_tusA
列出真实参与编译的翻译单元(TU)及其完整编译参数。回答"哪些文件真正被编译了"。
Inputs: no named parameters. Returns: result
search_entitiesB
按名称模糊搜索符号(FTS5 全文检索),如 search_entities('parse_*')。
Inputs: query (required), limit. Returns: result
statusB
索引状态:TU/实体/调用边/缺陷数量及构建时间。
Inputs: no named parameters. Returns: result
what_callsC
查询 fn 调用了哪些函数(正向调用边)。
Inputs: fn (required). Returns: result
who_callsA
查询哪些函数调用了 fn(编译器验证的反向调用边)。
Inputs: fn (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Each tool targets a clearly distinct query type: entity listing/searching, definitions, call-graph directions, impact analysis, call paths, static-analysis defects, ASTs, index status, and translation units. who_calls vs. what_calls and blast_radius vs. call_path are explicitly differentiated by direction and analysis purpose.
All names use snake_case consistently, and most follow a readable verb_noun or query pattern. Minor deviations exist in noun-only names like blast_radius, call_path, file_issues, and status, but they remain clear and predictable within the set.
Eleven tools are well-scoped for a code-intelligence and static-analysis server, covering entities, call graphs, defects, ASTs, and build artifacts without obvious redundancy. Each tool appears to earn its place.
The surface covers core code-analysis workflows: symbol lookup, definitions, callers/callees, impact paths, Coverity defects, ASTs, status, and translation units. Minor gaps exist, such as global defect search/listing or general file/source retrieval, but agents can largely work around them.
Maintenance
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
Ask who calls a route, what a change breaks or who reads a field, across a system's repos.
Codebase intelligence for AI agents — dead code, blast radius, ownership.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query and analyze code across multiple repositories through a unified knowledge graph, with tools for symbol search, impact analysis, and graph algorithms.MIT
- AlicenseAqualityBmaintenanceEnables AI coding agents to query a semantic cross-repository code graph for symbols, references, callers, dependencies, and change impact across registered repositories.1224Apache 2.0
- AlicenseNot gradedqualityAmaintenanceEnables AI coding agents and IDEs to query a local structural code graph and retrieve focused, token-bounded context on code entities, Git relationships, callers/callees, impact, paths, and recorded mistakes for more efficient sessions.24 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables AI coding agents to query a local structural code graph, inspect relationships and impact, and retrieve focused project context before reading full files.24 npmMIT