Skip to main content
Glama
GusDawn123

cpp-analysis-mcp

by GusDawn123

cpp-analysis-mcp

一个 MCP 服务器,让 AI 编程代理能够真正测试 C++ 代码,而不仅仅是阅读它。

问题所在

有些 C++ 缺陷在源代码中是看不见的。这段代码看起来没问题:

void deposit(int amt) {
    balance += amt;   // no lock
}

从 100 个线程运行它,更新就会丢失。缺陷存在于时序中,而不是文本中,所以只读文件的 AI 会判定它是干净的。

能捕获这些缺陷的工具早已存在,而且非常出色。它们只是命令行程序,没有接入任何 AI 助手。这个项目就是那根接线。

Related MCP server: cpp-semantic-graph

它的功能

八个工具,三个问题:

问题

工具

成本

有什么看起来不对劲吗?

static_check_file / _snippet

秒级

它真的有问题吗?

sanitize_file / _project / _snippet

分钟级

哪里慢?

profile_file / _project

分钟级

代理从低成本手段开始,只在必要时升级。第八个工具 capabilities 会报告这台机器实际能运行什么。

底层技术:ThreadSanitizer 用于数据竞争,AddressSanitizer 用于内存破坏,LeakSanitizer 用于泄漏,UBSan 用于未定义行为,clang-tidy 和 -Wthread-safety 用于编译期检查,perf 用于性能分析。

平台支持

Linux

macOS

Windows

ASan、UBSan、静态检查

支持

支持

支持

TSan、LSan

支持

支持

支持,通过 WSL

性能分析器(perf)

支持

暂不支持

支持,通过 WSL

在 Windows 上,服务器会自动找到 WSL 发行版,并将仅限 Linux 的工具路由到其中。你仍然可以传入普通的 C:\ 路径。当某些内容无法运行时,服务器会直说,并指出可以修复问题的命令。

安装

你需要 Python 3.11+、uv 和一个 C++ 编译器(clang 或 gcc)。

git clone https://github.com/GusDawn123/cpp-analysis-mcp
cd cpp-analysis-mcp
uv sync

然后将其注册到你的代理中。对于 Claude Code:

claude mcp add cpp-analysis -- uv run --directory <path-to-repo> cpp-analysis-mcp

对于任何其他 MCP 客户端,将相同的命令添加到其配置文件中:

{ "mcpServers": { "cpp-analysis": {
    "command": "uv",
    "args": ["run", "--directory", "<path-to-repo>", "cpp-analysis-mcp"]
}}}

首次启动需要一分钟。服务器会为每项分析编译并运行一个带有缺陷的小程序,以证明该工具在你的机器上确实可用,然后缓存结果。

为什么你可以信任空结果

服务器从不轻信工具的一面之词。启动时它会植入一个真实的缺陷(数据竞争、泄漏、溢出),并要求每个检测器捕获它。如果某个检测器对已知缺陷保持沉默,它会被报告为不可用,并附上原因和修复所需的安装命令。

因此,空报告意味着一个已被证明在此处可用的检测器没有发现任何问题。这个区别很重要,因为一个静默失效的工具看起来和干净的代码一模一样。

架构

your AI agent (Claude Code, Cursor, anything that speaks MCP)
        |
    server.py        eight tools, no logic of its own
        |
    pipelines/       the recipes: check, sanitize, profile
        |
   +----------+-------------+
   |          |             |
 build/    process.py    parsers/
 compiles  runs tools    raw tool output in,
 the code  safely, with  clean findings out
   |       timeouts
   |
   +-- platforms/    what Linux, macOS, and Windows each need
   +-- toolchains/   what clang and gcc each need
   +-- wsl.py        Windows borrowing Linux for what it lacks

层规则由解析源代码树的测试强制执行,因此它们不会腐化:server.py 不包含控制流,只有 process.py 可以启动子进程,解析器从不触碰文件,并且只允许一个模块询问这台机器是什么。

测试

507 个单元测试可在任何地方运行,无需编译器。集成测试会编译并运行植入了缺陷的测试夹具,而在 Linux、macOS 和 Windows 上捕获的黄金输出让每个解析器都保持诚实。

make test

许可证

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that exposes LLDB debugging capabilities, enabling AI-assisted interactive debugging of C/C++ applications through 40 specialized tools.
    39 PyPI
    4
    MIT
  • F
    license
    Not graded
    quality
    B
    maintenance
    Builds a semantic knowledge graph of C++ code and exposes 9 MCP tools for AI assistants to search classes, functions, inheritance, callers, callees, overrides, and more.
    3
    -
  • F
    license
    B
    quality
    C
    maintenance
    Enables AI agents to perform comprehensive, zero-infrastructure codebase analysis through 24 MCP tools, covering security, quality, architecture, type safety, git history, and dead code detection with high precision and local privacy.
    45
    -