merge_merge_request
Merge a GitLab merge request with options for custom commit messages and branch cleanup. Use this tool to finalize code changes by combining source and target branches in GitLab projects.
Instructions
合併 Merge Request
Args: project_id: 專案 ID 或路徑 mr_iid: MR 的 IID merge_commit_message: 自訂合併 commit 訊息 should_remove_source_branch: 合併後是否刪除來源分支
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| mr_iid | Yes | ||
| merge_commit_message | No | ||
| should_remove_source_branch | No |
Implementation Reference
- src/gitlab_mcp/server.py:334-358 (handler)MCP tool registration and handler implementation for merge_merge_request.
@mcp.tool() def merge_merge_request(project_id: int | str, mr_iid: int, merge_commit_message: str = None, should_remove_source_branch: bool = False) -> str: """合併 Merge Request Args: project_id: 專案 ID 或路徑 mr_iid: MR 的 IID merge_commit_message: 自訂合併 commit 訊息 should_remove_source_branch: 合併後是否刪除來源分支 """ try: client = get_client() mr = client.merge_merge_request( project_id, mr_iid, merge_commit_message=merge_commit_message, should_remove_source_branch=should_remove_source_branch ) result = f"✓ MR !{mr['iid']} 已合併 — {mr['title']}" if should_remove_source_branch: result += f"\n來源分支 {mr.get('source_branch', '')} 已標記刪除" return result except GitLabAPIError as e: return f"合併 MR 失敗: {str(e)}" - src/gitlab_mcp/gitlab_client.py:234-250 (handler)GitLab client method to perform the API request to merge a merge request.
def merge_merge_request( self, project_id: int | str, mr_iid: int, merge_commit_message: str = None, should_remove_source_branch: bool = False, ) -> dict: """PUT /projects/:id/merge_requests/:iid/merge""" pid = self._resolve_project_id(project_id) data = {} if merge_commit_message: data["merge_commit_message"] = merge_commit_message if should_remove_source_branch: data["should_remove_source_branch"] = True return self._put_json( f"/projects/{pid}/merge_requests/{mr_iid}/merge", data=data )