Skip to main content
Glama
jolfr

Commit Helper MCP

by jolfr

get_branch_analysis

Analyze Git repository branches to identify relationships, merging status, commit counts, and recent activity for better project management.

Instructions

Get comprehensive branch analysis using GitPython.

Provides information about:

  • All local and remote branches

  • Branch relationships and merging status

  • Commit counts per branch

  • Last activity per branch

Args: repo_path: Path to git repository

Returns: Dict containing branch analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'get_branch_analysis' tool. Decorated with @mcp.tool(), it uses GitPython via CommitzenService to analyze local and remote branches, commit counts, last activity, and returns structured analysis data.
    @mcp.tool()
    @handle_errors(log_errors=True)
    def get_branch_analysis(repo_path: str) -> Dict[str, Any]:
        """
        Get comprehensive branch analysis using GitPython.
        
        Provides information about:
        - All local and remote branches
        - Branch relationships and merging status
        - Commit counts per branch
        - Last activity per branch
        
        Args:
            repo_path: Path to git repository
            
        Returns:
            Dict containing branch analysis
        """
        # Initialize service for the specified repository
        try:
            target_service = CommitzenService(repo_path=repo_path)
        except Exception as e:
            raise RepositoryError(
                f"Failed to initialize service for repository '{repo_path}'",
                repo_path=repo_path,
                cause=e
            )
        
        if not target_service.git_enabled:
            # For backward compatibility with tests
            return {
                "success": False,
                "error": "Branch analysis requires GitPython",
                "repository_path": repo_path
            }
        
        try:
            repo = target_service.git_service.repo
            
            # Analyze local branches
            local_branches = []
            for branch in repo.branches:
                try:
                    last_commit = branch.commit
                    commit_count = sum(1 for _ in repo.iter_commits(branch))
                    
                    local_branches.append({
                        "name": branch.name,
                        "is_current": branch == repo.active_branch,
                        "last_commit": {
                            "sha": last_commit.hexsha[:8],
                            "message": last_commit.summary,
                            "author": last_commit.author.name,
                            "date": last_commit.committed_datetime.isoformat()
                        },
                        "commit_count": commit_count
                    })
                except Exception as e:
                    logger.warning(f"Could not analyze branch {branch.name}: {e}")
            
            # Analyze remote branches
            remote_branches = []
            try:
                for remote in repo.remotes:
                    for ref in remote.refs:
                        if ref.name.endswith('/HEAD'):
                            continue
                        
                        try:
                            last_commit = ref.commit
                            remote_branches.append({
                                "name": ref.name,
                                "remote": remote.name,
                                "last_commit": {
                                    "sha": last_commit.hexsha[:8],
                                    "message": last_commit.summary,
                                    "author": last_commit.author.name,
                                    "date": last_commit.committed_datetime.isoformat()
                                }
                            })
                        except Exception as e:
                            logger.warning(f"Could not analyze remote branch {ref.name}: {e}")
            except Exception as e:
                logger.warning(f"Could not analyze remote branches: {e}")
            
            return create_success_response({
                "repository_path": repo_path,
                "implementation": target_service.git_implementation,
                "branch_analysis": {
                    "current_branch": repo.active_branch.name if repo.active_branch else "HEAD (detached)",
                    "local_branches": {
                        "branches": local_branches,
                        "count": len(local_branches)
                    },
                    "remote_branches": {
                        "branches": remote_branches,
                        "count": len(remote_branches)
                    },
                    "summary": {
                        "total_branches": len(local_branches) + len(remote_branches),
                        "local_count": len(local_branches),
                        "remote_count": len(remote_branches)
                    }
                }
            })
        except Exception as e:
            logger.error(f"Failed to get branch analysis: {e}")
            raise ServiceError(
                f"Failed to get branch analysis: {e}",
                service_name="get_branch_analysis",
                cause=e
            )
  • Import statement in the main MCP server file that brings in the get_branch_analysis handler. Since the function is decorated with @mcp.tool(), this import registers the tool with the MCP server instance.
    from .server.enhanced_tools import (
        analyze_repository_health,
        get_detailed_diff_analysis,
        get_branch_analysis,
        smart_commit_suggestion,
        batch_commit_analysis,
    )
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool provides 'comprehensive branch analysis' and lists information types, but doesn't disclose behavioral traits like whether it's read-only, potential performance impacts, error conditions, or how it handles large repositories. The description adds some context about what information is returned but lacks critical operational details.

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 well-structured and appropriately sized. It starts with a clear purpose statement, bullet-points key information provided, then separately documents args and returns. Every sentence earns its place with no redundant information.

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

Completeness4/5

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

Given the tool's moderate complexity (branch analysis), no annotations, 0% schema coverage, but with an output schema present, the description is reasonably complete. It explains what the tool does and what information it provides, and the output schema will handle return value details. However, it lacks operational context that would be helpful for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics for the single parameter: 'repo_path: Path to git repository'. With 0% schema description coverage and only one parameter, this adequately compensates by explaining what the parameter represents. However, it doesn't provide format examples or validation rules beyond the basic definition.

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's purpose: 'Get comprehensive branch analysis using GitPython' with specific details about what information is provided (local/remote branches, relationships, commit counts, last activity). It distinguishes from siblings by focusing on branch analysis rather than commits, status, or health checks, though it doesn't explicitly contrast with similar tools like 'analyze_repository_health'.

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 this tool is appropriate compared to siblings like 'get_git_status', 'analyze_repository_health', or 'get_detailed_diff_analysis', nor does it specify prerequisites or exclusions for usage.

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