gitlab_add_merge_request_comment
Add comments to GitLab merge requests for code reviews or discussions. Supports Markdown, mentions, and slash commands to streamline feedback and collaboration within the MCP GitLab Server.
Instructions
Add comment to merge request Returns: Created comment object Use when: Code review feedback, discussions Supports: Markdown, mentions, slash commands
Example: "LGTM! π Just one minor suggestion..."
Related tools:
gitlab_get_merge_request_notes: Read existing
gitlab_get_merge_request_discussions: Threaded view
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | Yes | Comment content Type: string Required: Yes Format: GitLab Flavored Markdown Features: - Mentions: @username - References: #123, !456 - Code blocks: ```language - Task lists: - [ ] Task - Slash commands: /assign @user Examples: 'LGTM! π' 'Found an issue in line 42: ```python # This could be None result = data["key"] ``` Should check if key exists first.' | |
| mr_iid | Yes | Merge request number (IID - Internal ID) Type: integer Format: Project-specific MR number (without !) Required: Yes Examples: - 456 (for MR !456) - 7890 (for MR !7890) How to find: Look at MR URL or title - URL: https://gitlab.com/group/project/-/merge_requests/456 β use 456 - Title: "Add new feature (!456)" β use 456 Note: This is NOT the global MR ID | |
| project_id | No | Project identifier (auto-detected if not provided) Type: integer OR string Format: numeric ID or 'namespace/project' Optional: Yes - auto-detects from current git repository Examples: - 12345 (numeric ID) - 'gitlab-org/gitlab' (namespace/project path) - 'my-group/my-subgroup/my-project' (nested groups) Note: If in a git repo with GitLab remote, this can be omitted |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:338-344 (handler)The main handler function that implements the gitlab_add_merge_request_comment tool. It resolves the project ID (auto-detecting from git if not provided), requires mr_iid and body parameters, and delegates to the GitLabClient's add_merge_request_comment method.def handle_add_merge_request_comment(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle adding a comment to a merge request""" project_id = require_project_id(client, arguments) mr_iid = require_argument(arguments, "mr_iid") body = require_argument(arguments, "body") return client.add_merge_request_comment(project_id, mr_iid, body)
- The input schema definition for the tool, specifying parameters: optional project_id (string), required mr_iid (integer), required body (string).types.Tool( name=TOOL_ADD_MR_COMMENT, description=desc.DESC_ADD_MR_COMMENT, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "mr_iid": {"type": "integer", "description": desc.DESC_MR_IID}, "body": {"type": "string", "description": desc.DESC_COMMENT_BODY} }, "required": ["mr_iid", "body"] } ),
- src/mcp_gitlab/tool_handlers.py:1049-1049 (registration)Registration of the handler function in the TOOL_HANDLERS dictionary, mapping the tool name constant to its handler.TOOL_ADD_MR_COMMENT: handle_add_merge_request_comment,
- src/mcp_gitlab/constants.py:236-236 (registration)Constant definition for the tool name used in registration and schema.TOOL_ADD_MR_COMMENT = "gitlab_add_merge_request_comment"
- Helper function used by the handler to resolve or require the project_id, auto-detecting from git repository if not provided.def require_project_id(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> str: """Get project_id or raise error if not found""" project_id = get_project_id_or_detect(client, arguments) if not project_id: raise ValueError(ERROR_NO_PROJECT) return project_id