Skip to main content
Glama
Alosies

GitLab MCP Server

by Alosies

create_mr_discussion

Add comments to GitLab merge requests for general feedback or specific code line discussions to facilitate code review and collaboration.

Instructions

Create a new discussion on a merge request. Can be a general discussion or an inline comment on the diff

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID or path
merge_request_iidYesMerge request internal ID
bodyYesThe content of the discussion (supports Markdown)
positionNoPosition for inline/diff comments. Required fields: base_sha, start_sha, head_sha, old_path, new_path. Use new_line for additions, old_line for deletions, both for context lines.

Implementation Reference

  • The handler function that executes the tool: creates a new discussion thread on a GitLab merge request, supporting inline diff positions, by calling the GitLab Discussions API endpoint.
    async createMRDiscussion(args: CreateMRDiscussionParams) {
      const requestData: Record<string, unknown> = {
        body: args.body,
      };
    
      // Add position for inline/diff comments
      if (args.position) {
        requestData.position = {
          base_sha: args.position.base_sha,
          start_sha: args.position.start_sha,
          head_sha: args.position.head_sha,
          old_path: args.position.old_path,
          new_path: args.position.new_path,
          position_type: args.position.position_type || "text",
          ...(args.position.old_line !== undefined && {
            old_line: args.position.old_line,
          }),
          ...(args.position.new_line !== undefined && {
            new_line: args.position.new_line,
          }),
        };
      }
    
      const data = await this.client.post(
        `/projects/${encodeURIComponent(args.project_id)}/merge_requests/${
          args.merge_request_iid
        }/discussions`,
        requestData
      );
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(data, null, 2),
          },
        ],
      };
    }
  • MCP tool definition including name, description, and inputSchema for validating parameters like project_id, merge_request_iid, body, and optional position for inline comments.
    {
      name: 'create_mr_discussion',
      description:
        'Create a new discussion on a merge request. Can be a general discussion or an inline comment on the diff',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'string',
            description: 'Project ID or path',
          },
          merge_request_iid: {
            type: 'number',
            description: 'Merge request internal ID',
          },
          body: {
            type: 'string',
            description: 'The content of the discussion (supports Markdown)',
          },
          position: {
            type: 'object',
            description:
              'Position for inline/diff comments. Required fields: base_sha, start_sha, head_sha, old_path, new_path. Use new_line for additions, old_line for deletions, both for context lines.',
            properties: {
              base_sha: {
                type: 'string',
                description: 'Base commit SHA (merge request target branch HEAD)',
              },
              start_sha: {
                type: 'string',
                description:
                  'SHA of the commit when the MR was created (typically same as base_sha)',
              },
              head_sha: {
                type: 'string',
                description: 'HEAD commit SHA of the merge request source branch',
              },
              old_path: {
                type: 'string',
                description:
                  'File path before the change (use same as new_path for new files)',
              },
              new_path: {
                type: 'string',
                description: 'File path after the change',
              },
              position_type: {
                type: 'string',
                enum: ['text'],
                description: 'Type of position (text for code comments)',
                default: 'text',
              },
              old_line: {
                type: 'number',
                description:
                  'Line number in old version (for deleted lines or context)',
              },
              new_line: {
                type: 'number',
                description:
                  'Line number in new version (for added lines or context)',
              },
            },
            required: ['base_sha', 'start_sha', 'head_sha', 'old_path', 'new_path'],
          },
        },
        required: ['project_id', 'merge_request_iid', 'body'],
      },
    },
  • src/server.ts:219-222 (registration)
    Server-side registration: switch case that dispatches tool calls to the mergeRequestHandlers.createMRDiscussion method.
    case "create_mr_discussion":
      return await this.mergeRequestHandlers.createMRDiscussion(
        args as unknown as CreateMRDiscussionParams
      );
  • TypeScript interface defining the input parameters for the createMRDiscussion handler, matching the tool schema.
    export interface CreateMRDiscussionParams {
      project_id: string;
      merge_request_iid: number;
      body: string;
      position?: {
        base_sha: string;
        start_sha: string;
        head_sha: string;
        old_path: string;
        new_path: string;
        position_type?: 'text';
        old_line?: number;
        new_line?: number;
      };
    }

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/Alosies/gitlab-mcp-server'

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