Skip to main content
Glama

gitlab_assign_reviewers_to_merge_request

Assign reviewers to GitLab merge requests by specifying user IDs and MR URL for code review workflow automation.

Instructions

Assigns reviewers to a GitLab Merge Request.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mrUrlYesThe URL of the GitLab Merge Request.
reviewerIdsYesAn array of GitLab user IDs to assign as reviewers.

Implementation Reference

  • The core handler functions that parse the merge request URL, extract project path and MR IID, encode the project path, and execute the PUT request to the GitLab API endpoint to assign the specified reviewer IDs to the merge request.
    async assignReviewersToMergeRequest( projectPath: string, mrIid: number, reviewerIds: number[], ): Promise<any> { const encodedProjectPath = encodeURIComponent(projectPath); return this.callGitLabApi( `projects/${encodedProjectPath}/merge_requests/${mrIid}`, 'PUT', { reviewer_ids: reviewerIds }, ); } // Convenience method to assign reviewers from MR URL async assignReviewersToMergeRequestFromUrl( mrUrl: string, reviewerIds: number[], ): Promise<any> { const { projectPath, mrIid } = this.parseMrUrl(mrUrl, this.config.url); return this.assignReviewersToMergeRequest(projectPath, mrIid, reviewerIds); }
  • src/index.ts:164-182 (registration)
    MCP tool registration including the tool name, description, and input schema definition.
    name: 'gitlab_assign_reviewers_to_merge_request', description: 'Assigns reviewers to a GitLab Merge Request.', inputSchema: { type: 'object', properties: { mrUrl: { type: 'string', description: 'The URL of the GitLab Merge Request.', }, reviewerIds: { type: 'array', items: { type: 'number', }, description: 'An array of GitLab user IDs to assign as reviewers.', }, }, required: ['mrUrl', 'reviewerIds'], },
  • The MCP server request handler (switch case) that validates the GitLab service availability, extracts input arguments, calls the GitLabService handler method, and formats the success response.
    case 'gitlab_assign_reviewers_to_merge_request': { if (!gitlabService) { throw new Error('GitLab service is not initialized.'); } const { mrUrl, reviewerIds } = args as { mrUrl: string; reviewerIds: number[]; }; const result = await gitlabService.assignReviewersToMergeRequestFromUrl( mrUrl, reviewerIds, ); return { content: [ { type: 'text', text: `Reviewers assigned successfully: ${JSON.stringify( result, )}`, }, ], };
  • Helper utility function to parse a GitLab merge request URL into project path and MR IID, with validation against the configured GitLab base URL.
    private parseMrUrl( mrUrl: string, gitlabBaseUrl: string, ): { projectPath: string; mrIid: number } { try { const url = new URL(mrUrl); const baseUrl = new URL(gitlabBaseUrl); // Ensure the URL is from the same GitLab instance if (url.origin !== baseUrl.origin) { throw new Error( `MR URL is not from the configured GitLab instance: ${gitlabBaseUrl}`, ); } // Parse the path: /{namespace}/{project}/-/merge_requests/{iid} const pathMatch = url.pathname.match(/^\/(.+)\/-\/merge_requests\/(\d+)/); if (!pathMatch) { throw new Error(`Invalid GitLab MR URL format: ${mrUrl}`); } const projectPath = pathMatch[1]; const mrIid = parseInt(pathMatch[2], 10); return { projectPath, mrIid }; } catch (error) { throw new Error( `Failed to parse GitLab MR URL: ${error instanceof Error ? error.message : String(error)}`, ); } }

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