KC

kandrwmrtn/cplusplus_mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

34 stars 6 forks 质量 83 趋势 26MIT

一个MCP(模型上下文协议)服务器,用于使用 libclang 分析 C++ 代码库。

概览

一个MCP(模型上下文协议)服务器,用于使用 libclang 分析 C++ 代码库。 这个服务器不需要让 Claude 在你的 C++ 代码库中逐一浏览结构,而是提供对代码的语义理解。Claude 可以即时找到类、函数及其关系,而不会在成千上万的文件中丢失。它理解 C++ 语法、继承层级和调用图——让 Claude 能够像 IDE 一样浏览你的代码库。 上下文高效的 C++ 代码分析:- - 按名称模式查找类 - - 按名称模式查找函数 - - 获取详细类信息(方法、成员、继承) - 获取函数签名和参数 - - 在特定文件中搜索符号 - 获取类的完整继承层级结构 - 查找所有继承自基类的类 - 查找所有调用特定函数的函数 - 查找所有由特定函数调用的函数 - 查找从一个函数到...

概述(AI 翻译)

一个MCP(模型上下文协议)服务器,用于使用 libclang 分析 C++ 代码库。

为什么要用这个?

这个服务器不需要让 Claude 在你的 C++ 代码库中逐一浏览结构,而是提供对代码的语义理解。Claude 可以即时找到类、函数及其关系,而不会在成千上万的文件中丢失。它理解 C++ 语法、继承层级和调用图——让 Claude 能够像 IDE 一样浏览你的代码库。

特色

上下文高效的 C++ 代码分析:

  • search_classes - 按名称模式查找类
  • search_functions - 按名称模式查找函数
  • get_class_info - 获取详细的类信息(方法、成员、继承)
  • get_function_signature - 获取函数签名和参数
  • find_in_file - 在特定文件中搜索符号
  • get_class_hierarchy - 获取一个类的完整继承层级
  • get_derived_classes - 查找所有继承自基类的类
  • find_callers - 查找所有调用特定函数的函数
  • find_callees - 查找由特定函数调用的所有函数

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 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

  • 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

  1. Clone the repository:
git clone 
cd CPlusPlus-MCP-Server
  1. Run the setup script for your platform (this creates a virtual environment, installs dependencies, and fetches libclang if possible):

    • Windows
      server_setup.bat
      
    • Linux/macOS
      ./server_setup.sh
      
  2. 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.

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\\.claude.json
    C:\Users\\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"
          }
        }
      }
    }
    
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "cpp-analyzer": { "command": "python", "args": [ "-m", "mcp_server.cpp_mcp_server" ], "cwd": "YOUR_INSTALLATION_PATH_HERE", "env": { "PYTHONPATH": "YOUR_INSTALLATION_PATH_HERE" } } } }