An MCP (Model Context Protocol) server for Git operations, built with Kotlin and Ktor.
This MCP server provides tools to perform Git operations through the MCP protocol via HTTP REST API or STDIO:
- git_status - Shows the repository state
- git_diff - Shows changes made (with option for specific file and staged)
- git_commit - Creates commits with messages
- git_log - Views commit history
- git_branch - Lists/creates/deletes branches
- git_checkout - Restores files or switches branches
- git_add - Adds files to staging area
- git_push - Pushes commits to remote repository
- Java 17 or higher
- Git installed on the system
- Clone the repository
- Make the script executable:
chmod +x mcp-git-server.shStarts the HTTP server on port 8080:
./gradlew runOr using the script:
./mcp-git-server.sh httpThe server will be available at http://localhost:8080
Endpoints:
GET /- Server informationGET /health- Health checkPOST /mcp- JSON-RPC endpoint for MCP commands
To use with Claude Desktop via stdin/stdout:
./mcp-git-server.sh stdioAdd to your Claude Desktop configuration file (claude_desktop_config.json):
{
"mcpServers": {
"git": {
"command": "/full/path/to/mcp-git-server.sh",
"args": ["stdio"],
"env": {
"GIT_WORKING_DIR": "/path/to/repository"
}
}
}
}GIT_WORKING_DIR: Git repository directory (default: current directory)MCP_PORT: HTTP server port (default: 8080)MCP_HOST: HTTP server host (default: 0.0.0.0)
# Health check
curl http://localhost:8080/health
# View repository status
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "git_status",
"arguments": {}
}
}'echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"git_status","arguments":{}}}' | ./mcp-git-server.sh stdio{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "git_status",
"arguments": {}
}
}{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "git_diff",
"arguments": {
"file_path": "src/Main.kt",
"staged": false
}
}
}{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "git_commit",
"arguments": {
"message": "feat: add new feature",
"add_all": true
}
}
}{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "git_log",
"arguments": {
"max_count": 5,
"oneline": true
}
}
}{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "git_branch",
"arguments": {
"action": "list"
}
}
}{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "git_branch",
"arguments": {
"action": "create",
"branch_name": "feature/new-feature"
}
}
}{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "git_checkout",
"arguments": {
"target": "main",
"create_new": false
}
}
}{
"jsonrpc": "2.0",
"id": 8,
"method": "tools/call",
"params": {
"name": "git_add",
"arguments": {
"files": "."
}
}
}{
"jsonrpc": "2.0",
"id": 9,
"method": "tools/call",
"params": {
"name": "git_push",
"arguments": {
"remote": "origin",
"branch": "main",
"set_upstream": true,
"force": false
}
}
}./gradlew build./gradlew test# Terminal 1: Start server
./gradlew run
# Terminal 2: Run HTTP tests
./test-http.sh./mcp-git-server.sh --rebuildmcp-git-server/
├── build.gradle.kts # Gradle configuration
├── settings.gradle.kts # Project settings
├── mcp-git-server.sh # Execution script
├── test-http.sh # HTTP tests
├── test-manual.sh # STDIO tests
├── README.md # Documentation
├── TESTING.md # Testing guide
└── src/
├── main/
│ └── kotlin/
│ └── com/
│ └── mcp/
│ └── git/
│ ├── Main.kt # Entry point
│ ├── KtorServer.kt # Ktor HTTP server
│ ├── McpServer.kt # MCP server (logic)
│ ├── McpProtocol.kt # Protocol structures
│ └── GitOperations.kt # Git operations
└── test/
└── kotlin/
└── com/
└── mcp/
└── git/
├── GitOperationsTest.kt # Git operations tests
├── McpServerTest.kt # MCP server tests
└── KtorServerTest.kt # HTTP tests
This server implements the Model Context Protocol version 2024-11-05.
- TESTING.md - Comprehensive testing guide with examples
- HTTP-MIGRATION.md - HTTP migration and dual-mode support documentation
- http-usage-example.md - HTTP usage examples and API reference
MIT