Skip to main content
Glama

gitlab_add_comment_to_merge_request

Add comments to GitLab merge requests for general feedback, discussion replies, or inline code reviews.

Instructions

Adds a comment to a GitLab Merge Request. Can be a general comment, a reply to an existing discussion, or an inline comment on a specific line.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mrUrlYesThe URL of the GitLab Merge Request.
commentBodyYesThe content of the comment.
discussionIdNoOptional: The ID of an existing discussion to reply to.
positionNoOptional: Position object for inline comments, specifying file paths, SHAs, and line numbers.

Implementation Reference

  • src/index.ts:109-147 (registration)
    Tool registration and input schema definition for gitlab_add_comment_to_merge_request
    {
      name: 'gitlab_add_comment_to_merge_request',
      description:
        'Adds a comment to a GitLab Merge Request. Can be a general comment, a reply to an existing discussion, or an inline comment on a specific line.',
      inputSchema: {
        type: 'object',
        properties: {
          mrUrl: {
            type: 'string',
            description: 'The URL of the GitLab Merge Request.',
          },
          commentBody: {
            type: 'string',
            description: 'The content of the comment.',
          },
          discussionId: {
            type: 'string',
            description:
              'Optional: The ID of an existing discussion to reply to.',
          },
          position: {
            type: 'object',
            description:
              'Optional: Position object for inline comments, specifying file paths, SHAs, and line numbers.',
            properties: {
              base_sha: { type: 'string' },
              start_sha: { type: 'string' },
              head_sha: { type: 'string' },
              position_type: { type: 'string' },
              old_path: { type: 'string' },
              new_path: { type: 'string' },
              new_line: { type: 'number' },
              old_line: { type: 'number' },
            },
          },
        },
        required: ['mrUrl', 'commentBody'],
      },
    },
  • MCP tool call handler that invokes the GitLab service method to add the comment
    case 'gitlab_add_comment_to_merge_request': {
      if (!gitlabService) {
        throw new Error('GitLab service is not initialized.');
      }
      const { mrUrl, commentBody, discussionId, position } = args as {
        mrUrl: string;
        commentBody: string;
        discussionId?: string;
        position?: GitLabPosition;
      };
      const result = await gitlabService.addCommentToMergeRequestFromUrl(
        mrUrl,
        commentBody,
        discussionId,
        position,
      );
      return {
        content: [
          {
            type: 'text',
            text: `Comment added successfully: ${JSON.stringify(result)}`,
          },
        ],
      };
    }
  • Convenience wrapper that parses MR URL and delegates to core addCommentToMergeRequest method
    async addCommentToMergeRequestFromUrl(
      mrUrl: string,
      commentBody: string,
      discussionId?: string,
      position?: GitLabPosition,
    ): Promise<any> {
      const { projectPath, mrIid } = this.parseMrUrl(mrUrl, this.config.url);
      return this.addCommentToMergeRequest(
        projectPath,
        mrIid,
        discussionId,
        commentBody,
        position,
      );
    }
  • Core handler logic in GitLabService that makes the API calls to GitLab for adding comments (general, reply, or inline) to a merge request
    async addCommentToMergeRequest(
      projectPath: string,
      mrIid: number,
      discussionId: string | undefined,
      commentBody: string,
      position: GitLabPosition | undefined,
    ): Promise<any> {
      const encodedProjectPath = encodeURIComponent(projectPath);
    
      if (discussionId) {
        // Reply to an existing discussion
        return this.callGitLabApi(
          `projects/${encodedProjectPath}/merge_requests/${mrIid}/discussions/${discussionId}/notes`,
          'POST',
          { body: commentBody },
        );
      } else if (position) {
        // Add a new comment with a position (inline comment)
        return this.callGitLabApi(
          `projects/${encodedProjectPath}/merge_requests/${mrIid}/notes`,
          'POST',
          {
            body: commentBody,
            noteable_type: 'MergeRequest',
            noteable_id: mrIid,
            position: {
              base_sha: position.base_sha,
              start_sha: position.start_sha,
              head_sha: position.head_sha,
              position_type: position.position_type,
              old_path: position.old_path,
              new_path: position.new_path,
              new_line: position.new_line,
              old_line: position.old_line,
            },
          },
        );
      } else {
        // Add a general comment
        return this.callGitLabApi(
          `projects/${encodedProjectPath}/merge_requests/${mrIid}/notes`,
          'POST',
          { body: commentBody },
        );
      }
    }
  • Type definition for GitLabPosition used in inline comment positions
    export interface GitLabPosition {
      base_sha: string;
      start_sha: string;
      head_sha: string;
      position_type: 'text';
      old_path: string;
      new_path: string;
      new_line?: number;
      old_line?: number;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the action ('adds a comment') but doesn't disclose critical behavioral traits such as required permissions, whether comments are editable/deletable, rate limits, or error conditions. The description is functional but lacks operational context needed for safe invocation.

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 a single, well-structured sentence that efficiently conveys the tool's capabilities without redundancy. It front-loads the core purpose and then enumerates the three comment types, with every word earning its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (4 parameters with nested objects, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose and parameter mapping but lacks completeness regarding behavioral traits, error handling, and output expectations, which are important for a mutation tool with no structured safety annotations.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds marginal value by hinting at the three use cases (general, reply, inline) which map to the optional 'discussionId' and 'position' parameters, but doesn't provide additional syntax or format details beyond what the schema provides.

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 verb ('adds a comment') and resource ('to a GitLab Merge Request'), making the purpose unambiguous. It distinguishes from sibling tools like 'gitlab_add_comment_to_issue' by specifying the target is a merge request, not an issue. However, it doesn't explicitly differentiate from other merge request tools beyond the comment action.

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

Usage Guidelines3/5

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

The description implies usage context by listing three comment types (general, reply, inline), suggesting when this tool is appropriate. However, it doesn't provide explicit guidance on when to use this versus alternatives like 'gitlab_update_issue' for issue comments or other merge request tools, nor does it mention prerequisites or exclusions.

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/HainanZhao/mcp-gitlab-jira'

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