Skip to main content
Glama
bsreeram08

Git Repo Browser MCP

git_branch_diff

Compare two Git branches to identify files changed between them. Use this tool to analyze differences in code, track modifications, and review changes before merging branches in a repository.

Instructions

Compare two branches and show files changed between them.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_urlYesThe URL of the Git repository
source_branchYesThe source branch name
target_branchYesThe target branch name
show_patchNoWhether to include the actual diff patches

Implementation Reference

  • The main handler function that executes the git_branch_diff tool. It clones the repository, ensures branches are available, computes the diff between source and target branches (with optional patch), gets commit count, and returns a JSON-formatted result or error.
    export async function handleGitBranchDiff({
      repo_url,
      source_branch,
      target_branch,
      show_patch = false,
    }) {
      try {
        const repoPath = await cloneRepo(repo_url);
        const git = simpleGit(repoPath);
    
        // Make sure both branches exist locally
        const branches = await git.branch();
        if (!branches.all.includes(source_branch)) {
          await git.fetch("origin", source_branch);
          await git.checkout(source_branch);
        }
    
        if (!branches.all.includes(target_branch)) {
          await git.fetch("origin", target_branch);
        }
    
        // Get the diff between branches
        const diffOptions = ["--name-status"];
        if (show_patch) {
          diffOptions.push("--patch");
        }
    
        const diff = await git.diff([
          ...diffOptions,
          `${target_branch}...${source_branch}`,
        ]);
    
        // Get commit range information
        const logSummary = await git.log({
          from: target_branch,
          to: source_branch,
        });
    
        const result = {
          commits_count: logSummary.total,
          diff_summary: diff,
        };
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                { error: `Failed to get branch diff: ${error.message}` },
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
  • The MCP tool schema definition for 'git_branch_diff', including description and input schema with properties repo_url, source_branch, target_branch, and optional show_patch.
    name: "git_branch_diff",
    description:
      "Compare two branches and show files changed between them.",
    inputSchema: {
      type: "object",
      properties: {
        repo_url: {
          type: "string",
          description: "The URL of the Git repository",
        },
        source_branch: {
          type: "string",
          description: "The source branch name",
        },
        target_branch: {
          type: "string",
          description: "The target branch name",
        },
        show_patch: {
          type: "boolean",
          description: "Whether to include the actual diff patches",
          default: false,
        },
      },
      required: ["repo_url", "source_branch", "target_branch"],
    },
  • src/server.js:902-902 (registration)
    Registers the tool name 'git_branch_diff' mapped to the handleGitBranchDiff handler function in the server's handlersMap.
    git_branch_diff: handleGitBranchDiff,
  • Imports the handleGitBranchDiff handler from branch-operations.js into the handlers index module, facilitating its use in the server.
    import {
      handleGitBranchDiff,
      handleGitCheckoutBranch,
      handleGitDeleteBranch,
      handleGitMergeBranch,
    } from "./branch-operations.js";

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/bsreeram08/git-commands-mcp'

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