Skip to main content
Glama
bsreeram08

Git Repo Browser MCP

git_blame

Identify which commit introduced each line in a file to track changes and understand code evolution in Git repositories.

Instructions

Get blame information for a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
file_pathYesPath to the file
revNoRevision to blame (default: HEAD)HEAD

Implementation Reference

  • The core handler function that runs `git blame --line-porcelain`, parses the detailed output, and returns structured blame information for each line including commit hash, author, time, and content.
    export async function handleGitBlame({ repo_path, file_path, rev = "HEAD" }) {
      try {
        const git = simpleGit(repo_path);
    
        // Run git blame
        const blameResult = await git.raw([
          "blame",
          "--line-porcelain",
          rev,
          "--",
          file_path,
        ]);
    
        // Parse the output
        const lines = blameResult.split("\n");
        const blameInfo = [];
    
        let currentCommit = null;
    
        for (let i = 0; i < lines.length; i++) {
          const line = lines[i];
    
          // Start of a new blame entry
          if (line.match(/^[0-9a-f]{40}/)) {
            if (currentCommit) {
              blameInfo.push(currentCommit);
            }
    
            const parts = line.split(" ");
            currentCommit = {
              hash: parts[0],
              originalLine: parseInt(parts[1]),
              finalLine: parseInt(parts[2]),
              lineCount: parseInt(parts[3] || 1),
              author: "",
              authorMail: "",
              authorTime: 0,
              subject: "",
              content: "",
            };
          } else if (line.startsWith("author ") && currentCommit) {
            currentCommit.author = line.substring(7);
          } else if (line.startsWith("author-mail ") && currentCommit) {
            currentCommit.authorMail = line.substring(12).replace(/[<>]/g, "");
          } else if (line.startsWith("author-time ") && currentCommit) {
            currentCommit.authorTime = parseInt(line.substring(12));
          } else if (line.startsWith("summary ") && currentCommit) {
            currentCommit.subject = line.substring(8);
          } else if (line.startsWith("\t") && currentCommit) {
            // This is the content line
            currentCommit.content = line.substring(1);
            blameInfo.push(currentCommit);
            currentCommit = null;
          }
        }
    
        // Add the last commit if there is one
        if (currentCommit) {
          blameInfo.push(currentCommit);
        }
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  success: true,
                  file: file_path,
                  blame: blameInfo,
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                { error: `Failed to get blame information: ${error.message}` },
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
    }
  • Tool schema definition specifying the name, description, and input parameters (repo_path, file_path, rev) for the git_blame tool, used in ListTools response.
    {
      name: "git_blame",
      description: "Get blame information for a file.",
      inputSchema: {
        type: "object",
        properties: {
          repo_path: {
            type: "string",
            description: "The path to the local Git repository",
          },
          file_path: {
            type: "string",
            description: "Path to the file",
          },
          rev: {
            type: "string",
            description: "Revision to blame (default: HEAD)",
            default: "HEAD",
          },
        },
        required: ["repo_path", "file_path"],
      },
    },
  • src/server.js:898-927 (registration)
    Maps the tool name 'git_blame' to its handler function handleGitBlame in the central handlersMap used by the MCP server to dispatch tool calls.
    this.handlersMap = {
      // Primary handlers
      git_directory_structure: handleGitDirectoryStructure,
      git_read_files: handleGitReadFiles,
      git_branch_diff: handleGitBranchDiff,
      git_commit_history: handleGitCommitHistory,
      git_commits_details: handleGitCommitsDetails,
      git_local_changes: handleGitLocalChanges,
      git_search_code: handleGitSearchCode,
      git_commit: handleGitCommit,
      git_track: handleGitTrack,
      git_checkout_branch: handleGitCheckoutBranch,
      git_delete_branch: handleGitDeleteBranch,
      git_merge_branch: handleGitMergeBranch,
      git_push: handleGitPush,
      git_pull: handleGitPull,
      git_stash: handleGitStash,
      git_create_tag: handleGitCreateTag,
      git_rebase: handleGitRebase,
      git_config: handleGitConfig,
      git_reset: handleGitReset,
      git_archive: handleGitArchive,
      git_attributes: handleGitAttributes,
      git_blame: handleGitBlame,
      git_clean: handleGitClean,
      git_hooks: handleGitHooks,
      git_lfs: handleGitLFS,
      git_lfs_fetch: handleGitLFSFetch,
      git_revert: handleGitRevert,
    };
  • Imports handleGitBlame from other-operations.js into the index barrel file for centralized access.
    import {
      handleGitArchive,
      handleGitAttributes,
      handleGitBlame,
      handleGitClean,
      handleGitHooks,
      handleGitLFS,
      handleGitLFSFetch,
      handleGitRevert,
    } from "./other-operations.js";
  • Re-exports handleGitBlame from the handlers index for convenient import in server.js.
    // Other operations
    handleGitArchive,
    handleGitAttributes,
    handleGitBlame,
    handleGitClean,
    handleGitHooks,
    handleGitLFS,
    handleGitLFSFetch,
    handleGitRevert,
Behavior2/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 but offers minimal information. It states what the tool does ('Get blame information') but doesn't describe the output format (e.g., line-by-line authorship data), potential errors (e.g., if the file doesn't exist), or side effects (likely read-only, but not explicitly stated). This is inadequate for a tool with no annotation coverage.

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 a single, efficient sentence with zero wasted words. It's front-loaded with the core purpose ('Get blame information for a file'), making it immediately scannable and easy to parse. Every word earns its place, and there's no redundancy or unnecessary elaboration.

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 complexity of a Git blame operation (which involves version control data), lack of annotations, and no output schema, the description is insufficiently complete. It doesn't explain what 'blame information' entails (e.g., commit hashes, authors, timestamps per line), potential use cases, or error conditions. For a tool with no structured behavioral hints, this leaves significant gaps for an agent to operate effectively.

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?

The input schema has 100% description coverage, with clear documentation for all three parameters (repo_path, file_path, rev). The description adds no additional parameter semantics beyond what the schema provides, such as explaining how 'blame information' relates to these inputs. Since schema coverage is high, the baseline score of 3 is appropriate, as the description doesn't compensate but doesn't need to.

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 the action ('Get blame information') and resource ('for a file'), making the purpose immediately understandable. It distinguishes itself from siblings like git_commit_history or git_search_code by focusing specifically on blame data rather than general history or search. However, it doesn't explicitly differentiate from all siblings (e.g., git_read_files might also read file content).

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when blame information is needed (e.g., for debugging or attribution), what alternatives exist among siblings (like git_commit_history for broader history), or any prerequisites (e.g., needing a valid repository). This leaves the agent to infer usage context from the tool name alone.

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

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