Skip to main content
Glama
SongJiangzhou

C++ Style Guide MCP Server

suggest_modern_cpp

Upgrade C++ code to modern standards by analyzing existing code and providing specific rewrite suggestions with new feature examples.

Instructions

建议将代码升级为现代 C++ 写法

参数:
    code: 要分析的 C++ 代码
    target_standard: 目标 C++ 标准,可选值:
                    - cpp11: C++11
                    - cpp14: C++14
                    - cpp17: C++17 (默认)
                    - cpp20: C++20
                    - cpp23: C++23

返回:
    现代化建议报告,包括可以使用的新特性和重写示例

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
target_standardNocpp17

Implementation Reference

  • The primary MCP tool handler for 'suggest_modern_cpp'. It defines the tool schema via type hints and docstring, registers it with @mcp.tool(), and delegates execution to the ModernCppSuggester class.
    @mcp.tool()
    def suggest_modern_cpp(code: str, target_standard: str = "cpp17") -> str:
        """
        建议将代码升级为现代 C++ 写法
    
        参数:
            code: 要分析的 C++ 代码
            target_standard: 目标 C++ 标准,可选值:
                            - cpp11: C++11
                            - cpp14: C++14
                            - cpp17: C++17 (默认)
                            - cpp20: C++20
                            - cpp23: C++23
    
        返回:
            现代化建议报告,包括可以使用的新特性和重写示例
        """
        suggester = get_modern_cpp_suggester()
        suggestions, report = suggester.suggest_modern_cpp(code, target_standard)
        return report
  • Core implementation of modernization suggestions in ModernCppSuggester class. Orchestrates feature checks via regex patterns for different C++ standards and generates a formatted report.
    def suggest_modern_cpp(self, code: str, target_standard: str = "cpp17") -> Tuple[List[Dict], str]:
        """
        建议将代码升级为现代 C++ 写法
    
        Args:
            code: 要分析的 C++ 代码
            target_standard: 目标标准 (cpp11, cpp14, cpp17, cpp20, cpp23)
    
        Returns:
            (建议列表, 格式化的建议报告)
        """
        suggestions = []
    
        # 根据目标标准检查可用特性
        if target_standard in ['cpp11', 'cpp14', 'cpp17', 'cpp20', 'cpp23']:
            suggestions.extend(self._check_cpp11_features(code))
    
        if target_standard in ['cpp14', 'cpp17', 'cpp20', 'cpp23']:
            suggestions.extend(self._check_cpp14_features(code))
    
        if target_standard in ['cpp17', 'cpp20', 'cpp23']:
            suggestions.extend(self._check_cpp17_features(code))
    
        if target_standard in ['cpp20', 'cpp23']:
            suggestions.extend(self._check_cpp20_features(code))
    
        if target_standard == 'cpp23':
            suggestions.extend(self._check_cpp23_features(code))
    
        # 生成报告
        report = self._generate_report(suggestions, target_standard)
    
        return suggestions, report
  • Singleton factory function providing the shared ModernCppSuggester instance used by the tool handler.
    def get_suggester() -> ModernCppSuggester:
        """获取全局现代 C++ 建议器实例"""
        global _suggester
        if _suggester is None:
            _suggester = ModernCppSuggester()
        return _suggester
  • MCP tool registration decorator for 'suggest_modern_cpp'.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SongJiangzhou/cpp_guidelines'

If you have feedback or need assistance with the MCP directory API, please join our Discord server