Skip to main content
Glama
jonmatum

Git Metrics MCP Server

by jonmatum

get_commit_stats

Retrieve commit statistics for a git repository within a date range, optionally filtered by author. Analyze development activity and team contribution patterns.

Instructions

Get commit statistics for a repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesPath to git repository
sinceYesStart date (YYYY-MM-DD)
untilNoEnd date (YYYY-MM-DD), optional
authorNoFilter by author email/name, optional

Implementation Reference

  • The main handler function for the get_commit_stats tool. It runs a git log command with --shortstat, parses the output to count commits, additions, deletions, and files changed, and returns an object with those stats plus netChange.
    export function handleGetCommitStats(args: any) {
      const { repo_path, since, until, author } = args;
      
      validateRepoPath(repo_path);
      validateDate(since, "since");
      if (until) validateDate(until, "until");
      
      let cmd = `git log --since="${since}"`;
      if (until) cmd += ` --until="${until} 23:59:59"`;
      if (author) cmd += ` --author="${author}"`;
      cmd += ` --pretty=format:"%H" --shortstat`;
    
      const output = runGitCommand(repo_path, cmd);
      const lines = output.trim().split("\n");
      
      let commits = 0, additions = 0, deletions = 0, filesChanged = 0;
      
      for (const line of lines) {
        if (line.match(/^[0-9a-f]{40}$/)) {
          commits++;
        } else if (line.includes("changed")) {
          const addMatch = line.match(/(\d+) insertion/);
          const delMatch = line.match(/(\d+) deletion/);
          const fileMatch = line.match(/(\d+) file/);
          if (addMatch) additions += parseInt(addMatch[1]);
          if (delMatch) deletions += parseInt(delMatch[1]);
          if (fileMatch) filesChanged += parseInt(fileMatch[1]);
        }
      }
    
      return {
        commits,
        additions,
        deletions,
        filesChanged,
        netChange: additions - deletions,
      };
    }
  • Tool registration with its input schema definition. Defines the tool name 'get_commit_stats', description, and input schema with properties: repo_path (required), since (required), until (optional), author (optional).
      name: "get_commit_stats",
      description: "Get commit statistics for a repository",
      inputSchema: {
        type: "object",
        properties: {
          repo_path: { type: "string", description: "Path to git repository" },
          since: { type: "string", description: "Start date (YYYY-MM-DD)" },
          until: { type: "string", description: "End date (YYYY-MM-DD), optional" },
          author: { type: "string", description: "Filter by author email/name, optional" },
        },
        required: ["repo_path", "since"],
      },
    },
  • The CallToolRequestSchema handler that dispatches the 'get_commit_stats' tool name to the handleGetCommitStats function.
    } else if (request.params.name === "get_commit_stats") {
      result = handlers.handleGetCommitStats(args);
  • The runGitCommand helper function that executes git commands. Used by the handler to run git log.
    export function runGitCommand(repoPath: string, command: string): string {
      const fullPath = resolve(repoPath);
      if (!existsSync(fullPath)) {
        throw new Error(`Repository path does not exist: ${fullPath}`);
      }
      try {
        return execSync(command, { 
          cwd: fullPath, 
          encoding: "utf-8",
          timeout: GIT_TIMEOUT,
          maxBuffer: MAX_BUFFER
        });
      } catch (error: any) {
        log('ERROR', 'Git command failed', { command, error: error.message });
        throw new Error(`Git command failed: ${error.message}`);
      }
    }
  • The validateDate helper function used by the handler to ensure dates are in YYYY-MM-DD format.
    export function validateDate(date: string, fieldName: string): void {
      if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
        throw new Error(`Invalid ${fieldName} format. Use YYYY-MM-DD (e.g., 2025-11-21)`);
      }
    }
Behavior2/5

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

Annotations are missing, so the description must carry the full transparency burden. It implies a read-only operation ('Get') but does not explicitly confirm safety, side effects, or authentication requirements.

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, clear sentence with no wasted words. It is front-loaded and efficient.

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?

The description is too minimal given the complexity of 4 parameters and no output schema. It does not explain what statistics are returned, leaving the agent uncertain about the tool's full behavior.

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 coverage is 100%, so baseline is 3. The description adds no additional meaning beyond what the schema already provides for the parameters.

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') and resource ('commit statistics'), but lacks specificity about what statistics are included. It does not differentiate from sibling tools like get_author_metrics or get_commit_patterns.

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 on when to use this tool versus alternatives. It does not mention prerequisites, when not to use it, or which sibling tools might be more appropriate.

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/jonmatum/git-metrics-mcp-server'

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