Skip to main content
Glama
ffpy

GitLab MCP Code Review

by ffpy

add_merge_request_discussion

Add comments to specific lines in GitLab merge request files to provide targeted feedback during code review.

Instructions

Add a discussion to a merge request at a specific position in a file.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
    body: The discussion text
    position: Position data for the discussion.
        Example:
        {
            "position_type": "text", // Required, Type of the position reference. Allowed values: text, image, or file. file introduced in GitLab 16.4.
            "base_sha": "...", // Required, Base commit SHA in the source branch.
            "start_sha": "...", // Required, SHA referencing commit in target branch.
            "head_sha": "...", // Required, SHA referencing HEAD of this merge request.
            "old_path": "path/to/file.py", // Required, File path before change.
            "new_path": "path/to/file.py", // Required, File path after change.
            "new_line": 15, // For text diff notes, the line number after change.
            "old_line": 10 // For text diff notes, the line number before change.
        }
Returns:
    Dict containing the created discussion information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
merge_request_iidYes
bodyYes
positionYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), which registers the tool and implements the logic to add a discussion to a GitLab merge request at a specific file position using the GitLab Python client. Includes input schema in the docstring and error handling.
    @mcp.tool()
    def add_merge_request_discussion(ctx: Context, project_id: str, merge_request_iid: str, body: str, position: Dict[str, Any]) -> Dict[str, Any]:
        """
        Add a discussion to a merge request at a specific position in a file.
        
        Args:
            project_id: The GitLab project ID or URL-encoded path
            merge_request_iid: The merge request IID (project-specific ID)
            body: The discussion text
            position: Position data for the discussion.
                Example:
                {
                    "position_type": "text", // Required, Type of the position reference. Allowed values: text, image, or file. file introduced in GitLab 16.4.
                    "base_sha": "...", // Required, Base commit SHA in the source branch.
                    "start_sha": "...", // Required, SHA referencing commit in target branch.
                    "head_sha": "...", // Required, SHA referencing HEAD of this merge request.
                    "old_path": "path/to/file.py", // Required, File path before change.
                    "new_path": "path/to/file.py", // Required, File path after change.
                    "new_line": 15, // For text diff notes, the line number after change.
                    "old_line": 10 // For text diff notes, the line number before change.
                }
        Returns:
            Dict containing the created discussion information
        """
        gl = ctx.request_context.lifespan_context
        project = gl.projects.get(project_id)
        mr = project.mergerequests.get(merge_request_iid)
        
        discussion_data = {'body': body, 'position': position}
        logger.info(f"Creating discussion with data: {discussion_data}")
        
        try:
            discussion = mr.discussions.create(discussion_data)
            logger.info(f"Successfully created discussion: {discussion.id}")
            return discussion.asdict()
        except gitlab.exceptions.GitlabHttpError as e:
            logger.error(f"GitLab API error while creating discussion: {e.error_message}", exc_info=True)
            logger.error(f"Response body: {e.response_body}")
            raise e
Behavior3/5

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

With no annotations provided, the description carries the full burden. It clearly indicates this is a write operation ('Add'), but lacks details on permissions required, rate limits, error conditions, or whether the discussion is editable/deletable. The example in the position parameter adds some behavioral context but doesn't cover broader operational traits.

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 well-structured with a clear purpose statement followed by Args and Returns sections. The position example is detailed but necessary for understanding. It could be slightly more concise by integrating the example more tightly, but overall it's front-loaded and 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 complexity (4 parameters with nested objects) and no annotations, the description does a good job explaining parameters and indicating a dict return. However, it lacks details on authentication, error handling, or side effects, which would be helpful for a mutation tool with no output schema details beyond 'Dict'.

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 schema description coverage is 0%, so the description must compensate. It provides detailed explanations for all 4 parameters, including a comprehensive example for the complex 'position' parameter with required fields, allowed values, and GitLab version specifics, adding significant meaning beyond the bare schema.

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 ('Add a discussion'), target resource ('to a merge request'), and precise location ('at a specific position in a file'), distinguishing it from sibling tools like add_merge_request_comment (general comment) and reply_to_merge_request_discussion (reply to existing discussion).

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

Usage Guidelines4/5

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

The description implies usage context by specifying 'at a specific position in a file,' suggesting this tool is for file-specific discussions rather than general comments. However, it doesn't explicitly state when to use this versus alternatives like add_merge_request_comment or when not to use it (e.g., for non-file discussions).

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