Skip to main content
Glama
ffpy

GitLab MCP Code Review

by ffpy

fetch_code_review_rules

Retrieve team code review standards and guidelines from a remote server to ensure consistent code quality assessment before reviewing merge requests.

Instructions

Fetch the team's code review rules from a remote server via SSH.

IMPORTANT: You should call this tool BEFORE reviewing any merge requests or code changes
to understand the team's code review standards and guidelines.

Returns:
    str: The code review rules content on success, or a simple message if SSH is not configured
    Dict: Error information only on connection failures

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'fetch_code_review_rules' tool, decorated with @mcp.tool() for registration. It connects to a remote server via SSH/SFTP to fetch and return the code review rules file content, with comprehensive error handling.
    @mcp.tool()
    def fetch_code_review_rules(ctx: Context):
        """
        Fetch the team's code review rules from a remote server via SSH.
    
        IMPORTANT: You should call this tool BEFORE reviewing any merge requests or code changes
        to understand the team's code review standards and guidelines.
    
        Returns:
            str: The code review rules content on success, or a simple message if SSH is not configured
            Dict: Error information only on connection failures
        """
        # Read SSH configuration from environment variables
        ssh_host = os.getenv("CODE_REVIEW_SSH_HOST")
        ssh_port = int(os.getenv("CODE_REVIEW_SSH_PORT", "22"))
        ssh_username = os.getenv("CODE_REVIEW_SSH_USERNAME")
        ssh_password = os.getenv("CODE_REVIEW_SSH_PASSWORD")
        rule_file = os.getenv("CODE_REVIEW_RULE_FILE")
    
        # Check if SSH configuration is provided
        if not all([ssh_host, ssh_username, ssh_password, rule_file]):
            return "代码审查规则未配置。如需使用团队的代码审查规范,请配置SSH相关环境变量(CODE_REVIEW_SSH_HOST, CODE_REVIEW_SSH_USERNAME, CODE_REVIEW_SSH_PASSWORD, CODE_REVIEW_RULE_FILE)。"
    
        ssh_client = None
        sftp_client = None
    
        try:
            # Create SSH client
            ssh_client = paramiko.SSHClient()
            ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    
            logger.info(f"Connecting to SSH server {ssh_host}:{ssh_port} as {ssh_username}")
    
            # Connect to the remote server
            ssh_client.connect(
                hostname=ssh_host,
                port=ssh_port,
                username=ssh_username,
                password=ssh_password,
                timeout=30
            )
    
            # Open SFTP session
            sftp_client = ssh_client.open_sftp()
    
            logger.info(f"Reading code review rules from {rule_file}")
    
            # Read the file content
            with sftp_client.file(rule_file, 'r') as remote_file:
                content = remote_file.read().decode('utf-8')
    
            logger.info(f"Successfully fetched code review rules ({len(content)} characters)")
    
            # Return the content directly as a string on success
            return content
    
        except paramiko.AuthenticationException:
            logger.error(f"SSH authentication failed for {ssh_username}@{ssh_host}")
            return {
                "success": False,
                "error": "Authentication failed",
                "message": "Failed to authenticate with the SSH server. Please check your username and password."
            }
        except paramiko.SSHException as e:
            logger.error(f"SSH connection error: {e}")
            return {
                "success": False,
                "error": "SSH connection error",
                "message": f"Failed to connect to SSH server: {str(e)}"
            }
        except FileNotFoundError:
            logger.error(f"File not found: {rule_file}")
            return {
                "success": False,
                "error": "File not found",
                "message": f"The code review rules file '{rule_file}' does not exist on the server."
            }
        except Exception as e:
            logger.error(f"Error fetching code review rules: {e}", exc_info=True)
            return {
                "success": False,
                "error": "Unexpected error",
                "message": f"An error occurred while fetching code review rules: {str(e)}"
            }
        finally:
            # Clean up connections
            if sftp_client:
                try:
                    sftp_client.close()
                except:
                    pass
            if ssh_client:
                try:
                    ssh_client.close()
                except:
                    pass
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool fetches via SSH and mentions possible outcomes (success with content, simple message if SSH not configured, error dict on connection failures). However, it lacks details on authentication requirements, rate limits, or what 'SSH is not configured' entails. The description doesn't contradict annotations, but could be more comprehensive given the absence of annotations.

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

Conciseness5/5

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

The description is well-structured and concise, with three sentences that each add value: the first states the purpose, the second provides usage guidelines, and the third outlines return behavior. There is no wasted text, and key information is front-loaded.

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 complexity (involves SSH and fetching rules), no annotations, no output schema, and 0 parameters, the description does a good job covering purpose, usage, and basic behavioral outcomes. However, it could be more complete by detailing authentication, error handling specifics, or format of returned content, which would help an agent use it more effectively.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description appropriately doesn't discuss parameters, focusing instead on behavior and usage. This meets the baseline for zero parameters, as it doesn't mislead or omit necessary param info.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Fetch the team's code review rules from a remote server via SSH.' This specifies the verb (fetch), resource (code review rules), and method (SSH). However, it doesn't explicitly differentiate from sibling tools like 'fetch_merge_request' or 'get_project_merge_requests', which might also retrieve data but for different resources.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: 'You should call this tool BEFORE reviewing any merge requests or code changes to understand the team's code review standards and guidelines.' This clearly indicates when to use it (as a prerequisite for code review activities) and implies alternatives (e.g., not using it would mean reviewing without standards).

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/ffpy/gitlab-mcp-code-review'

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