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

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

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