Provides semantic analysis of C++ codebases using libclang, including finding classes and functions, viewing class hierarchies, analyzing inheritance relationships, and generating call graphs.
C++ MCP Server
An MCP (Model Context Protocol) server for analyzing C++ codebases using libclang.
Why Use This?
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.
Features
Context-efficient C++ code analysis:
search_classes - Find classes by name pattern
search_functions - Find functions by name pattern
get_class_info - Get detailed class information (methods, members, inheritance)
get_function_signature - Get function signatures and parameters
find_in_file - Search symbols within specific files
get_class_hierarchy - Get complete inheritance hierarchy for a class
get_derived_classes - Find all classes that inherit from a base class
find_callers - Find all functions that call a specific function
find_callees - Find all functions called by a specific function
get_call_path - Find call paths from one function to another
Prerequisites
Python 3.9 or higher
pip (Python package manager)
Git (for cloning the repository)
LLVM's libclang (the setup scripts will attempt to download a portable build)
Setup
Clone the repository:
Run the setup script for your platform (this creates a virtual environment, installs dependencies, and fetches libclang if possible):
Windows
server_setup.batLinux/macOS
./server_setup.sh
Test the installation (recommended):
This will verify that all components are properly installed and working. The test script lives at scripts/test_installation.py
.
Configuring Claude Code
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.jsonThe 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.
Configuring Codex CLI
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
toYOUR_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.
Usage with Claude
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:
"Find all classes containing 'Actor'"
"Show me the Component class details"
"What's the signature of BeginPlay function?"
"Search for physics-related functions"
"Show me the inheritance hierarchy for GameObject"
"Find all functions that call Update()"
"What functions does Render() call?"
Architecture
Uses libclang for accurate C++ parsing
Caches parsed AST for improved performance
Supports incremental analysis and project-wide search
Provides detailed symbol information including:
Function signatures with parameter types and names
Class members, methods, and inheritance
Call graph analysis for understanding code flow
File locations for easy navigation
Configuration Options
The server behavior can be configured via cpp-analyzer-config.json
:
exclude_directories: Directories to skip during project scanning
exclude_patterns: File patterns to exclude from analysis
dependency_directories: Directories containing third-party dependencies
include_dependencies: Whether to analyze files in dependency directories
max_file_size_mb: Maximum file size to analyze (larger files are skipped)
Troubleshooting
Common Issues
"libclang not found" error
Run
server_setup.bat
(Windows) or./server_setup.sh
(Linux/macOS) to let the project download libclang automaticallyIf automatic download fails, manually download libclang:
Download the appropriate file for your system:
Windows:
clang+llvm-*-x86_64-pc-windows-msvc.tar.xz
macOS:
clang+llvm-*-x86_64-apple-darwin.tar.xz
Linux:
clang+llvm-*-x86_64-linux-gnu-ubuntu-*.tar.xz
Extract and copy the libclang library to the appropriate location:
Windows: Copy
bin\libclang.dll
tolib\windows\libclang.dll
macOS: Copy
lib\libclang.dylib
tolib\macos\libclang.dylib
Linux: Copy
lib\libclang.so.*
tolib\linux\libclang.so
Server fails to start
Check that Python 3.9+ is installed:
python --version
Verify all dependencies are installed:
pip install -r requirements.txt
Run the installation test to identify issues:
mcp_env\Scripts\activate python -m mcp_server.test_installation
Claude doesn't recognize the server
Ensure the paths in
.claude.json
are absolute pathsRestart Claude Desktop after modifying the configuration
Claude uses grep/glob instead of the C++ analyzer
Be explicit in prompts: Say "use the cpp-analyzer to..." when asking about C++ code
Add instructions to your project's
CLAUDE.md
file telling Claude to prefer the cpp-analyzer for C++ symbol searchesThe cpp-analyzer is much faster than grep for finding classes, functions, and understanding code structure
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
An MCP server that provides semantic understanding of C++ codebases using libclang, allowing Claude to instantly find classes, functions, and their relationships without having to grep through thousands of files.
Related MCP Servers
- -securityFlicense-qualityA MCP server that exposes OpenAPI schema information to LLMs like Claude. This server allows an LLM to explore and understand large OpenAPI schemas through a set of specialized tools, without needing to load the whole schema into the contextLast updated -2944
- AsecurityAlicenseAqualityAn MCP server that implements Claude Code-like functionality, allowing the AI to analyze codebases, modify files, execute commands, and manage projects through direct file system interactions.Last updated -15267MIT License
- -securityFlicense-qualityAn MCP server that integrates with Claude to provide smart documentation search capabilities across multiple AI/ML libraries, allowing users to retrieve and process technical information through natural language queries.Last updated -
- AsecurityAlicenseAqualityAn MCP server that scans codebases to extract structural information (classes, functions, etc.) with flexible filtering options and outputs in LLM-friendly formats.Last updated -13GPL 3.0