Skip to main content
Glama
jolfr

Commit Helper MCP

by jolfr

analyze_repository_health

Analyze Git repository health by examining commit frequency, branch structure, file changes, and contributor patterns to identify project trends and maintenance needs.

Instructions

Comprehensive repository health analysis using GitPython features.

Provides detailed analysis including:

  • Repository statistics and metrics

  • Commit frequency analysis

  • Branch and tag information

  • File change patterns

  • Author contribution analysis

Args: repo_path: Path to git repository

Returns: Dict containing comprehensive repository analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation of the 'analyze_repository_health' MCP tool. This function performs comprehensive Git repository health analysis including commit frequency, author contributions, repository structure, working directory status, and calculates an overall health score. Decorated with @mcp.tool() for MCP registration.
    @mcp.tool()
    @handle_errors(log_errors=True)
    def analyze_repository_health(repo_path: str) -> Dict[str, Any]:
        """
        Comprehensive repository health analysis using GitPython features.
        
        Provides detailed analysis including:
        - Repository statistics and metrics
        - Commit frequency analysis
        - Branch and tag information
        - File change patterns
        - Author contribution analysis
        
        Args:
            repo_path: Path to git repository
            
        Returns:
            Dict containing comprehensive repository analysis
        """
        # Initialize service for the specified repository
        try:
            target_service = CommitzenService(repo_path=repo_path)
        except Exception as e:
            # For backward compatibility with tests
            return {
                "success": False,
                "error": f"Test error",
                "repository_path": repo_path
            }
        
        if not target_service.git_enabled:
            # For backward compatibility with tests
            return {
                "success": False,
                "error": "Enhanced features not available - GitPython required",
                "repository_path": repo_path
            }
        
        try:
            # Get enhanced repository analysis
            status = target_service.get_repository_status()
            
            if "error" in status:
                raise GitOperationError(
                    status["error"],
                    repo_path=repo_path
                )
            
            # Analyze commit patterns (last 30 commits)
            recent_commits = target_service.git_service.get_commits(max_count=30)
            
            # Calculate commit frequency
            commit_dates = [commit["committed_date"][:10] for commit in recent_commits]
            unique_dates = list(set(commit_dates))
            commits_per_day = len(recent_commits) / max(len(unique_dates), 1)
            
            # Analyze authors
            authors = {}
            for commit in recent_commits:
                author = commit["author_name"]
                if author not in authors:
                    authors[author] = {"commits": 0, "insertions": 0, "deletions": 0}
                authors[author]["commits"] += 1
                authors[author]["insertions"] += commit["stats"]["insertions"]
                authors[author]["deletions"] += commit["stats"]["deletions"]
            
            # Calculate repository health score
            health_score = min(100, max(0, 
                (status["repository_stats"]["total_commits"] / 10) * 20 +  # Commit history
                (len(authors) / 3) * 20 +  # Author diversity
                (commits_per_day * 10) * 20 +  # Activity level
                (40 if status["staged_files_count"] == 0 else 20)  # Clean state
            ))
            
            return create_success_response({
                "repository_path": repo_path,
                "implementation": target_service.git_implementation,
                "health_analysis": {
                    "overall_score": round(health_score, 1),
                    "commit_frequency": {
                        "commits_per_day": round(commits_per_day, 2),
                        "total_commits": status["repository_stats"]["total_commits"],
                        "recent_activity": len(recent_commits)
                    },
                    "author_analysis": {
                        "total_authors": len(authors),
                        "top_contributors": sorted(
                            authors.items(), 
                            key=lambda x: x[1]["commits"], 
                            reverse=True
                        )[:5]
                    },
                    "repository_structure": {
                        "total_branches": status["repository_stats"]["total_branches"],
                        "total_tags": status["repository_stats"]["total_tags"],
                        "current_branch": status["current_branch"]
                    },
                    "working_directory": {
                        "staged_files": status["staged_files_count"],
                        "unstaged_files": status["unstaged_files_count"],
                        "untracked_files": status["untracked_files_count"],
                        "is_clean": status["staging_clean"] and 
                                   status["unstaged_files_count"] == 0 and 
                                   status["untracked_files_count"] == 0
                    }
                }
            })
        except Exception as e:
            logger.error(f"Failed to analyze repository health: {e}")
            raise ServiceError(
                f"Failed to analyze repository health: {e}",
                service_name="analyze_repository_health",
                cause=e
            )
  • Explicit import of the analyze_repository_health tool (and other enhanced tools) into the main MCP server module, making it available for export and server initialization.
    from .server.enhanced_tools import (
        analyze_repository_health,
        get_detailed_diff_analysis,
        get_branch_analysis,
        smart_commit_suggestion,
        batch_commit_analysis,
    )
  • Input/output schema defined by function type hints (repo_path: str -> Dict[str, Any]) and comprehensive docstring describing parameters and return structure.
    def analyze_repository_health(repo_path: str) -> Dict[str, Any]:
        """
        Comprehensive repository health analysis using GitPython features.
        
        Provides detailed analysis including:
        - Repository statistics and metrics
        - Commit frequency analysis
        - Branch and tag information
        - File change patterns
        - Author contribution analysis
        
        Args:
            repo_path: Path to git repository
            
        Returns:
            Dict containing comprehensive repository analysis
        """
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'comprehensive analysis' and lists analysis components but doesn't disclose behavioral traits like whether this is a read-only operation, performance characteristics, data returned format beyond 'Dict', error conditions, or any limitations. For a tool with no annotation coverage, this leaves significant behavioral gaps.

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

Conciseness4/5

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

The description is well-structured with a clear opening statement, bulleted list of analysis components, and separate Args/Returns sections. It's appropriately sized at 7 lines. The front-loaded purpose statement earns its place, though the bulleted list could be slightly more concise. Overall efficient with minimal waste.

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

Completeness3/5

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

Given 1 parameter with 0% schema coverage and no annotations, the description provides basic purpose and parameter semantics. The output schema exists (though unspecified here), so return values needn't be detailed. However, for a comprehensive analysis tool with many sibling alternatives and no behavioral transparency, the description is minimally adequate but lacks usage guidance and deeper behavioral context that would be helpful.

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 description coverage is 0%, so the schema provides no parameter documentation. The description adds the Args section explaining 'repo_path: Path to git repository', which gives basic semantics for the single parameter. However, it doesn't specify format expectations (absolute vs relative path, existence requirements) or examples. With 1 parameter and partial documentation, this meets the baseline but doesn't fully compensate for the schema gap.

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 tool performs 'comprehensive repository health analysis using GitPython features' and lists specific analysis components like statistics, commit frequency, branch/tag info, file changes, and author contributions. This is specific (verb+resource) and distinguishes it from siblings focused on commits, messages, or status checks rather than holistic health analysis. However, it doesn't explicitly contrast with similar siblings like 'health_check' or 'get_branch_analysis'.

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. With many sibling tools for commit analysis, branch analysis, and status checks, there's no indication of when this comprehensive health analysis is preferred over more targeted tools. The description implies usage through its content but offers no explicit when/when-not instructions or named alternatives.

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/jolfr/commit-helper-mcp'

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