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.
- ๐ก๏ธ 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
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
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
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.
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
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
Choose your AI coding assistant for specific setup instructions:
Assistant | Integration Guide | Setup Complexity |
---|---|---|
Claude Code | Native MCP support with workflow configuration | โญโญโญ |
Cursor | MCP + .cursorrules integration | โญโญ |
Warp Terminal | Built-in MCP support with direct server configuration | โญโญ |
GitHub Copilot | Bridge extensions + git hooks | โญโญโญโญ |
KILOCODE | Plugin system integration | โญโญโญ |
๐ก Quick Start: Most users should start with the Claude Code guide for the smoothest experience.
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
# The MCP server analyzes your repository
Current Branch: feature/user-auth
Status: Clean โ
Protected: No โ
Integration Branch: dev
# 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
# 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!
The MCP server provides these tools to AI assistants:
Tool | Purpose | Example Use |
---|---|---|
get_repository_status |
Check branch, cleanliness, protection status | Before any Git operation |
validate_git_command |
Validate if a Git command is allowed | Before push , commit , merge |
suggest_workflow |
Get step-by-step workflow guidance | Starting features, merging, releases |
analyze_repository_compliance |
Full repository health check | Regular compliance audits |
- Protected Branches: Prevent direct commits to main/master
- Integration Workflow: Enforce proper merge patterns
- Clean Working Tree: Require clean state for protected operations
- Conventional Commits: Enforce
type: description
format - Type Validation: Only allow configured commit types
- Message Quality: Ensure meaningful commit messages
- Smart Suggestions: Alternative paths when commands blocked
- Step-by-Step Guidance: Complete workflow instructions
- Safety Checks: Validate before every operation
- Universal Compatibility: Works with any MCP-enabled AI assistant
- Real-time Validation: Immediate feedback on Git operations
- Educational: Teaches proper Git workflows
main (protected) โ PR โ dev โ merge โ feature/new-auth
โ
You work here
# 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)
# .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"]
# .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 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 Claude Code Caveats
- 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
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/FRAQTIV/gitrules-mcp-server.git
cd gitrules-mcp-server
npm install
npm run build
npm test
- 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
MIT License - see LICENSE file for details.
- ๐ Documentation: Full docs and integration guides
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Website: https://fraqtiv.github.io/gitrules-mcp-server
โญ Star this repo if it helps keep your Git workflow clean! โญ
Made with โค๏ธ by FRAQTIV