A Model Context Protocol (MCP) server that provides Git repository analysis and GitHub data retrieval capabilities. This server enables AI assistants to interact with Git repositories, retrieve commit histories, analyze file changes, and synchronize data with MongoDB for enhanced repository insights.
- Commit Message Logs: Retrieve commit messages for a specified number of days
- Patch Logs: Get detailed patch information for specific files
- Directory Listings: Explore project structure and file listings
- File Content: Access current content of any file in the repository
- Repository Data Sync: Batch processing to sync GitHub repository data to MongoDB
- Content Retrieval: Download and store repository content
- Commit Diff Analysis: Retrieve detailed commit diffs via GitHub REST API
- Rate Limit Handling: Intelligent pagination and API rate limit management
- MongoDB integration for persistent data storage
- Collections for commits, content, and diffs
- Base64 content decoding for file content storage
- Node.js (v22)
- Docker and Docker Compose
- MongoDB (provided via Docker Compose)
- GitHub Personal Access Token (for GitHub API features)
-
Clone the repository
git clone <repository-url> cd git-mcp-server
-
Install dependencies
npm install
-
Set up environment variables
Create a.env
file in the root directory:GITHUB_TOKEN=your_github_personal_access_token_here
-
Start MongoDB
Start your mongodb locally, the default connection string has no authentication on it. -
Build the project
npm run build
-
Install as an MCP server using the following file:
{
"servers": {
"git-mcp-server": {
"type": "stdio",
"command": "node",
"args": [
"C:\\Users\\evano\\WebstormProjects\\git-mcp-server\\build\\src\\index.js"
]
},
"ESLint": {
"type": "stdio",
"command": "npx",
"args": [
"@eslint/mcp@latest"
]
}
}
}
The server implements the Model Context Protocol and can be used with compatible AI assistants. It exposes the following tools:
get-commit-message-logs
: Get commit messages for the last N daysget-commit-patch-logs
: Get patch logs for a specific fileget-directory-filenames
: List files in a directoryget-file-content
: Get current content of a file
The project includes several CLI runners for manual operations. This allows for easier testing during development:
# Get commit messages
npm run git-message
# Get patch logs
npm run git-patch
# Get directory listings
npm run git-directory
# Get file content
npm run git-file-content
# Sync repository metadata
npm run batch-processing
# Sync repository content
npm run batch-processing-content
# Sync commit diffs
npm run batch-processing-commit-diff
src/
├── index.ts # Main MCP server entry point
├── git/ # Git-related operations
│ ├── git-message-logs.ts # Commit message retrieval
│ ├── git-patch-logs.ts # Patch log analysis
│ ├── git-directory-logs.ts # Directory listing
│ ├── git-file-content.ts # File content retrieval
│ └── *-runner.ts # CLI runners for manual execution
└── batch-processing/ # GitHub API integration
├── github-retrieval.ts # Repository data sync
├── github-retrieval-content.ts # Content sync
├── github-retrieval-commit-diff.ts # Commit diff sync
└── *-runner.ts # CLI runners for batch operations
- commits: Repository commit metadata
- content: File content from repositories (base64 decoded)
- diffs: Detailed commit diff information
The project uses Docker Compose to set up MongoDB with Mongo Express for database management:
- MongoDB:
localhost:27017
- Mongo Express:
localhost:8081
- Username:
mongoexpressuser
- Password:
mongoexpresspass
- Username:
- Requires a GitHub Personal Access Token with appropriate repository permissions
- Implements rate limiting to stay within GitHub API limits (5000 requests/hour)
- Supports pagination for large datasets
The project is written in TypeScript with strict type checking enabled.
npm run build
This compiles TypeScript to JavaScript and sets appropriate permissions.
- Create new modules in the appropriate directory (
git/
orbatch-processing/
) - Add corresponding runner files for CLI access
- Register new tools in
src/index.ts
if they should be exposed via MCP - Update the build scripts in
package.json
- Parameters:
number_days
(1-180) - Returns: Commit messages for the specified time period
- Parameters:
filename
(string) - Returns: Patch information for the specified file
- Parameters:
directory
(string, empty for root) - Returns: List of files and subdirectories
- Parameters:
filename
(string) - Returns: Current content of the specified file