gitrules-mcp-server

FRAQTIV/gitrules-mcp-server

3.2

If you are the rightful owner of gitrules-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The @fraqtiv/git-rules-mcp is an MCP server designed to assist with Git rules and workflow management.

Tools
7
Resources
0
Prompts
0

Git Rules MCP Server

npm version License: MIT CI Status

Enforce Git workflow rules and prevent repository violations with AI coding assistants.

A Model Context Protocol (MCP) server that validates Git commands against configurable repository rules, providing workflow guidance and preventing common Git mistakes when working with AI coding assistants.


๐Ÿš€ What It Does

  • ๐Ÿ›ก๏ธ Branch Protection: Prevents direct commits/pushes to protected branches (main, master, etc.)
  • ๐Ÿ“‹ Workflow Validation: Validates Git commands against your repository's workflow rules
  • ๐Ÿ”„ Smart Suggestions: Provides alternative workflows when commands are blocked
  • ๐Ÿ“ Commit Standards: Enforces conventional commit message formats
  • ๐Ÿงน Repository Health: Analyzes repository compliance with workflow rules
  • ๐Ÿค– AI Integration: Works seamlessly with Claude Code, Cursor, GitHub Copilot, and other AI assistants

๐ŸŽฏ Why You Need This

The Problem

AI coding assistants can accidentally:

  • Push directly to protected branches
  • Create commits with poor messages
  • Bypass your team's Git workflows
  • Make repository management chaotic

The Solution

This MCP server acts as a gatekeeper that:

  • โœ… Validates every Git operation before execution
  • โœ… Enforces your team's workflow rules consistently
  • โœ… Guides AI assistants to follow proper Git practices
  • โœ… Prevents repository violations before they happen

๐Ÿ“ฆ Quick Install

โš ๏ธ Important: Most users will encounter permission errors with the default npm configuration. Use the Recommended Setup below to avoid issues.

๐ŸŽฏ Recommended Setup (Prevents Permission Errors)

Copy and paste this entire block into your terminal:

# Setup npm user directory and install in one go:
mkdir -p ~/.npm-global && \
npm config set prefix ~/.npm-global && \
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc && \
source ~/.zshrc && \
npm install -g @fraqtiv/git-rules-mcp && \
echo "๐ŸŽ‰ Installation complete! Testing..." && \
mcp-git-rules --test

For Bash users, replace ~/.zshrc with ~/.bashrc:

# Bash version:
mkdir -p ~/.npm-global && \
npm config set prefix ~/.npm-global && \
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc && \
source ~/.bashrc && \
npm install -g @fraqtiv/git-rules-mcp && \
echo "๐ŸŽ‰ Installation complete! Testing..." && \
mcp-git-rules --test

Expected output after running the above:

๐ŸŽ‰ Installation complete! Testing...
๐Ÿ” Testing git-rules-mcp installation...
โœ… MCP Server: Initialized successfully
โœ… Git Repository: Detected (or Not found)
โœ… Configuration: Loaded (X protected branches)
๐ŸŽ‰ Installation test passed! The MCP server is ready to use.

๐Ÿ”ง Alternative: System-Wide Install (May Need Sudo)

If you prefer system-wide installation and encounter permission errors:

# Only if you get EACCES permission errors:
sudo npm install -g @fraqtiv/git-rules-mcp

# Then test (no sudo needed for testing):
mcp-git-rules --test

๐Ÿšจ Quick Fixes for Common Issues

Still getting permission errors? Use the one-liner commands above instead of npm install -g directly.

โŒ "command not found: mcp-git-rules" after installation? You missed adding npm bin to your PATH. Fix it now:

# Quick fix (copy-paste this):
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc && source ~/.zshrc && mcp-git-rules --test

# Or for Bash:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc && source ~/.bashrc && mcp-git-rules --test

# Alternative - run with full path once:
~/.npm-global/bin/mcp-git-rules --test

Want to verify installation status?

npm list -g @fraqtiv/git-rules-mcp  # Check if installed
which mcp-git-rules                 # Check if in PATH
mcp-git-rules --help               # Show available options

โšก Quick Setup by AI Assistant

Choose your AI coding assistant for specific setup instructions:

AssistantIntegration GuideSetup Complexity
Native MCP support with workflow configurationโญโญโญ
MCP + .cursorrules integrationโญโญ
Built-in MCP support with direct server configurationโญโญ
Bridge extensions + git hooksโญโญโญโญ
Plugin system integrationโญโญโญ

๐Ÿ’ก Quick Start: Most users should start with the for the smoothest experience.


๐Ÿ› ๏ธ Basic Configuration

Create .gitrules.yaml in your repository root:

# Protected branches that cannot be directly modified
protectedBranches:
  - main
  - master

# Integration branch where features are merged first  
integrationBranch: dev

# Branch naming conventions
featureBranchPrefix: feature/
hotfixBranchPrefix: hotfix/

# Workflow enforcement
requireCleanWorkingTree: true
allowDirectPush: false
enforceCommitMessageFormat: true

# Conventional commit types
allowedCommitTypes:
  - feat      # New features
  - fix       # Bug fixes  
  - docs      # Documentation
  - style     # Formatting
  - refactor  # Code restructuring
  - test      # Adding tests
  - chore     # Maintenance

๐ŸŽฎ How It Works

1. Repository Status Check

# The MCP server analyzes your repository
Current Branch: feature/user-auth
Status: Clean โœ…
Protected: No โœ…
Integration Branch: dev

2. Command Validation

# Before: git push origin main
โŒ BLOCKED: Direct push to protected branch 'main'
๐Ÿ’ก Suggestion: Merge to 'dev' first, then create PR to main

# Proper workflow:
โœ… git checkout dev
โœ… git merge feature/user-auth  
โœ… git push origin dev
โœ… Create PR: dev โ†’ main

3. Workflow Guidance

# AI Assistant asks: "How do I start a new feature?"
# MCP Server responds:

๐Ÿš€ Starting New Feature:
1. git checkout dev
2. git pull origin dev  
3. git checkout -b feature/your-feature-name

โœ… Ready to begin development!

๐Ÿ”ง Available Tools

The MCP server provides these tools to AI assistants:

ToolPurposeExample Use
get_repository_statusCheck branch, cleanliness, protection statusBefore any Git operation
validate_git_commandValidate if a Git command is allowedBefore push, commit, merge
suggest_workflowGet step-by-step workflow guidanceStarting features, merging, releases
analyze_repository_complianceFull repository health checkRegular compliance audits

๐ŸŒŸ Key Features

Branch Protection

  • Protected Branches: Prevent direct commits to main/master
  • Integration Workflow: Enforce proper merge patterns
  • Clean Working Tree: Require clean state for protected operations

Commit Standards

  • Conventional Commits: Enforce type: description format
  • Type Validation: Only allow configured commit types
  • Message Quality: Ensure meaningful commit messages

Workflow Automation

  • Smart Suggestions: Alternative paths when commands blocked
  • Step-by-Step Guidance: Complete workflow instructions
  • Safety Checks: Validate before every operation

AI Assistant Integration

  • Universal Compatibility: Works with any MCP-enabled AI assistant
  • Real-time Validation: Immediate feedback on Git operations
  • Educational: Teaches proper Git workflows

๐Ÿ“– Example Workflows

Protected Branch Workflow

main (protected) โ† PR โ† dev โ† merge โ† feature/new-auth
                                   โ†‘
                              You work here

Feature Development Flow

# 1. Start new feature (validated by MCP)
git checkout dev
git pull origin dev
git checkout -b feature/user-authentication

# 2. Development work
git add .
git commit -m "feat: add user login form"
git commit -m "test: add login form tests"

# 3. Feature complete (validated by MCP)  
git checkout dev
git merge feature/user-authentication
git push origin dev

# 4. Production release
# Create PR: dev โ†’ main (only way to update main)

๐Ÿ—๏ธ Advanced Usage

Custom Rules

# .gitrules.yaml - Advanced configuration
protectedBranches:
  - main
  - staging
  - release/*

workflowRules:
  requirePullRequest: true
  requireCodeReview: true
  requireStatusChecks: true
  
branchNaming:
  feature: "feature/JIRA-123-description"
  hotfix: "hotfix/JIRA-456-critical-fix"
  
commitRules:
  maxLength: 72
  requireJiraTicket: true
  allowedScopes: ["auth", "api", "ui", "docs"]

CI/CD Integration

# .github/workflows/validate-git-rules.yml
name: Git Rules Validation
on: [push, pull_request]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup npm global directory
        run: |
          mkdir -p ~/.npm-global
          npm config set prefix ~/.npm-global
          echo "$HOME/.npm-global/bin" >> $GITHUB_PATH
      - run: npm install -g @fraqtiv/git-rules-mcp
      - run: mcp-git-rules --test

๐Ÿ” Advanced Troubleshooting

Installation Issues

โš ๏ธ Most Common Problems: See the Quick Install section above for proactive solutions.

Advanced PATH Configuration

# For different shells:
echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.bashrc   # Bash
echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.zshrc    # Zsh
echo 'set -gx PATH (npm config get prefix)/bin $PATH' >> ~/.config/fish/config.fish  # Fish

# Check current npm prefix:
npm config get prefix

# Check if PATH includes npm global bin:
echo $PATH | grep -q "$(npm config get prefix)/bin" && echo "โœ… PATH configured" || echo "โŒ PATH missing npm global bin"

Package Installation Issues

# Check installation
npm list -g @fraqtiv/git-rules-mcp

# Reinstall if needed
npm install -g @fraqtiv/git-rules-mcp

Rules Not Being Enforced

  • See
  • Ensure project has proper workflow documentation
  • AI assistants need explicit instruction to use MCP tools

Configuration Not Loading

# Test configuration
mcp-git-rules --config-check

# Validate YAML syntax
mcp-git-rules --validate-config .gitrules.yaml

๐Ÿค Contributing

We welcome contributions! Please see our for details.

Development Setup

git clone https://github.com/FRAQTIV/gitrules-mcp-server.git
cd gitrules-mcp-server
npm install
npm run build
npm test

๐Ÿ“‹ Roadmap

  • Web Dashboard - Visual repository compliance dashboard
  • Team Analytics - Workflow compliance metrics and reporting
  • Custom Hooks - Extensible validation system
  • Integration Templates - Pre-built configurations for popular workflows
  • Enterprise Features - Advanced compliance and audit logging

๐Ÿ“„ License

MIT License - see file for details.


๐Ÿ™‹ Support & Community


โญ Star this repo if it helps keep your Git workflow clean! โญ

Made with โค๏ธ by FRAQTIV