Skip to main content
Glama
Alosies
by Alosies

update_merge_request

Modify an existing GitLab merge request by updating its title, description, assignees, target branch, or state. Use this tool to edit merge request details or change its status to closed or reopened.

Instructions

Update an existing merge request. Either merge_request_iid or source_branch must be provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID or path
merge_request_iidNoMerge request internal ID
source_branchNoSource branch name (alternative to merge_request_iid)
titleNoUpdate merge request title
descriptionNoUpdate merge request description (max 1,048,576 characters)
state_eventNoChange the state (close or reopen the MR)
target_branchNoChange the target branch
assignee_idNoAssign a user to the merge request (use 0 to unassign)
assignee_idsNoAssign multiple users to the merge request
reviewer_idsNoSet reviewers for the merge request
milestone_idNoAssign a milestone (use 0 to remove)
labelsNoUpdate labels (comma-separated)
remove_source_branchNoFlag to remove source branch after merging
squashNoToggle squash commits on merge
allow_collaborationNoAllow commits from members who can merge
merge_when_pipeline_succeedsNoSet MR to merge when pipeline succeeds

Implementation Reference

  • The main handler function that executes the update_merge_request tool logic. Resolves the merge request IID using helper if not provided, conditionally builds the update payload from input parameters, performs a PUT request to the GitLab API to update the merge request, and returns the response.
    async updateMergeRequest(args: UpdateMergeRequestParams) { const mergeRequestIid = await this.resolveMergeRequestIid( args.project_id, args.merge_request_iid, args.source_branch ); const requestData: any = {}; // Only include provided parameters if (args.title !== undefined) requestData.title = args.title; if (args.description !== undefined) requestData.description = args.description; if (args.state_event !== undefined) requestData.state_event = args.state_event; if (args.target_branch !== undefined) requestData.target_branch = args.target_branch; if (args.assignee_id !== undefined) requestData.assignee_id = args.assignee_id; if (args.assignee_ids !== undefined) requestData.assignee_ids = args.assignee_ids; if (args.reviewer_ids !== undefined) requestData.reviewer_ids = args.reviewer_ids; if (args.milestone_id !== undefined) requestData.milestone_id = args.milestone_id; if (args.labels !== undefined) requestData.labels = args.labels; if (args.remove_source_branch !== undefined) requestData.remove_source_branch = args.remove_source_branch; if (args.squash !== undefined) requestData.squash = args.squash; if (args.allow_collaboration !== undefined) requestData.allow_collaboration = args.allow_collaboration; if (args.merge_when_pipeline_succeeds !== undefined) requestData.merge_when_pipeline_succeeds = args.merge_when_pipeline_succeeds; const data = await this.client.put( `/projects/${encodeURIComponent( args.project_id )}/merge_requests/${mergeRequestIid}`, requestData ); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; }
  • MCP tool definition object including the name 'update_merge_request', description, and detailed inputSchema (JSON Schema) defining parameters, types, descriptions, enums, and requirements.
    { name: 'update_merge_request', description: 'Update an existing merge request. Either merge_request_iid or source_branch must be provided.', inputSchema: { type: 'object', properties: { project_id: { type: 'string', description: 'Project ID or path', }, merge_request_iid: { type: 'number', description: 'Merge request internal ID', }, source_branch: { type: 'string', description: 'Source branch name (alternative to merge_request_iid)', }, title: { type: 'string', description: 'Update merge request title', }, description: { type: 'string', description: 'Update merge request description (max 1,048,576 characters)', }, state_event: { type: 'string', enum: ['close', 'reopen'], description: 'Change the state (close or reopen the MR)', }, target_branch: { type: 'string', description: 'Change the target branch', }, assignee_id: { type: 'number', description: 'Assign a user to the merge request (use 0 to unassign)', }, assignee_ids: { type: 'array', items: { type: 'number' }, description: 'Assign multiple users to the merge request', }, reviewer_ids: { type: 'array', items: { type: 'number' }, description: 'Set reviewers for the merge request', }, milestone_id: { type: 'number', description: 'Assign a milestone (use 0 to remove)', }, labels: { type: 'string', description: 'Update labels (comma-separated)', }, remove_source_branch: { type: 'boolean', description: 'Flag to remove source branch after merging', }, squash: { type: 'boolean', description: 'Toggle squash commits on merge', }, allow_collaboration: { type: 'boolean', description: 'Allow commits from members who can merge', }, merge_when_pipeline_succeeds: { type: 'boolean', description: 'Set MR to merge when pipeline succeeds', }, }, required: ['project_id'], }, },
  • src/server.ts:189-192 (registration)
    Dispatch/registration case in the main tool call handler switch statement that routes 'update_merge_request' calls to the mergeRequestHandlers.updateMergeRequest method.
    case "update_merge_request": return await this.mergeRequestHandlers.updateMergeRequest( args as unknown as UpdateMergeRequestParams );
  • TypeScript interface defining the input parameters for the updateMergeRequest handler, used for type safety across the codebase.
    export interface UpdateMergeRequestParams { project_id: string; merge_request_iid?: number; source_branch?: string; title?: string; description?: string; state_event?: 'close' | 'reopen'; target_branch?: string; assignee_id?: number; assignee_ids?: number[]; reviewer_ids?: number[]; milestone_id?: number; labels?: string; remove_source_branch?: boolean; squash?: boolean; allow_collaboration?: boolean; merge_when_pipeline_succeeds?: boolean; }
  • Helper method used by updateMergeRequest (and others) to resolve merge request IID from source branch name if not directly provided.
    private async resolveMergeRequestIid( projectId: string, mergeRequestIid?: number, sourceBranch?: string ): Promise<number> { if (mergeRequestIid) { return mergeRequestIid; } if (!sourceBranch) { throw new Error( "Either merge_request_iid or source_branch must be provided" ); } // Find MR by source branch const mrs = (await this.client.get( `/projects/${encodeURIComponent( projectId )}/merge_requests?source_branch=${encodeURIComponent( sourceBranch )}&state=opened&per_page=1` )) as GitLabMergeRequest[]; if (!mrs || mrs.length === 0) { // Try all states if no open MR found const allMrs = (await this.client.get( `/projects/${encodeURIComponent( projectId )}/merge_requests?source_branch=${encodeURIComponent( sourceBranch )}&per_page=1` )) as GitLabMergeRequest[]; if (!allMrs || allMrs.length === 0) { throw new Error( `No merge request found for source branch: ${sourceBranch}` ); } return allMrs[0].iid; } return mrs[0].iid; }

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