add_merge_request_comment
Add comments to GitLab merge requests for code review feedback, discussion points, or general observations during the review process.
Instructions
Add a general comment to a merge request.
Args:
project_id: The GitLab project ID or URL-encoded path
merge_request_iid: The merge request IID (project-specific ID)
body: The comment text
Returns:
Dict containing the created comment information
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| merge_request_iid | Yes | ||
| body | Yes |
Input Schema (JSON Schema)
{
"properties": {
"body": {
"title": "Body",
"type": "string"
},
"merge_request_iid": {
"title": "Merge Request Iid",
"type": "string"
},
"project_id": {
"title": "Project Id",
"type": "string"
}
},
"required": [
"project_id",
"merge_request_iid",
"body"
],
"type": "object"
}
Implementation Reference
- server.py:197-216 (handler)The handler function decorated with @mcp.tool(), which registers and implements the 'add_merge_request_comment' tool. It fetches the project and merge request using the GitLab client from context, creates a new note with the provided body, and returns the note as a dictionary.@mcp.tool() def add_merge_request_comment(ctx: Context, project_id: str, merge_request_iid: str, body: str) -> Dict[str, Any]: """ Add a general comment to a merge request. Args: project_id: The GitLab project ID or URL-encoded path merge_request_iid: The merge request IID (project-specific ID) body: The comment text Returns: Dict containing the created comment information """ gl = ctx.request_context.lifespan_context project = gl.projects.get(project_id) mr = project.mergerequests.get(merge_request_iid) note = mr.notes.create({'body': body}) return note.asdict()
- server.py:197-197 (registration)The @mcp.tool() decorator registers the 'add_merge_request_comment' function as an MCP tool.@mcp.tool()