Skip to main content
Glama
jolfr

Commit Helper MCP

by jolfr

execute_git_commit

Execute Git commits with safety checks and user approval, requiring explicit confirmation to perform actual commits while supporting conventional commit messages.

Instructions

Execute actual git commit with safety checks and user approval.

SAFETY: Requires force_execute=True to perform actual commit.

Args: message: Commit message to use 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) force_execute: Must be True to execute actual commit (safety flag)

Returns: Dict containing: - success: Whether commit was successful - message: The commit message used - executed: Whether commit was actually executed - error: Error message (if failed) - dry_run: False if actually executed, True if preview only

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageYes
repo_pathYes
stage_allNo
sign_offNo
force_executeNo

Implementation Reference

  • The core handler function for the 'execute_git_commit' MCP tool. Decorated with @mcp.tool(), it implements the git commit logic using CommitzenService, with safety requiring 'force_execute=True' to actually commit. Handles repository initialization, git checks, and error responses.
    @mcp.tool()
    def execute_git_commit(
        message: str,
        repo_path: str,
        stage_all: bool = False,
        sign_off: bool = True,
        force_execute: bool = False,
    ) -> Dict[str, Any]:
        """
        Execute actual git commit with safety checks and user approval.
    
        SAFETY: Requires force_execute=True to perform actual commit.
    
        Args:
            message: Commit message to use
            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)
            force_execute: Must be True to execute actual commit (safety flag)
    
        Returns:
            Dict containing:
            - success: Whether commit was successful
            - message: The commit message used
            - executed: Whether commit was actually executed
            - error: Error message (if failed)
            - dry_run: False if actually executed, True if preview only
        """
        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}",
                    "success": False,
                    "executed": False,
                    "message": message,
                    "repository_path": repo_path,
                }
    
            if not target_service.git_enabled:
                return {
                    "git_enabled": False,
                    "error": "Git operations not available - not in a git repository",
                    "success": False,
                    "executed": False,
                    "message": message,
                    "repository_path": repo_path,
                }
    
            # Execute commit with safety checks
            result = target_service.execute_commit_operation(
                message=message, force_execute=force_execute, sign_off=sign_off
            )
    
            # Add dry_run flag based on execution
            result["dry_run"] = not result.get("executed", False)
            result["git_enabled"] = True
            result["repository_path"] = repo_path
    
            return result
    
        except Exception as e:
            logger.error(f"Failed to execute git commit: {e}")
            return {
                "git_enabled": False,
                "error": str(e),
                "success": False,
                "executed": False,
                "message": message,
                "dry_run": True,
                "repository_path": repo_path,
            }
  • Registration via re-export/import of the execute_git_commit function from git_tools.py in the main mcp_server.py, ensuring it's available in the server's namespace after module imports trigger @mcp.tool() decorators.
    from .server.git_tools import (
        get_git_implementation_info,
        get_enhanced_git_status,
        get_git_status,
        preview_git_commit,
        execute_git_commit,
        generate_and_commit,
        validate_commit_readiness,
        stage_files_and_commit,
    )
  • Internal usage of execute_git_commit within the generate_and_commit tool, demonstrating how it's integrated into higher-level workflows.
    commit_result = execute_git_commit(
        message=generated_message,
        repo_path=repo_path,
        sign_off=sign_off,
        force_execute=True,  # Since user explicitly set preview_only=False
    )
  • Usage of execute_git_commit in the multi-step commit_workflow_step tool during the 'execute' phase.
    commit_result = execute_git_commit(
        message=workflow_data["generated_message"],
        repo_path=repo_path,
        sign_off=workflow_data.get("sign_off", True),  # Default to True for signoff
        force_execute=True,
    )

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