C++
STDIO使用libclang进行C++代码语义分析的服务器
使用libclang进行C++代码语义分析的服务器
An MCP (Model Context Protocol) server for analyzing C++ codebases using libclang.
Instead of having Claude grep through your C++ codebase trying to understand the structure, this server provides semantic understanding of your code. Claude can instantly find classes, functions, and their relationships without getting lost in thousands of files. It understands C++ syntax, inheritance hierarchies, and call graphs - giving Claude the ability to navigate your codebase like an IDE would.
Context-efficient C++ code analysis:
git clone <repository-url> cd CPlusPlus-MCP-Server
Run the setup script for your platform (this creates a virtual environment, installs dependencies, and fetches libclang if possible):
server_setup.bat
./server_setup.sh
Test the installation (recommended):
# Activate the virtual environment first mcp_env\Scripts\activate # Run the installation test python scripts\test_installation.py
This will verify that all components are properly installed and working. The test script lives at scripts/test_installation.py.
To use this MCP server with Claude Code, you need to add it to your Claude configuration file.
Find and open your Claude configuration file. Common locations include:
C:\Users\<YourUsername>\.claude.json
C:\Users\<YourUsername>\AppData\Roaming\Claude\.claude.json
%APPDATA%\Claude\.claude.json
The exact location may vary depending on your Claude installation.
Add the C++ MCP server to the mcpServers section:
{ "mcpServers": { "cpp-analyzer": { "command": "python", "args": [ "-m", "mcp_server.cpp_mcp_server" ], "cwd": "YOUR_INSTALLATION_PATH_HERE", "env": { "PYTHONPATH": "YOUR_INSTALLATION_PATH_HERE" } } } }
IMPORTANT: Replace YOUR_INSTALLATION_PATH_HERE with the actual path where you cloned this repository.
Restart Claude Desktop for the changes to take effect.
To use this MCP server inside the OpenAI Codex CLI:
Make sure the virtual environment is created (see setup above).
Create a .mcp.json file in the project you open with Codex. The CLI reads this file to discover MCP servers.
Add an entry that points to the Python module inside the virtual environment. Replace YOUR_REPO_PATH with the absolute path to this repository.
{ "mcpServers": { "cpp-analyzer": { "type": "stdio", "command": "YOUR_REPO_PATH/mcp_env/bin/python", "args": [ "-m", "mcp_server.cpp_mcp_server" ], "env": { "PYTHONPATH": "YOUR_REPO_PATH" } } } }
On Windows change command to YOUR_REPO_PATH\\mcp_env\\Scripts\\python.exe.
Restart the Codex CLI (or run codex reload) so it picks up the new server definition.
Inside Codex, use the MCP palette or prompt instructions (for example, "use the cpp-analyzer tool to set the project directory to ...") to start indexing your C++ project.
If you keep the .mcp.json file inside this repository you can also add a "cwd": "YOUR_REPO_PATH" entry so Codex launches the server from the correct directory.
Once configured, you can use the C++ analyzer in your conversations with Claude:
First, ask Claude to set your project directory using the MCP tool:
"Use the cpp-analyzer tool to set the project directory to C:\path\to\your\cpp\project"
Note: The initial indexing might take a long time for very large projects (several minutes for codebases with thousands of files). The server will cache the results for faster subsequent queries.
Then you can ask questions like:
The server behavior can be configured via cpp-analyzer-config.json:
{ "exclude_directories": [".git", ".svn", "node_modules", "build", "Build"], "exclude_patterns": ["*.generated.h", "*.generated.cpp", "*_test.cpp"], "dependency_directories": ["vcpkg_installed", "third_party", "external"], "include_dependencies": true, "max_file_size_mb": 10 }
"libclang not found" error
server_setup.bat (Windows) or ./server_setup.sh (Linux/macOS) to let the project download libclang automaticallyclang+llvm-*-x86_64-pc-windows-msvc.tar.xzclang+llvm-*-x86_64-apple-darwin.tar.xzclang+llvm-*-x86_64-linux-gnu-ubuntu-*.tar.xzbin\libclang.dll to lib\windows\libclang.dlllib\libclang.dylib to lib\macos\libclang.dyliblib\libclang.so.* to lib\linux\libclang.soServer fails to start
python --versionpip install -r requirements.txtmcp_env\Scripts\activate python -m mcp_server.test_installation
Claude doesn't recognize the server
.claude.json are absolute pathsClaude uses grep/glob instead of the C++ analyzer
CLAUDE.md file telling Claude to prefer the cpp-analyzer for C++ symbol searches