Skip to main content
Glama
SongJiangzhou

C++ Style Guide MCP Server

check_naming

Validate C++ identifier naming conventions for variables, functions, classes, and other code elements against style guidelines to ensure consistent and compliant code structure.

Instructions

检查 C++ 标识符命名是否符合规范

参数:
    identifier: 要检查的标识符名称
    category: 标识符类别,可选值:
             - variable: 变量
             - constant: 常量
             - function: 函数
             - class: 类
             - namespace: 命名空间
             - member_variable: 成员变量
             - template_parameter: 模板参数
             - file_naming: 文件命名

返回:
    检查结果,包含是否符合规范、详细说明和建议

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
identifierYes
categoryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler function that implements the naming convention checks for C++ identifiers, including style validation, detailed reporting, rule explanations, and suggestion generation.
    def check_naming(self, identifier: str, category: str) -> Tuple[bool, str, List[str]]:
        """
        检查标识符命名是否符合规范
    
        Args:
            identifier: 要检查的标识符
            category: 类别 (variable, constant, function, class, namespace,
                     member_variable, template_parameter, file_naming)
    
        Returns:
            (是否符合规范, 详细说明, 建议列表)
        """
        if category not in self.conventions:
            return False, f"未知的类别: {category}", []
    
        conv = self.conventions[category]
        style = conv["style"]
    
        # 根据不同风格进行检查
        is_valid, message = self._check_style(identifier, style, category)
    
        suggestions = []
        if not is_valid:
            suggestions = self._generate_suggestions(identifier, style, category)
    
        # 构建详细说明
        details = f"类别: {category}\n"
        details += f"推荐风格: {style}\n"
        details += f"标识符: {identifier}\n"
        details += f"检查结果: {'✓ 符合规范' if is_valid else '✗ 不符合规范'}\n"
        if message:
            details += f"说明: {message}\n"
        if suggestions:
            details += f"\n建议的命名:\n"
            for sug in suggestions:
                details += f"  • {sug}\n"
    
        # 添加规则说明
        details += f"\n规范要求:\n"
        for rule in conv.get("rules", []):
            details += f"  • {rule}\n"
    
        # 添加示例
        if "examples" in conv:
            details += f"\n正确示例: {', '.join(conv['examples']['good'])}\n"
            details += f"错误示例: {', '.join(conv['examples']['bad'])}\n"
    
        return is_valid, details, suggestions
  • MCP tool registration for 'check_naming'. Defines the tool schema via parameters and docstring, wraps the core NamingChecker, and formats the final output string.
    @mcp.tool()
    def check_naming(identifier: str, category: str) -> str:
        """
        检查 C++ 标识符命名是否符合规范
    
        参数:
            identifier: 要检查的标识符名称
            category: 标识符类别,可选值:
                     - variable: 变量
                     - constant: 常量
                     - function: 函数
                     - class: 类
                     - namespace: 命名空间
                     - member_variable: 成员变量
                     - template_parameter: 模板参数
                     - file_naming: 文件命名
    
        返回:
            检查结果,包含是否符合规范、详细说明和建议
        """
        checker = get_naming_checker()
        is_valid, details, suggestions = checker.check_naming(identifier, category)
    
        result = details
        if suggestions:
            result += f"\n推荐使用:\n"
            for sug in suggestions:
                result += f"  • {sug}\n"
    
        return result
  • NamingChecker class initialization loads the naming conventions JSON data used by the check_naming handler.
    class NamingChecker:
        """C++ 命名规范检查器"""
    
        def __init__(self):
            """加载命名规范数据"""
            data_path = Path(__file__).parent.parent / "data" / "naming_conventions.json"
            with open(data_path, 'r', encoding='utf-8') as f:
                self.conventions = json.load(f)
    
        def check_naming(self, identifier: str, category: str) -> Tuple[bool, str, List[str]]:
            """
            检查标识符命名是否符合规范
    
            Args:
                identifier: 要检查的标识符
                category: 类别 (variable, constant, function, class, namespace,
                         member_variable, template_parameter, file_naming)
    
            Returns:
                (是否符合规范, 详细说明, 建议列表)
            """
            if category not in self.conventions:
                return False, f"未知的类别: {category}", []
    
            conv = self.conventions[category]
            style = conv["style"]
    
            # 根据不同风格进行检查
            is_valid, message = self._check_style(identifier, style, category)
    
            suggestions = []
            if not is_valid:
                suggestions = self._generate_suggestions(identifier, style, category)
    
            # 构建详细说明
            details = f"类别: {category}\n"
            details += f"推荐风格: {style}\n"
            details += f"标识符: {identifier}\n"
            details += f"检查结果: {'✓ 符合规范' if is_valid else '✗ 不符合规范'}\n"
            if message:
                details += f"说明: {message}\n"
            if suggestions:
                details += f"\n建议的命名:\n"
                for sug in suggestions:
                    details += f"  • {sug}\n"
    
            # 添加规则说明
            details += f"\n规范要求:\n"
            for rule in conv.get("rules", []):
                details += f"  • {rule}\n"
    
            # 添加示例
            if "examples" in conv:
                details += f"\n正确示例: {', '.join(conv['examples']['good'])}\n"
                details += f"错误示例: {', '.join(conv['examples']['bad'])}\n"
    
            return is_valid, details, suggestions
  • Singleton factory function providing the global NamingChecker instance, used by the MCP tool wrapper.
    def get_checker() -> NamingChecker:
        """获取全局命名检查器实例"""
        global _checker
        if _checker is None:
            _checker = NamingChecker()
        return _checker
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does (check naming compliance) but doesn't describe how it behaves: it doesn't specify what standards are used (e.g., Google Style Guide, C++ Core Guidelines), whether it's read-only or has side effects, what happens with invalid inputs, or performance characteristics. The return format is mentioned but without details on error handling or output structure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and well-structured with clear sections for parameters and return values. Every sentence adds value: the first states the purpose, the parameter section explains both parameters thoroughly, and the return section describes the output. It could be slightly more concise by integrating the parameter explanations more tightly, but overall it's efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but with output schema), the description is reasonably complete. It explains the purpose, parameters in detail, and mentions the return format. Since an output schema exists, the description doesn't need to detail return values. However, it lacks context about the naming standards used and behavioral aspects, leaving some gaps for a tool that evaluates code conventions.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description provides comprehensive parameter semantics beyond the input schema. The schema has 0% description coverage with only titles 'Identifier' and 'Category', but the description explains that 'identifier' is the name to check and 'category' specifies the type with detailed enum values (variable, constant, function, etc.) and their meanings. This fully compensates for the schema's lack of documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('检查' - check) and resource ('C++ 标识符命名' - C++ identifier naming) with the precise scope ('是否符合规范' - whether it complies with standards). It distinguishes itself from sibling tools like 'analyze_memory_safety' or 'check_const_correctness' by focusing exclusively on naming conventions rather than other code quality aspects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While it mentions checking C++ identifier naming, it doesn't specify scenarios where this is appropriate (e.g., during code review, refactoring, or learning) or when other sibling tools might be more suitable. There's no mention of prerequisites or limitations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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