UNPKG

cpp-enhancement-mcp-server

Version:

MCP server for C++ programming enhancement with modern best practices, performance optimization, and real-time web research. Requires Python 3.8+.

218 lines (166 loc) 6.28 kB
# C++ Programming Enhancement MCP Server A Model Context Protocol (MCP) server that enhances AI assistance for C++ programming by providing modern best practices, performance optimization guidance, RAII advice, template programming help, and real-time web research capabilities. ## Features ### 🔍 Code Analysis & Suggestions - Analyze C++ code for modern best practices - Detect common anti-patterns and suggest improvements - Identify memory management issues - Check for const correctness and type safety ### 🚀 Modern C++ Guidance - **Auto keyword**: Best practices for type deduction - **Smart pointers**: RAII-compliant memory management - **Move semantics**: Efficient resource transfer - **Constexpr**: Compile-time computation - **Concepts (C++20)**: Template constraints with clear requirements ### ⚡ Performance Optimization - **Cache locality**: Memory access pattern optimization - **Vectorization**: SIMD optimization techniques - **Memory management**: Efficient allocation strategies - **Compiler optimizations**: Best practices for performance ### 🛡️ Memory Safety & RAII - Smart pointer usage patterns - Resource management best practices - Exception safety guidelines - Ownership semantics ### 🔧 Template Programming - **CRTP**: Curiously Recurring Template Pattern - **SFINAE**: Substitution Failure Is Not An Error - **Concepts**: Modern template constraints - **Variadic templates**: Variable argument templates - **Type traits**: Compile-time type manipulation ### 🌐 Real-time Research (Brave Search API) - **Live web search** for latest C++ techniques and best practices - **Real-time results** from authoritative sources like ISO C++, CppCon, blogs - **Recent developments** in C++20/23/26 features - **Community discussions** from Stack Overflow, Reddit, GitHub - **Performance guides** and optimization techniques - **Fallback to curated knowledge** when API is not configured ## Installation ### Quick Start with npm ```bash # Install and run npx cpp-enhancement-mcp-server # First-time setup (configure Brave Search API) npx cpp-enhancement-mcp-server --setup # Run interactive demo npx cpp-enhancement-mcp-server --demo ``` ### Manual Installation 1. **Install dependencies:** ```bash pip install -r requirements.txt ``` 2. **Setup Brave Search API (optional but recommended):** ```bash python cpp_enhancement_server.py --setup ``` See [BRAVE_SEARCH_SETUP.md](BRAVE_SEARCH_SETUP.md) for detailed instructions. 3. **Configure MCP client:** Add the server configuration to your MCP client (Claude Desktop, Cursor, etc.): ```json { "mcpServers": { "cpp-enhancement": { "command": "npx", "args": ["cpp-enhancement-mcp-server"], "env": {}, "description": "C++ Programming Enhancement MCP Server" } } } ``` 4. **Run the server:** ```bash python cpp_enhancement_server.py ``` ## Available Tools ### `analyze_cpp_code` Analyze C++ code and provide improvement suggestions. **Parameters:** - `code` (string): C++ code to analyze - `focus_areas` (array, optional): Specific areas to focus on **Example:** ```cpp int* ptr = new int(42); // Analysis will suggest using smart pointers ``` ### `get_cpp_best_practices` Get best practices for specific C++ topics. **Parameters:** - `topic` (string): C++ topic (auto, smart_pointers, move_semantics, etc.) - `include_examples` (boolean, optional): Include code examples ### `suggest_modern_alternatives` Suggest modern C++ alternatives to legacy code patterns. **Parameters:** - `legacy_code` (string): Legacy C++ code to modernize - `target_standard` (string, optional): Target C++ standard (cpp11, cpp14, cpp17, cpp20, cpp23) ### `performance_optimization_tips` Get performance optimization suggestions. **Parameters:** - `code` (string): C++ code to optimize - `optimization_type` (string, optional): Type of optimization (cache_locality, vectorization, memory_management, general) ### `memory_management_advice` Get advice on memory management and RAII. **Parameters:** - `code` (string): C++ code with memory management concerns - `focus` (string, optional): Focus area (smart_pointers, raii, memory_leaks, ownership) ### `template_programming_help` Get help with template metaprogramming. **Parameters:** - `code` (string): Template code or description - `technique` (string, optional): Specific technique (sfinae, crtp, concepts, variadic_templates, type_traits) ### `search_cpp_techniques` Search for latest C++ techniques and best practices. **Parameters:** - `query` (string): Search query for C++ techniques - `include_recent` (boolean, optional): Focus on recent developments ## Usage Examples ### Code Analysis ```python # Analyze code for improvements result = await analyze_cpp_code( code="int* ptr = new int(42); delete ptr;", focus_areas=["memory_safety", "modern_features"] ) ``` ### Get Best Practices ```python # Get smart pointer best practices result = await get_cpp_best_practices( topic="smart_pointers", include_examples=True ) ``` ### Modernize Legacy Code ```python # Modernize old C++ code result = await suggest_modern_alternatives( legacy_code="for(int i = 0; i < vec.size(); ++i) { process(vec[i]); }", target_standard="cpp20" ) ``` ## Knowledge Base The server includes a comprehensive knowledge base covering: - **Modern C++ Features**: auto, smart pointers, move semantics, constexpr, concepts - **Performance Optimization**: cache locality, vectorization, memory management - **Design Patterns**: RAII, CRTP, type erasure, policy-based design - **Common Pitfalls**: memory safety, performance anti-patterns, threading issues ## Contributing 1. Fork the repository 2. Create a feature branch 3. Add new C++ techniques or improve existing ones 4. Submit a pull request ## Resources - [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) - [ISO C++ Standard](https://isocpp.org/) - [cppreference.com](https://en.cppreference.com/) - [CppCon Talks](https://www.youtube.com/user/CppCon) ## License MIT License - see LICENSE file for details. ## Support For issues and questions: - Create an issue on GitHub - Check the documentation - Review the C++ Core Guidelines --- *Enhance your C++ programming with AI-powered assistance!*