Skip to main content
Glama
Alosies

GitLab MCP Server

by Alosies

get_branch_diffs

Compare changes between branches or commits in a GitLab project to review code differences and track modifications.

Instructions

Get the changes/diffs between two branches or commits in a GitLab project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID or path
fromYesThe base branch or commit SHA to compare from
toYesThe target branch or commit SHA to compare to
straightNoComparison method: false for "..." (default), true for "--"

Implementation Reference

  • The core handler function that implements the get_branch_diffs tool logic: constructs the GitLab repository/compare API URL and fetches/returns the diffs as JSON.
    async getBranchDiffs(args: GetBranchDiffsParams) {
      const params = new URLSearchParams();
      params.append("from", args.from);
      params.append("to", args.to);
      if (args.straight !== undefined)
        params.append("straight", String(args.straight));
    
      const url = `/projects/${encodeURIComponent(
        args.project_id
      )}/repository/compare?${params.toString()}`;
    
      const data = await this.client.get(url);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(data, null, 2),
          },
        ],
      };
    }
  • Tool definition including the input schema (JSON Schema) for validating parameters: project_id, from, to, straight.
    {
      name: 'get_branch_diffs',
      description: 'Get the changes/diffs between two branches or commits in a GitLab project',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'string',
            description: 'Project ID or path',
          },
          from: {
            type: 'string',
            description: 'The base branch or commit SHA to compare from',
          },
          to: {
            type: 'string',
            description: 'The target branch or commit SHA to compare to',
          },
          straight: {
            type: 'boolean',
            description: 'Comparison method: false for "..." (default), true for "--"',
          },
        },
        required: ['project_id', 'from', 'to'],
      },
    },
  • src/server.ts:201-204 (registration)
    Server-side dispatch/registration in the CallToolRequestSchema handler switch statement that routes calls to the mergeRequestHandlers.getBranchDiffs method.
    case "get_branch_diffs":
      return await this.mergeRequestHandlers.getBranchDiffs(
        args as unknown as GetBranchDiffsParams
      );
  • TypeScript type definition/interface for the GetBranchDiffsParams used in handler signature and server dispatch.
    export interface GetBranchDiffsParams {
      project_id: string;
      from: string;
      to: string;
      straight?: boolean;
    }

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

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