Skip to main content
Glama
jolfr

Commit Helper MCP

by jolfr

preview_git_commit

Preview git commit operations in dry-run mode to validate messages and review files before committing changes to a repository.

Instructions

Preview git commit operation without executing (dry-run mode).

Args: message: Commit message to preview repo_path: Path to git repository stage_all: Whether to stage all changes before commit (not implemented yet) sign_off: Whether to add sign-off to commit (default: True)

Returns: Dict containing: - message: The commit message - is_valid: Whether message passes validation - files_to_commit: List of files that would be committed - dry_run: Always True for this tool - repository_status: Current repository state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageYes
repo_pathYes
stage_allNo
sign_offNo

Implementation Reference

  • The main handler function for the 'preview_git_commit' MCP tool. It performs a dry-run preview of a git commit operation using the CommitzenService, including validation and status reporting.
    @mcp.tool()
    @handle_errors(log_errors=True)
    def preview_git_commit(
        message: str, repo_path: str, stage_all: bool = False, sign_off: bool = True
    ) -> Dict[str, Any]:
        """
        Preview git commit operation without executing (dry-run mode).
    
        Args:
            message: Commit message to preview
            repo_path: Path to git repository
            stage_all: Whether to stage all changes before commit (not implemented yet)
            sign_off: Whether to add sign-off to commit (default: True)
    
        Returns:
            Dict containing:
            - message: The commit message
            - is_valid: Whether message passes validation
            - files_to_commit: List of files that would be committed
            - dry_run: Always True for this tool
            - repository_status: Current repository state
        """
        # For backward compatibility with tests expecting git_enabled field
        try:
            # Initialize service for the specified repository
            try:
                target_service = CommitzenService(repo_path=repo_path)
            except Exception as e:
                return {
                    "git_enabled": False,
                    "error": f"Failed to initialize service for repository '{repo_path}': {e}",
                    "message": message,
                    "dry_run": True,
                    "repository_path": repo_path,
                }
    
            if not target_service.git_enabled:
                return {
                    "git_enabled": False,
                    "error": "Git operations not available - not in a git repository",
                    "message": message,
                    "dry_run": True,
                    "repository_path": repo_path,
                }
    
            # Get preview from service
            preview_result = target_service.preview_commit_operation(
                message, sign_off=sign_off
            )
    
            if "error" in preview_result:
                return {
                    "git_enabled": True,
                    "error": preview_result["error"],
                    "message": message,
                    "dry_run": True,
                    "repository_path": repo_path,
                }
    
            git_preview = preview_result.get("git_preview", {})
    
            return {
                "git_enabled": True,
                "message": message,
                "is_valid": preview_result.get("is_valid", False),
                "files_to_commit": git_preview.get("staged_files", []),
                "staged_files_count": git_preview.get("staged_files_count", 0),
                "would_execute": git_preview.get("would_execute", False),
                "dry_run": True,
                "repository_status": git_preview,
                "repository_path": git_preview.get("repository_path"),
                "success": True,
            }
    
        except Exception as e:
            logger.error(f"Failed to preview git commit: {e}")
            return {
                "git_enabled": False,
                "error": str(e),
                "message": message,
                "dry_run": True,
                "repository_path": repo_path,
                "success": False,
            }
  • Import of git_tools module in mcp_server.py, which registers the preview_git_commit tool via its @mcp.tool() decorator.
    from .server import git_tools
  • Explicit export of preview_git_commit in __all__ list in mcp_server.py for backward compatibility.
    "preview_git_commit",
    "execute_git_commit",

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