C++ MCP Server

C++ MCP Server

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.

Category
访问服务器

README

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

  • Windows operating system (may work on macOS/Linux but not tested)
  • Python 3.9 or higher
  • pip (Python package manager)
  • Git (for cloning the repository)

Setup

  1. Clone the repository:
git clone <repository-url>
cd CPlusPlus-MCP-Server
  1. Run the setup script (this will create a virtual environment, install dependencies, and download libclang):
server_setup.bat
  1. 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 is located 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.

  1. 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.

  2. 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.

  3. Restart Claude Desktop for the changes to take effect.

Usage with Claude

Once configured, you can use the C++ analyzer in your conversations with Claude:

  1. 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.

  2. 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": [".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
}
  • 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

  1. "libclang not found" error

    • Run server_setup.bat to download libclang automatically
    • If automatic download fails, manually download libclang:
      1. Go to: https://github.com/llvm/llvm-project/releases
      2. 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
      3. Extract and copy the libclang library to the appropriate location:
        • Windows: Copy bin\libclang.dll to lib\windows\libclang.dll
        • macOS: Copy lib\libclang.dylib to lib\macos\libclang.dylib
        • Linux: Copy lib\libclang.so.* to lib\linux\libclang.so
  2. 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
      
  3. Claude doesn't recognize the server

    • Ensure the paths in .claude.json are absolute paths
    • Restart Claude Desktop after modifying the configuration
  4. 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 searches
    • The cpp-analyzer is much faster than grep for finding classes, functions, and understanding code structure

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选