Skip to main content
Glama
jolfr

Commit Helper MCP

by jolfr

generate_commit_message

Generate conventional commit messages with validation using specified parameters like type, subject, scope, and breaking changes for version control workflows.

Instructions

Generate a commit message with validation using provided parameters.

Args: type: The commit type (e.g., 'feat', 'fix', 'docs') subject: The commit subject/description body: Optional commit body with detailed description scope: Optional scope of the change breaking: Whether this is a breaking change footer: Optional footer (e.g., issue references) include_git_preview: Whether to include git preview in response

Returns: Dict containing the generated message and validation status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYes
subjectYes
bodyNo
scopeNo
breakingNo
footerNo
include_git_previewNo

Implementation Reference

  • The core handler function for the 'generate_commit_message' MCP tool. Decorated with @mcp.tool() for registration and implements the logic: builds answers dict, generates message via service, validates it, optionally adds git preview, and returns structured response.
    @mcp.tool()
    @handle_errors(log_errors=True)
    def generate_commit_message(
        type: str,
        subject: str,
        body: Optional[str] = None,
        scope: Optional[str] = None,
        breaking: Optional[bool] = False,
        footer: Optional[str] = None,
        include_git_preview: bool = False,
    ) -> Dict[str, Any]:
        """
        Generate a commit message with validation using provided parameters.
    
        Args:
            type: The commit type (e.g., 'feat', 'fix', 'docs')
            subject: The commit subject/description
            body: Optional commit body with detailed description
            scope: Optional scope of the change
            breaking: Whether this is a breaking change
            footer: Optional footer (e.g., issue references)
            include_git_preview: Whether to include git preview in response
    
        Returns:
            Dict containing the generated message and validation status
        """
        # Build answers dictionary with all fields (adapter will handle mapping)
        answers = {
            "type": type,
            "prefix": type,  # Some plugins expect 'prefix'
            "subject": subject,
            "body": body or "",
            "scope": scope or "",
            "breaking": breaking or False,
            "is_breaking_change": breaking or False,  # Some plugins expect this name
            "footer": footer or "",
        }
    
        # Generate the message
        message = service.generate_message(answers)
    
        # Validate the generated message
        is_valid = service.validate_message(message)
    
        if not is_valid:
            raise create_validation_error(
                "Invalid commit message format",
                validation_type="commit_message",
                invalid_value=f"{type}: {subject}",
            )
    
        result = {
            "message": message,
            "is_valid": is_valid,
            "parameters": {
                "type": type,
                "subject": subject,
                "body": body,
                "scope": scope,
                "breaking": breaking,
                "footer": footer,
            },
        }
    
        # Add git preview if requested and available
        if include_git_preview and service.git_enabled:
            try:
                # Import preview function from git_tools
                from .git_tools import preview_git_commit
    
                # Use the current service's repository path for preview
                repo_path = (
                    str(service.git_service.repo_path) if service.git_service else None
                )
                if repo_path:
                    git_preview = preview_git_commit(message, repo_path)
                    result["git_preview"] = git_preview
                else:
                    result["git_preview_error"] = (
                        "No repository path available for git preview"
                    )
            except Exception as e:
                logger.warning(f"Failed to include git preview: {e}")
                result["git_preview_error"] = str(e)
        elif include_git_preview and not service.git_enabled:
            result["git_preview_error"] = (
                "Git operations not available - not in a git repository"
            )
    
        return create_success_response(result)
  • Import statement in the main MCP server file that loads the generate_commit_message tool (along with other message tools), ensuring it is registered and available in the server.
    from .server.message_tools import (
        generate_commit_message,
        create_commit_message,
        validate_commit_message,
        get_commit_types,
    )

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