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
| Name | Required | Description | Default |
|---|---|---|---|
| mrUrl | Yes | The URL of the GitLab Merge Request. | |
| reviewerIds | Yes | An array of GitLab user IDs to assign as reviewers. |
Implementation Reference
- src/gitlab.service.ts:386-406 (handler)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'], },
- src/index.ts:1297-1319 (handler)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, )}`, }, ], };
- src/gitlab.service.ts:120-150 (helper)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)}`, ); } }