Skip to main content
Glama
jolfr

Commit Helper MCP

by jolfr

get_detailed_diff_analysis

Analyze detailed differences between working directory and specific commits to track file changes, line modifications, and change classifications for Git repositories.

Instructions

Get detailed diff analysis between working directory and specified commit.

Uses GitPython to provide:

  • File-by-file change analysis

  • Line-level insertion/deletion counts

  • Change type classification (added, modified, deleted, renamed)

  • Binary file detection

  • Optional diff content inclusion

Args: repo_path: Path to git repository compare_with: Commit/branch to compare with (default: HEAD) include_content: Whether to include actual diff content

Returns: Dict containing detailed diff analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes
compare_withNoHEAD
include_contentNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for 'get_detailed_diff_analysis' tool. Decorated with @mcp.tool(), it initializes CommitzenService, uses GitPython to get staged/unstaged diffs, analyzes each file's changes (insertions/deletions, binary detection, optional content), computes totals, and returns structured analysis.
    def get_detailed_diff_analysis(
        repo_path: str,
        compare_with: str = "HEAD",
        include_content: bool = False
    ) -> Dict[str, Any]:
        """
        Get detailed diff analysis between working directory and specified commit.
        
        Uses GitPython to provide:
        - File-by-file change analysis
        - Line-level insertion/deletion counts
        - Change type classification (added, modified, deleted, renamed)
        - Binary file detection
        - Optional diff content inclusion
        
        Args:
            repo_path: Path to git repository
            compare_with: Commit/branch to compare with (default: HEAD)
            include_content: Whether to include actual diff content
            
        Returns:
            Dict containing detailed diff 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"Failed to initialize service for repository '{repo_path}': {e}",
                "repository_path": repo_path
            }
        
        if not target_service.git_enabled:
            # For backward compatibility with tests
            return {
                "success": False,
                "error": "Enhanced diff analysis requires GitPython",
                "repository_path": repo_path
            }
        
        try:
            # Get staged and unstaged diffs
            repo = target_service.git_service.repo
            staged_diff = repo.index.diff(compare_with)
            unstaged_diff = repo.index.diff(None)
            
            def analyze_diff_items(diff_items, diff_type):
                analysis = []
                total_insertions = 0
                total_deletions = 0
                
                for item in diff_items:
                    try:
                        # Get diff statistics
                        if item.diff:
                            diff_text = item.diff.decode('utf-8', errors='ignore')
                            insertions = diff_text.count('\n+') - diff_text.count('\n+++')
                            deletions = diff_text.count('\n-') - diff_text.count('\n---')
                        else:
                            insertions = deletions = 0
                        
                        file_analysis = {
                            "file": item.a_path or item.b_path,
                            "change_type": item.change_type,
                            "insertions": max(0, insertions),
                            "deletions": max(0, deletions),
                            "is_binary": item.diff == b'',
                            "old_file": item.a_path,
                            "new_file": item.b_path,
                            "diff_type": diff_type
                        }
                        
                        if include_content and not file_analysis["is_binary"]:
                            file_analysis["diff_content"] = diff_text
                        
                        analysis.append(file_analysis)
                        total_insertions += max(0, insertions)
                        total_deletions += max(0, deletions)
                        
                    except Exception as e:
                        logger.warning(f"Could not analyze diff for {item.a_path}: {e}")
                        analysis.append({
                            "file": item.a_path or item.b_path,
                            "change_type": item.change_type,
                            "error": str(e),
                            "diff_type": diff_type
                        })
                
                return analysis, total_insertions, total_deletions
            
            staged_analysis, staged_insertions, staged_deletions = analyze_diff_items(staged_diff, "staged")
            unstaged_analysis, unstaged_insertions, unstaged_deletions = analyze_diff_items(unstaged_diff, "unstaged")
            
            return create_success_response({
                "repository_path": repo_path,
                "compare_with": compare_with,
                "implementation": target_service.git_implementation,
                "diff_analysis": {
                    "staged_changes": {
                        "files": staged_analysis,
                        "file_count": len(staged_analysis),
                        "total_insertions": staged_insertions,
                        "total_deletions": staged_deletions,
                        "total_changes": staged_insertions + staged_deletions
                    },
                    "unstaged_changes": {
                        "files": unstaged_analysis,
                        "file_count": len(unstaged_analysis),
                        "total_insertions": unstaged_insertions,
                        "total_deletions": unstaged_deletions,
                        "total_changes": unstaged_insertions + unstaged_deletions
                    },
                    "summary": {
                        "total_files_changed": len(staged_analysis) + len(unstaged_analysis),
                        "total_insertions": staged_insertions + unstaged_insertions,
                        "total_deletions": staged_deletions + unstaged_deletions,
                        "has_staged_changes": len(staged_analysis) > 0,
                        "has_unstaged_changes": len(unstaged_analysis) > 0
                    }
                }
            })
        except Exception as e:
            logger.error(f"Failed to get detailed diff analysis: {e}")
            raise ServiceError(
                f"Failed to get detailed diff analysis: {e}",
                service_name="get_detailed_diff_analysis",
                cause=e
            )
  • Import statement in the main MCP server file that registers the tool. Importing the @mcp.tool()-decorated function makes it available to the MCP server.
    from .server.enhanced_tools import (
        analyze_repository_health,
        get_detailed_diff_analysis,
        get_branch_analysis,
        smart_commit_suggestion,
        batch_commit_analysis,
    )
  • The tool is explicitly listed in __all__ for export and backward compatibility.
    "get_detailed_diff_analysis",
    "get_branch_analysis",
    "smart_commit_suggestion",
    "batch_commit_analysis",
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing behavioral traits: it specifies the use of GitPython, lists analysis features (file-by-file changes, line-level counts, etc.), and mentions optional diff content inclusion. However, it doesn't cover aspects like error handling, performance, or authentication needs, which could be relevant for a tool with 3 parameters.

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 appropriately sized and front-loaded, starting with the core purpose, followed by a bulleted list of features and clear parameter/return sections. Every sentence adds value without redundancy, making it efficient and well-structured.

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 complexity (3 parameters, no annotations, but with an output schema), the description is mostly complete: it covers purpose, features, parameters, and returns. However, it lacks details on error cases or example usage, which could enhance completeness for a tool with moderate complexity.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaningful semantics for all 3 parameters: 'repo_path' as the repository path, 'compare_with' as the commit/branch to compare with (including default), and 'include_content' as a boolean for diff content inclusion. This goes beyond the schema's basic titles, though it could provide more detail on format or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/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 with specific verbs ('get detailed diff analysis') and resources ('between working directory and specified commit'), distinguishing it from siblings like 'get_git_status' or 'get_branch_analysis' by focusing on detailed diff analysis rather than status or branch-specific analysis.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for detailed diff analysis but does not explicitly state when to use this tool versus alternatives like 'get_enhanced_git_status' or 'preview_git_commit'. It lacks explicit guidance on exclusions or prerequisites, leaving usage context somewhat vague.

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