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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the tool gets file changes/diffs, implying a read-only operation, but doesn't disclose behavioral traits like authentication needs, rate limits, pagination, error conditions, or what format the diff is returned in (e.g., raw diff, parsed JSON). The description is minimal and lacks context about the tool's behavior beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the purpose clearly. The Args section is structured but minimal. There's no wasted text. However, it could be more structured with bullet points or clearer separation, and the translation mix (Chinese purpose, English parameter labels) is slightly inconsistent but not detrimental.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which handles return values), no annotations, and simple parameters (2 required), the description is moderately complete. It covers the basic purpose and parameters but lacks behavioral context (e.g., authentication, rate limits) and usage guidelines. For a read-only tool with output schema, it's adequate but could be more informative about when and how to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the schema provides no parameter descriptions. The description adds basic semantics: 'project_id: 專案 ID 或路徑' (project ID or path) and 'mr_iid: MR 的 IID' (MR's IID). This clarifies that project_id can be an ID or path and mr_iid is an integer IID (not the global ID). However, it doesn't explain where to find these values, their formats, or examples. With 0% schema coverage, the description partially compensates but leaves gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '取得 Merge Request 的檔案變更(diff)' (Get Merge Request file changes/diff). It specifies the verb ('取得' - get) and resource ('Merge Request 的檔案變更' - Merge Request file changes). It distinguishes from siblings like get_merge_request (which likely gets MR metadata) and get_merge_request_commits (which gets commits). However, it doesn't explicitly differentiate from compare_branches (which might also show diffs).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when this tool is appropriate (e.g., for reviewing code changes before merging) or when not to use it (e.g., for getting MR metadata). It doesn't reference sibling tools like compare_branches (for branch diffs) or get_merge_request_commits (for commit lists). The only implicit context is that it's for MRs, but no explicit usage rules are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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