Skip to main content
Glama

compare_branches

Compare two branches in a GitLab project to see differences. Specify project ID, source branch, and target branch.

Instructions

Compare two branches.

Args:
    project_id: GitLab project ID
    from_branch: Source branch
    to_branch: Target branch
    token: GitLab Personal Access Token (optional)
    ctx: MCP context (automatically injected)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
from_branchYes
to_branchYes
tokenNo
ctxNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual handler function for the 'compare_branches' tool. It calls the GitLab API endpoint /projects/{project_id}/repository/compare?from={from_branch}&to={to_branch}, then formats the result showing commit count, files changed, and recent commits.
    async def compare_branches(project_id: int, from_branch: str, to_branch: str, token: str = None, ctx=None) -> str:
        """Compare two branches.
        
        Args:
            project_id: GitLab project ID
            from_branch: Source branch
            to_branch: Target branch
            token: GitLab Personal Access Token (optional)
            ctx: MCP context (automatically injected)
        """
        endpoint = f"/projects/{project_id}/repository/compare?from={from_branch}&to={to_branch}"
        data = await make_gitlab_request(endpoint, ctx=ctx, token=token)
        
        if isinstance(data, dict) and "error" in data:
            return f"Error: {data['error']}"
        
        commits = data.get('commits', [])
        diffs = data.get('diffs', [])
        
        result = f"Comparing {from_branch} to {to_branch}:\n"
        result += f"Commits: {len(commits)}\n"
        result += f"Files changed: {len(diffs)}\n\n"
        
        if commits:
            result += "Recent commits:\n"
            for commit in commits[:5]:
                result += f"• {commit['short_id']}: {commit['title']}\n"
        
        return result
  • The @mcp.tool() decorator registers the compare_branches function as an MCP tool.
    @mcp.tool()
    async def compare_branches(project_id: int, from_branch: str, to_branch: str, token: str = None, ctx=None) -> str:
Behavior2/5

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

No annotations are present, and the description does not disclose any behavioral traits beyond the basic operation. It does not mention side effects (e.g., no mutation is expected), required permissions, or response format. The description merely lists parameters without behavioral context.

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

Conciseness3/5

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

The description is relatively short but includes a redundant parameter list that duplicates the input schema. While not verbose, it could be more efficient by omitting the parameter details and focusing on usage guidance.

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

Completeness2/5

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

Given the tool has 5 parameters, 0% schema description coverage, and no annotations, the description is inadequate. It does not explain the return values despite an output schema existing, nor does it provide any context on how the comparison works (e.g., what is compared, output structure).

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

Parameters2/5

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

Schema description coverage is 0%, and the description adds no additional meaning beyond the parameter names and types already present in the input schema. It does not explain formats, constraints, or relationships between parameters (e.g., that 'from_branch' and 'to_branch' must exist).

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 'Compare two branches', which is a specific verb and resource. While it distinguishes from similar tools like 'create_branch' or 'delete_branch', it does not explicitly differentiate from other comparison or diff tools that might exist.

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?

No guidance is provided on when to use this tool versus alternatives, such as 'get_commits' or 'merge_merge_request'. There is no mention of prerequisites, context, or exclusions.

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/skmprb/gitlab-clone-mcp-server'

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