C++ MCP Server
Provides semantic analysis of C++ codebases using libclang, including symbol search, class details, inheritance hierarchies, type alias resolution, and call graph tracing.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
C++ MCP Server
An MCP (Model Context Protocol) server for analyzing C++ codebases using libclang.
About This Fork
This project is a fork of kandrwmrtn/cplusplus_mcp. The main intention of this fork was to add support for projects described by compile_commands.json.
⚠️ Development Status: This MCP server is currently in active development and is not suitable for production use. Use at your own risk.
Platform Support: This server has been primarily developed and tested to run on Linux and macOS. While Windows support may work, it is not the primary focus of development.
Related MCP server: MCP C++ Analyzer
Why Use This?
Instead of having an AI Agent grep through your C++ codebase trying to understand the structure, this server provides semantic understanding of your code. Agents 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 the AI Agent the ability to navigate your codebase like an IDE would.
Note: These tools are primarily intended for use with weaker LLM models running locally (e.g., via LM Studio or Ollama) to help them understand complex codebases, but they work equally well with frontier models like Claude 3.5 Sonnet or GPT-4o.
Features
Consolidated C++ code analysis tools (unified from multiple individual tools):
set_project - REQUIRED FIRST STEP: Set project directory or config file and wait for indexing completion.
sync_project - Check system status or trigger an incremental/full project refresh.
find_symbols_by_pattern - Discover classes and functions by name pattern with namespace and file filters.
find_in_file - List all symbols defined in a specific file.
get_class_info - Get detailed class information (methods, members, inheritance).
get_class_hierarchy - Get complete inheritance hierarchy for a class (ancestors, descendants, or both).
get_type_alias_info - Resolve type aliases (
using,typedef) and template aliases.find_outgoing_calls - Find functions called by a specific function (callees).
find_incoming_calls - Find functions that call a specific function (callers).
trace_execution_path - Find execution paths (call chains) between two functions.
Qualified Names Support:
Namespace-Aware Search: Search by qualified patterns like
"ui::View","app::Database::save".Template Specialization Detection: Distinguish
template<> void foo<int>()from generictemplate<typename T> void foo(T).Disambiguation: All results include
qualified_nameandnamespacefields.
Additional Capabilities:
Automatic Header Analysis: Project headers are automatically analyzed when included by source files.
Smart Deduplication: Headers are processed only once for optimal performance.
Incremental Analysis: Detects changes and re-analyzes only affected files (30-300x faster).
Error Recovery: Extracts symbols even from files with non-fatal parsing errors.
Transport Protocols
The server supports multiple transport protocols:
stdio (Default)
Standard input/output transport for MCP client integration (Claude Desktop, etc.):
python -m clang_index_mcpHTTP (Streamable HTTP)
RESTful HTTP transport for API access:
python -m clang_index_mcp --transport http --host 127.0.0.1 --port 8000SSE (Server-Sent Events)
Real-time streaming transport for event-driven applications:
python -m clang_index_mcp --transport sse --host 127.0.0.1 --port 8000For detailed HTTP/SSE usage, see HTTP_USAGE.md
Prerequisites
Python 3.10 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:
git clone https://github.com/andreymedv/clang_index_mcp.git
cd clang_index_mcpRun the setup script:
Linux/macOS:
./server_setup.shWindows:
server_setup.bat
Test the installation:
source mcp_env/bin/activate # Linux/macOS
python scripts/test_installation.pyPerformance Optimization
The analyzer is optimized for performance on multi-core systems.
Optional Dependencies
For large projects, install orjson for 3-5x faster JSON parsing:
pip install .[performance]Automatic Optimizations
GIL Bypass: Uses
ProcessPoolExecutorfor true parallel parsing.Binary Caching: Parsed
compile_commands.jsonand symbols are cached for fast subsequent startups.Intelligent Incremental Analysis: Re-analyzes only affected files when changes are detected.
Client Configuration
This MCP server can be used with various AI coding assistants and IDEs. See CLIENT_SETUP.md for detailed instructions for:
Claude Desktop / Claude Code
Cursor / Windsurf
Cline / Continue
Generic CLI Agent Configuration
To use this with an MCP-compatible CLI Agent, add the server to your configuration:
{
"mcpServers": {
"cpp-analyzer": {
"command": "python",
"args": ["-m", "clang_index_mcp"],
"cwd": "/absolute/path/to/clang_index_mcp",
"env": {
"PYTHONPATH": "/absolute/path/to/clang_index_mcp"
}
}
}
}Usage with AI Agent
Once configured, you can use the C++ analyzer in your conversations:
First, set your project directory:
"Set the project directory to /path/to/your/cpp/project"Then you can ask questions like:
"Find all classes containing 'Actor'"
"Show me the Component class details"
"Find all functions that call Update()"
"What functions does Render() call?"
"Show me the inheritance hierarchy for GameObject"
Configuration Options
The server behavior is configured via a .json configuration file. You must provide the path to this file when initializing the project.
The server loads configuration from:
The path explicitly passed to the
set_projecttool (recommended).The path specified by the
CPP_ANALYZER_CONFIGenvironment variable.
Example Configuration
{
"project_root": "/path/to/source",
"exclude_directories": [".git", "build", "node_modules"],
"include_dependencies": true,
"max_workers": null,
"query_behavior": "allow_partial",
"compile_commands": {
"enabled": true,
"path": "compile_commands.json"
}
}Key Options
project_root: (Optional) Specify the source root relative to the config file. This allows placing the config file outside the source tree.
exclude_directories: Directories to skip during project scanning.
include_dependencies: Whether to analyze files in dependency directories (e.g.,
third_party).max_workers: Number of worker processes (default:
null= use all CPU cores).query_behavior:
allow_partial(return results during indexing),block(wait for indexing), orreject.compile_commands: Configure the path and behavior for
compile_commands.jsonintegration.
For detailed information about compile_commands.json integration, see COMPILE_COMMANDS_INTEGRATION.md
Troubleshooting
Common Issues
"libclang not found" error
Run the setup script to download libclang automatically, or set
LIBCLANG_PATHenvironment variable to the path of yourlibclang.so/.dylib/.dll.
Server fails to start
Ensure Python 3.10+ is installed and all dependencies from
requirements.txtare available.
Parse warnings vs. fatal errors
The analyzer extracts what it can from files with syntax errors. If a file fails fatally, check its entry in
compile_commands.jsonor runpython scripts/diagnose_parse_errors.py.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
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.
Codebase intelligence for agents: 152 structured artifacts across 21 programs, one call.
Codebase intelligence for AI coding agents: graph, git history, docs, decisions, code health.
Related MCP Servers
- AlicenseAqualityDmaintenanceProvides C++ code intelligence tools for AI agents via the Model Context Protocol, enabling symbol navigation, type information, and diagnostics.951Mozilla Public 2.0
- FlicenseNot gradedqualityCmaintenanceProvides precise C++ code semantic analysis for AI coding tools like Claude Code and Cursor by integrating clangd static analysis, enabling symbol definition lookup, reference tracking, and hover information.1-
- FlicenseNot gradedqualityCmaintenanceBuilds 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-
- AlicenseNot gradedqualityDmaintenanceEnables semantic analysis and exploration of C++ codebases through libclang-backed tools for searching symbols, inspecting classes and functions, tracing call relationships, and checking indexing status and project statistics.MIT