A Model Context Protocol (MCP) tool server that helps LLM agents manage git repositories and pre-commit hooks automatically.
This MCP server provides tools to:
- 🔍 Detect project type (Python, JavaScript, or TypeScript)
- 📦 Check if a directory is a git repository
- 🪝 Verify if pre-commit hooks are installed
- 🚀 Initialize git repositories automatically
- ⚙️ Set up pre-commit hooks based on project type
- Node.js 18 or higher
- Git installed on your system
pre-commitinstalled (for hook installation)- For macOS:
brew install pre-commit - For Python users:
pip install pre-commit
- For macOS:
npm install -g mcp-pre-commit- Clone or download this repository
- Install dependencies:
npm install- Build the TypeScript code:
npm run buildStart the MCP server:
npm startOr run in development mode with auto-rebuild:
npm run watchAdd this server to your MCP client configuration.
macOS/Linux: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"pre-commit-manager": {
"command": "mcp-pre-commit"
}
}
}Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"pre-commit-manager": {
"command": "mcp-pre-commit"
}
}
}{
"mcpServers": {
"pre-commit-manager": {
"command": "node",
"args": ["/absolute/path/to/mcp-pre-commit/dist/index.js"]
}
}
}Refer to your MCP client's documentation for configuration instructions. The command is mcp-pre-commit (for npm installation) or node /path/to/dist/index.js (for source installation).
Analyzes a repository and returns its setup status.
Parameters:
repo_path(optional): Path to the repository (defaults to current directory)
Returns:
{
"repository_path": "/path/to/repo",
"project_type": "python",
"is_git_repository": true,
"has_precommit_hooks": false,
"status": "⚠️ Git repository exists but pre-commit hooks are not installed"
}Example usage in LLM conversation:
Check the project setup for /Users/john/my-project
Initializes git repository and sets up pre-commit hooks based on detected project type.
Parameters:
repo_path(optional): Path to the repository (defaults to current directory)force_project_type(optional): Force specific project type (python,javascript, ortypescript)
Returns: Status messages about git initialization and pre-commit hook setup.
Example usage in LLM conversation:
Set up git and pre-commit hooks for /Users/john/my-project
- Trailing whitespace removal
- End-of-file fixer
- YAML, JSON, TOML checkers
- Black code formatter
- Flake8 linter
- isort import sorter
- Trailing whitespace removal
- End-of-file fixer
- YAML, JSON checkers
- ESLint with TypeScript support
- Prettier code formatter
- Basic pre-commit hooks (whitespace, file fixes, YAML/JSON validation)
mcp-pre-commit/
├── src/
│ └── index.ts # Main server implementation
├── dist/ # Compiled JavaScript (generated)
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
npm run build- Compile TypeScript to JavaScriptnpm run dev- Build and run oncenpm run watch- Watch mode for development
-
Project Type Detection: Scans for common configuration files:
- Python:
setup.py,pyproject.toml,requirements.txt, etc. - TypeScript:
tsconfig.json - JavaScript:
package.json
- Python:
-
Git Repository Check: Uses
git rev-parse --is-inside-work-treeto verify git status -
Pre-commit Hook Detection: Checks for:
.pre-commit-config.yamlconfiguration file- Actual hook file in
.git/hooks/pre-commit
-
Automatic Setup:
- Initializes git if needed (
git init) - Creates appropriate
.pre-commit-config.yamlbased on project type - Runs
pre-commit installto activate hooks
- Initializes git if needed (
The server provides clear error messages for common issues:
- Missing
pre-commitinstallation - Permission errors
- Invalid repository paths
- Undetectable project types (use
force_project_typeparameter)
Contributions are welcome! Please see CONTRIBUTING.md for details on:
- Reporting bugs
- Suggesting enhancements
- Submitting pull requests
- Code style guidelines
Feel free to extend this server with additional features:
- Support for more project types (Go, Rust, etc.)
- Custom hook configurations
- Additional git operations
- Pre-commit hook testing
See CHANGELOG.md for a list of changes in each version.
If you encounter any issues or have questions:
- Open an issue on GitHub Issues
- Check existing issues for solutions
- Review the FAQ section
MIT - see LICENSE file for details