Skip to main content
Glama

gitlab_compare_refs

Compare two Git references to review changes between branches, tags, or commits before merging. Shows commits and diffs to understand what changed between two points in a GitLab project.

Instructions

Compare two git references Returns: Commits and diffs between refs Use when: Reviewing changes before merge Shows: What changed between two points

Example: Compare feature branch to main

  • from: "main"

  • to: "feature/new-feature" Shows all changes in feature branch

Related tools:

  • gitlab_create_merge_request: Create MR from comparison

  • gitlab_smart_diff: Advanced diff options

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
from_refYesSource reference for comparison Type: string Required: Yes Format: Branch, tag, or commit SHA Examples: - 'feature/new-api' (branch) - 'v1.0.0' (tag) - 'abc123def' (commit) Use case: Starting point for comparison
to_refYesTarget reference for comparison Type: string Required: Yes Format: Branch, tag, or commit SHA Examples: - 'main' (branch) - 'v2.0.0' (tag) - '456789abc' (commit) Use case: Ending point for comparison
straightNoDiff type Type: boolean Default: false Options: - true: Direct comparison (A..B) - false: Three-dot comparison (A...B) Explanation: - Direct: All changes between two points - Three-dot: Changes in B since common ancestor Use case: false for MR-style diffs, true for direct comparison

Implementation Reference

  • Main handler function that implements the core logic for the gitlab_compare_refs tool. Extracts parameters, validates project, and delegates to GitLabClient.compare_refs().
    def handle_compare_refs(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]:
        """Handle comparing two refs"""
        project_id = require_project_id(client, arguments)
        from_ref = require_argument(arguments, "from_ref")
        to_ref = require_argument(arguments, "to_ref")
        straight = get_argument(arguments, "straight", False)
        
        return client.compare_refs(project_id, from_ref, to_ref, straight)
  • Pydantic/MCP tool schema definition specifying input parameters, types, descriptions, and requirements for gitlab_compare_refs.
    name=TOOL_COMPARE_REFS,
    description=desc.DESC_COMPARE_REFS,
    inputSchema={
        "type": "object",
        "properties": {
            "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID},
            "from_ref": {"type": "string", "description": desc.DESC_FROM_REF},
            "to_ref": {"type": "string", "description": desc.DESC_TO_REF},
            "straight": {"type": "boolean", "description": desc.DESC_STRAIGHT, "default": False}
        },
        "required": ["from_ref", "to_ref"]
    }
  • Registration of the handler function in the central TOOL_HANDLERS dictionary, mapping tool name to its executor. Used by server.call_tool().
    TOOL_COMPARE_REFS: handle_compare_refs,
  • Constant defining the canonical tool name string used throughout the codebase for consistency.
    TOOL_COMPARE_REFS = "gitlab_compare_refs"
  • Tool schema registration in the server's list_tools() method, exposing it to MCP clients.
    name="gitlab_compare_refs",
    description=desc.DESC_COMPARE_REFS,
    inputSchema={
        "type": "object",
        "properties": {
            "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID},
            "from_ref": {"type": "string", "description": desc.DESC_FROM_REF},
            "to_ref": {"type": "string", "description": desc.DESC_TO_REF},
            "straight": {"type": "boolean", "description": desc.DESC_STRAIGHT, "default": False}
        },
        "required": ["from_ref", "to_ref"]
    }
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 of behavioral disclosure. It does well by stating what the tool returns ('commits and diffs between refs') and showing what it does ('Shows: What changed between two points'). However, it doesn't mention potential limitations like rate limits, authentication requirements, or whether this is a read-only operation (though 'compare' implies non-destructive).

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 perfectly structured and concise. It uses bullet points and clear sections ('Returns:', 'Use when:', 'Shows:', 'Example:', 'Related tools:') with zero wasted words. Every sentence earns its place by providing essential information in a scannable format.

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?

For a comparison tool with no output schema and no annotations, the description does well by explaining what the tool returns and when to use it. However, it could be more complete by mentioning the output format (e.g., JSON structure of commits/diffs) or any limitations. The example helps, but without an output schema, more detail about the return value would be beneficial.

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%, so the schema already fully documents all 4 parameters. The description adds minimal parameter semantics beyond the schema - it provides an example with 'from: "main"' and 'to: "feature/new-feature"' but doesn't explain parameter relationships or constraints beyond what's in the schema descriptions. This meets the baseline for high schema coverage.

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: 'Compare two git references' with specific verbs and resources. It distinguishes from siblings by explicitly mentioning what it returns ('commits and diffs between refs') and provides a concrete example comparing 'feature branch to main', making the purpose unambiguous and distinct from related tools like gitlab_smart_diff.

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 explicitly states 'Use when: Reviewing changes before merge', providing clear context for when to use this tool. It also lists related tools with specific guidance: 'gitlab_create_merge_request: Create MR from comparison' and 'gitlab_smart_diff: Advanced diff options', giving clear alternatives for different use cases.

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