Skip to main content
Glama

gitlab_get_merge_request_changes

Retrieve detailed file changes and complete diffs for a GitLab merge request to review code modifications with full context.

Instructions

Get detailed MR file changes Returns: Complete diffs for all files Use when: Reviewing code changes Shows: Full file diffs with context

Similar to commit diff but for entire MR Includes all commits in the MR

Related tools:

  • gitlab_get_merge_request: MR overview

  • gitlab_smart_diff: Customizable diffs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idNoProject identifier (auto-detected if not provided) Type: integer OR string Format: numeric ID or 'namespace/project' Optional: Yes - auto-detects from current git repository Examples: - 12345 (numeric ID) - 'gitlab-org/gitlab' (namespace/project path) - 'my-group/my-subgroup/my-project' (nested groups) Note: If in a git repo with GitLab remote, this can be omitted
mr_iidYesMerge request number (IID - Internal ID) Type: integer Format: Project-specific MR number (without !) Required: Yes Examples: - 456 (for MR !456) - 7890 (for MR !7890) How to find: Look at MR URL or title - URL: https://gitlab.com/group/project/-/merge_requests/456 → use 456 - Title: "Add new feature (!456)" → use 456 Note: This is NOT the global MR ID

Implementation Reference

  • The core handler function that implements the tool logic. Extracts project_id (auto-detects if missing) and mr_iid from arguments, then delegates to GitLabClient.get_merge_request_changes() to fetch the MR changes/diffs.
    def handle_get_merge_request_changes(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]:
        """Handle getting merge request changes"""
        project_id = require_project_id(client, arguments)
        mr_iid = require_argument(arguments, "mr_iid")
        
        return client.get_merge_request_changes(project_id, mr_iid)
  • The TOOL_HANDLERS dictionary maps tool names (like TOOL_GET_MR_CHANGES) to their handler functions. Used in server.py handle_call_tool() to dispatch tool calls to the correct handler.
    TOOL_HANDLERS = {
        # List tools
        TOOL_LIST_PROJECTS: handle_list_projects,
        TOOL_LIST_ISSUES: handle_list_issues,
        TOOL_LIST_MRS: handle_list_merge_requests,
        TOOL_LIST_BRANCHES: handle_list_branches,
        TOOL_LIST_PIPELINES: handle_list_pipelines,
        TOOL_LIST_USER_EVENTS: handle_get_user_events,
        TOOL_LIST_COMMITS: handle_get_commits,
        TOOL_LIST_REPOSITORY_TREE: handle_get_repository_tree,
        TOOL_LIST_TAGS: handle_get_tags,
        TOOL_LIST_RELEASES: handle_list_releases,
        TOOL_LIST_PROJECT_MEMBERS: handle_get_project_members,
        TOOL_LIST_PROJECT_HOOKS: handle_get_project_hooks,
        TOOL_LIST_GROUPS: handle_list_groups,
        TOOL_LIST_GROUP_PROJECTS: handle_list_group_projects,
        TOOL_LIST_SNIPPETS: handle_list_snippets,
        TOOL_LIST_PIPELINE_JOBS: handle_list_pipeline_jobs,
        TOOL_LIST_PROJECT_JOBS: handle_list_project_jobs,
    
        # Get tools
        TOOL_GET_PROJECT: handle_get_project,
        TOOL_GET_CURRENT_PROJECT: handle_get_current_project,
        TOOL_GET_MR_NOTES: handle_get_merge_request_notes,
        TOOL_GET_CURRENT_USER: handle_get_current_user,
        TOOL_GET_USER: handle_get_user,
        TOOL_GET_GROUP: handle_get_group,
        TOOL_GET_SNIPPET: handle_get_snippet,
        TOOL_DOWNLOAD_JOB_ARTIFACT: handle_download_job_artifact,
        TOOL_GET_ISSUE: handle_get_issue,
        TOOL_GET_MERGE_REQUEST: handle_get_merge_request,
        TOOL_GET_FILE_CONTENT: handle_get_file_content,
        TOOL_GET_COMMIT: handle_get_commit,
        TOOL_GET_COMMIT_DIFF: handle_get_commit_diff,
        TOOL_GET_MR_APPROVALS: handle_get_merge_request_approvals,
        TOOL_GET_MR_DISCUSSIONS: handle_get_merge_request_discussions,
        TOOL_GET_MR_CHANGES: handle_get_merge_request_changes,
    
        # Action tools
        TOOL_CREATE_SNIPPET: handle_create_snippet,
        TOOL_UPDATE_SNIPPET: handle_update_snippet,
        TOOL_UPDATE_MR: handle_update_merge_request,
        TOOL_CLOSE_MR: handle_close_merge_request,
        TOOL_MERGE_MR: handle_merge_merge_request,
        TOOL_REBASE_MR: handle_rebase_merge_request,
        TOOL_APPROVE_MR: handle_approve_merge_request,
        TOOL_ADD_ISSUE_COMMENT: handle_add_issue_comment,
        TOOL_ADD_MR_COMMENT: handle_add_merge_request_comment,
        TOOL_RESOLVE_DISCUSSION: handle_resolve_discussion,
        TOOL_CREATE_COMMIT: handle_create_commit,
        TOOL_CHERRY_PICK_COMMIT: handle_cherry_pick_commit,
        TOOL_COMPARE_REFS: handle_compare_refs,
    
        # Search tools
        TOOL_SEARCH_PROJECTS: handle_search_projects,
        TOOL_SEARCH_IN_PROJECT: handle_search_in_project,
    
        # AI and Advanced Tools
        TOOL_SUMMARIZE_MR: handle_summarize_merge_request,
        TOOL_SUMMARIZE_ISSUE: handle_summarize_issue,
        TOOL_SUMMARIZE_PIPELINE: handle_summarize_pipeline,
        TOOL_SMART_DIFF: handle_smart_diff,
        TOOL_SAFE_PREVIEW_COMMIT: handle_safe_preview_commit,
        TOOL_BATCH_OPERATIONS: handle_batch_operations,
        
        # Job and Artifact handlers
        TOOL_LIST_PIPELINE_JOBS: handle_list_pipeline_jobs,
        TOOL_DOWNLOAD_JOB_ARTIFACT: handle_download_job_artifact,
        TOOL_LIST_PROJECT_JOBS: handle_list_project_jobs,
        
        # User & Profile handlers
        TOOL_SEARCH_USER: handle_search_user,
        TOOL_GET_USER_DETAILS: handle_get_user_details,
        TOOL_GET_MY_PROFILE: handle_get_my_profile,
        TOOL_GET_USER_CONTRIBUTIONS_SUMMARY: handle_get_user_contributions_summary,
        TOOL_GET_USER_ACTIVITY_FEED: handle_get_user_activity_feed,
        
        # User's Issues & MRs handlers
        TOOL_GET_USER_OPEN_MRS: handle_get_user_open_mrs,
        TOOL_GET_USER_REVIEW_REQUESTS: handle_get_user_review_requests,
        TOOL_GET_USER_OPEN_ISSUES: handle_get_user_open_issues,
        TOOL_GET_USER_REPORTED_ISSUES: handle_get_user_reported_issues,
        TOOL_GET_USER_RESOLVED_ISSUES: handle_get_user_resolved_issues,
        
        # User's Code & Commits handlers  
        TOOL_GET_USER_COMMITS: handle_get_user_commits,
        TOOL_GET_USER_MERGE_COMMITS: handle_get_user_merge_commits,
        TOOL_GET_USER_CODE_CHANGES_SUMMARY: handle_get_user_code_changes_summary,
        TOOL_GET_USER_SNIPPETS: handle_get_user_snippets,
        
        # User's Comments & Discussions handlers
        TOOL_GET_USER_ISSUE_COMMENTS: handle_get_user_issue_comments,
        TOOL_GET_USER_MR_COMMENTS: handle_get_user_mr_comments,
        TOOL_GET_USER_DISCUSSION_THREADS: handle_get_user_discussion_threads,
        TOOL_GET_USER_RESOLVED_THREADS: handle_get_user_resolved_threads,
    }
  • MCP Tool schema definition registered via @server.list_tools(). Defines input parameters: project_id (optional, auto-detected) and required mr_iid (integer). Returned by list_tools() endpoint.
    types.Tool(
        name="gitlab_get_merge_request_changes",
        description=desc.DESC_GET_MR_CHANGES,
        inputSchema={
            "type": "object",
            "properties": {
                "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID},
                "mr_iid": {"type": "integer", "description": desc.DESC_MR_IID}
            },
            "required": ["mr_iid"]
        }
    ),
  • The @server.call_tool() handler that receives tool calls from MCP client. Looks up handler function via TOOL_HANDLERS[name], executes it with GitLabClient and arguments, handles errors, truncates large responses, and returns JSON.
    async def handle_call_tool(
        name: str, arguments: dict | None
    ) -> List[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle tool execution with comprehensive error handling"""
        try:
            client = get_gitlab_client()
            
            # Check if tool exists
            handler = TOOL_HANDLERS.get(name)
            if not handler:
                raise ValueError(f"Unknown tool: {name}")
            
            # Execute the handler
            result = handler(client, arguments)
            
            # Truncate response if too large
            result = truncate_response(result, MAX_RESPONSE_SIZE)
            
            return [types.TextContent(
                type="text",
                text=json.dumps(result, indent=2)
            )]
            
        except gitlab.exceptions.GitlabAuthenticationError as e:
            logger.error(f"Authentication failed: {e}")
            error_response = sanitize_error(e, ERROR_AUTH_FAILED)
            return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))]
        except gitlab.exceptions.GitlabGetError as e:
            response_code = getattr(e, 'response_code', None)
            if response_code == 404:
                logger.warning(f"Resource not found: {e}")
                error_response = sanitize_error(e, ERROR_NOT_FOUND)
            elif response_code == 429:
                logger.warning(f"Rate limit exceeded: {e}")
                error_response = sanitize_error(e, ERROR_RATE_LIMIT)
            else:
                logger.error(f"GitLab API error: {e}")
                error_response = sanitize_error(e)
            return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))]
        except gitlab.exceptions.GitlabError as e:
            logger.error(f"General GitLab error: {e}")
            error_response = sanitize_error(e)
            return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))]
        except ValueError as e:
            logger.warning(f"Invalid input: {e}")
            error_response = sanitize_error(e, ERROR_INVALID_INPUT)
            return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))]
        except Exception as e:
            logger.error(f"Unexpected error: {e}")
            error_response = sanitize_error(e, ERROR_GENERIC)
            return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))]
  • Constant defining the exact tool name string used throughout the codebase for references, mappings, and schema definitions.
    TOOL_GET_MR_CHANGES = "gitlab_get_merge_request_changes"
Behavior4/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it returns 'Complete diffs for all files', 'Full file diffs with context', and includes 'all commits in the MR'. However, it doesn't mention potential limitations like rate limits, authentication needs, or pagination behavior, which would be helpful for a read operation.

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

Conciseness5/5

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

The description is well-structured with bullet-like sections (Returns, Use when, Shows) and a related tools list. Every sentence adds value: the first line states the purpose, subsequent lines provide context and comparisons, and the final section clarifies sibling relationships. No wasted words.

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

Completeness4/5

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

Given the tool's moderate complexity (read operation with 2 parameters), no annotations, and no output schema, the description does a good job explaining what the tool returns ('Complete diffs', 'Full file diffs with context') and when to use it. However, it could benefit from more detail on output format or error conditions to be fully complete.

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 100%, providing detailed documentation for both parameters. The description adds no parameter-specific information beyond what's in the schema, so it meets the baseline of 3. It doesn't compensate but doesn't need to given the comprehensive schema.

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

Purpose5/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 with specific verbs ('Get detailed MR file changes') and resources ('MR file changes', 'Complete diffs for all files'). It effectively distinguishes from siblings like 'gitlab_get_merge_request' (overview) and 'gitlab_smart_diff' (customizable diffs) by specifying it returns complete diffs for all files in the MR.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance with 'Use when: Reviewing code changes' and lists related tools with clear distinctions ('gitlab_get_merge_request: MR overview', 'gitlab_smart_diff: Customizable diffs'). This tells the agent precisely when to use this tool versus alternatives.

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

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