Skip to main content
Glama

get_merge_request_changes

Retrieve file changes and diff details from a GitLab merge request to review code modifications before merging.

Instructions

取得 Merge Request 的檔案變更(diff)

Args: project_id: 專案 ID 或路徑 mr_iid: MR 的 IID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
mr_iidYes

Implementation Reference

  • Handler function in the MCP server that registers the 'get_merge_request_changes' tool and calls the GitLab client.
    def get_merge_request_changes(project_id: int | str, mr_iid: int) -> str:
        """取得 Merge Request 的檔案變更(diff)
    
        Args:
            project_id: 專案 ID 或路徑
            mr_iid: MR 的 IID
        """
        try:
            client = get_client()
            data = client.get_merge_request_changes(project_id, mr_iid)
    
            changes = data.get("changes", [])
            if not changes:
                return "此 MR 沒有檔案變更"
    
            lines = [f"MR !{mr_iid} 共有 {len(changes)} 個檔案變更:\n"]
            for c in changes:
                old_path = c.get("old_path", "")
                new_path = c.get("new_path", "")
    
                if c.get("new_file"):
                    status = "新增"
                elif c.get("deleted_file"):
                    status = "刪除"
                elif c.get("renamed_file"):
                    status = f"重新命名: {old_path} → {new_path}"
                else:
                    status = "修改"
    
                lines.append(f"  [{status}] {new_path}")
    
                diff = c.get("diff", "")
                if diff:
                    # 截斷過長的 diff
                    if len(diff) > 2000:
                        diff = diff[:2000] + "\n... (diff 已截斷)"
                    lines.append(f"```diff\n{diff}\n```\n")
    
            return "\n".join(lines)
        except GitLabAPIError as e:
            return f"取得 MR 變更失敗: {str(e)}"
  • The underlying method in the GitLabClient class that performs the actual API call to GitLab for merge request changes.
    def get_merge_request_changes(self, project_id: int | str, mr_iid: int) -> dict:
        """GET /projects/:id/merge_requests/:iid/changes"""
        pid = self._resolve_project_id(project_id)
        return self._get_json(f"/projects/{pid}/merge_requests/{mr_iid}/changes")

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

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