clangd-mcp
MCP服务器使用cland和clang工具进行C/C++代码分析。提供诊断、符号搜索、包括分析、函数列表和代码格式化。
特性
- 检查文件 --在C/C++文件上运行cland诊断程序(错误、警告)
- find_symbol --跨源文件搜索符号定义(正则表达式)
- get_包含 --列出并分析#include指令
- list_functions --从文件中提取函数/方法声明
- clang_format --使用clang-format格式化代码(模拟运行或就地)
如果clangd不可用,则返回编译器语法检查(clang++、g++、MSVC)。
需求
- Python 3.10+
- 可选:cland、clang-format、ctags(用于完整功能)
- 即使没有安装clang工具,也可以使用回退功能
安装
pip install clangd-mcp或来源:
git clone https://github.com/ibuildrun/clangd-mcp.git
cd clangd-mcp
pip install -e .MCP配置
添加到您的 .kiro/settings/mcp.json:
{
"mcpServers": {
"clangd": {
"command": "clangd-mcp",
"disabled": false
}
}
}或者使用uvx:
{
"mcpServers": {
"clangd": {
"command": "uvx",
"args": ["clangd-mcp"],
"disabled": false
}
}
}使用示例
> check_file "src/game/client/components/menus.cpp" "build"
> find_symbol "RenderBackground" "src"
> get_includes "src/game/client/ui.h"
> list_functions "src/game/client/components/menus.cpp"
> clang_format "src/game/client/ui.cpp" "file" true许可证
麻省理工学院
