About MCP Git Tools
MCP Git Tools is a Rust library and standalone MCP server for exposing repository operations to MCP clients. It covers everyday Git changes, history, remote sync, and worktree management.
Key features
- 01Repository status and branch listing
- 02Filtered commit history
- 03Stage, commit, reset, and diff
- 04Pull and push to remotes
- 05Worktree listing and management
Use cases
- 01Review repository state and commit history
- 02Stage and commit changes through an MCP client
- 03Sync a repository with its remote
- 04Create or clean up Git worktrees
MCP support
Runs as an MCP server over standard input/output and exposes Git operations as tools for MCP clients.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP Git Tools
Git tools implementation for the Model Context Protocol (MCP).
Features
This library provides a set of Git operations that can be called through the Model Context Protocol:
git_status- Get the status of a repositorygit_branches- List branch informationgit_log- Get commit history with flexible filtering options (by time, author, branch, count)git_commit- Create a new commitgit_pull- Pull changes from remotegit_push- Push changes to remotegit_diff- View file differencesgit_add- Add file contents to the staging areagit_reset- Reset the staging area or working tree to a specified stategit_worktree_list- List all worktreesgit_worktree_add- Create a new worktreegit_worktree_remove- Remove a worktreegit_worktree_prune- Prune expired worktree files
Installation
# Clone the repository
git clone https://gitcode.com/lileeei/mcp-git-tools.git
# Navigate to the directory
cd mcp-git-tools
# Build
cargo build --release
Usage
Run as a standalone server
cargo run --release --bin mcp-git-server
This starts an MCP server that interacts with clients through standard input/output.
Test with MCP Inspector
- Build the server:
cargo build --release
- Start the server:
./target/release/mcp-git-server
- Use MCP Inspector to test the tools:
- Download MCP Inspector: https://github.com/modelcontextprotocol/inspector
- Click "Add a server"
- Enter:
/path/to/mcp-git-server/target/release/mcp-git-server - Click "Add"
- Test each tool using the Inspector interface
Architecture
This project uses the modern RMCP SDK (v0.14.0) with a clean architecture:
Core Components
GitToolsHandler
- Central handler struct for all Git operations
- Implements
ServerHandlertrait from RMCP SDK - Contains methods for each Git operation
ServerHandler Implementation
get_info()- Provides server metadata and capabilitieslist_tools()- Lists all available tools with their schemascall_tool()- Routes tool calls to appropriate handler methods
Tool Implementation Pattern
Each tool is implemented as a method on GitToolsHandler:
impl GitToolsHandler {
#[tool(description = "Get the status of a git repository")]
pub async fn git_status(
&self,
repo_path: String,
) -> Result<CallToolResult> {
// Implementation
}
}
Parameter Handling
All tool parameters use derive macros for automatic schema generation:
#[derive(serde::Deserialize, schemars::JsonSchema)]
struct GitStatusParams {
repo_path: String,
}
This provides:
- Automatic JSON schema generation
- Type-safe parameter parsing
- No manual serialization/deserialization code
Transport
Uses RMCP's stdio() transport for standard input/output communication.
Tool Details
git_status
Get the status of a repository.
Parameters:
repo_path- Path to the Git repository
Returns:
{
"status": ["M file1.txt", "?? file2.txt"],
"is_clean": false
}
git_branches
List all branches.
Parameters:
repo_path- Path to the Git repository
Returns:
{
"branches": ["* main", "develop", "feature/new-feature"],
"current": "main"
}
git_log
Get commit history with flexible filtering options.
Parameters:
repo_path- Path to Git repositorymax_count- (optional) Maximum number of commits to returnbranch- (optional) Branch namesince- (optional) Start date (e.g., "2023-01-01", "1 week ago", "yesterday")until- (optional) End date (e.g., "2023-01-31", "today")author- (optional) Filter by specific author (matches name or email)
Returns:
{
"commits": [
{
"hash": "abcd1234",
"author": "User Name",
"author_date": "Mon Aug 1 10:00:00 2023 +0800",
"message_title": "Initial commit"
}
]
}
Examples:
- Get recent 10 commits:
{"repo_path": ".", "max_count": 10} - Get commits from last week:
{"repo_path": ".", "since": "1 week ago"} - Get commits by author:
{"repo_path": ".", "author": "John"} - Get commits from a time range:
{"repo_path": ".", "since": "2023-01-01", "until": "2023-12-31"}
git_commit
Create a new commit.
Parameters:
repo_path- Path to the Git repositorymessage- Commit messageall- (optional) Whether to automatically stage modified files
Returns:
{
"success": true,
"hash": "abcd1234",
"message": "feat: Add new feature",
"output": "[main abcd1234] feat: Add new feature\n 1 file changed, 10 insertions(+), 2 deletions(-)"
}
git_pull
Pull changes from remote.
Parameters:
repo_path- Path to the Git repositoryremote- (optional) Remote name, defaults to "origin"branch- (optional) Branch name
Returns:
{
"success": true,
"remote": "origin",
"output": "Updating abcd1234..efgh5678\nFast-forward\n file1.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)"
}
git_push
Push changes to remote.
Parameters:
repo_path- Path to the Git repositoryremote- (optional) Remote name, defaults to "origin"branch- (optional) Branch nameforce- (optional) Whether to force push
Returns:
{
"success": true,
"remote": "origin",
"output": "To github.com:user/repo.git\n abcd1234..efgh5678 main -> main"
}
git_diff
View file differences.
Parameters:
repo_path- Path to the Git repositorypath- (optional) Path to file or directorystaged- (optional) Whether to show staged changescommit- (optional) Commit to compare against
Returns:
{
"changes": "diff --git a/file.txt b/file.txt\nindex 1234567..abcdefg 100644\n--- a/file.txt\n+++ b/file.txt\n@@ -1,3 +1,4 @@\n Line 1\nLine 2\nLine 3\n+New line\nLine 4"
}
git_add
Add file contents to the staging area.
Parameters:
repo_path- Path to the Git repositorypath- Path(s) to add, or patterns to match. Use '.' for all files.update- (optional) Whether to update, rather than addall- (optional) Whether to add all changes, including untracked files
Returns:
{
"success": true,
"message": "Files staged successfully",
"status": ["M file1.txt", "A file2.txt"]
}
git_reset
Reset the staging area or working tree to a specified state.
Parameters:
repo_path- Path to the Git repositorypath- Path(s) to reset, or patterns to match. Use '.' for all files.hard- (optional) Whether to perform a hard reset (WARNING: discards all local changes)target- (optional) The commit or branch to reset to (defaults to HEAD)
Returns:
{
"success": true,
"message": "Files unstaged successfully",
"status": ["?? file1.txt", "?? file2.txt"]
}
git_worktree_list
List all worktrees in a repository.
Parameters:
repo_path- Path to the Git repository
Returns:
{
"worktrees": [
{
"id": "worktree-name",
"path": "/path/to/worktree",
"locked": false,
"lock_reason": null
}
]
}
git_worktree_add
Create a new worktree.
Parameters:
repo_path- Path to the Git repositorypath- Path for the new worktreebranch- (optional) Branch name to createcommit_ref- (optional) Commit reference to check outcheckout- (optional) Whether to check out files, defaults to true
Returns:
{
"success": true,
"path": "/path/to/new/worktree",
"branch": "feature-branch",
"output": "Preparing worktree (checking out 'feature-branch')"
}
git_worktree_remove
Remove a worktree.
Parameters:
repo_path- Path to the Git repositorypath- Path to the worktree to removeforce- (optional) Force removal even if worktree is dirty
Returns:
{
"success": true,
"path": "/path/to/worktree",
"force": false,
"output": "Removing worktrees/feature-branch"
}
git_worktree_prune
Prune working tree files in $GIT_DIR/worktrees.
Parameters:
repo_path- Path to the Git repositoryverbose- (optional) Report all removalsdry_run- (optional) Do not remove, show only
Returns:
{
"success": true,
"verbose": false,
"dry_run": false,
"output": "Pruning worktrees/feature-branch"
}
Development
Project Structure
mcp-git-tools/
├── Cargo.toml # Dependencies and project configuration
├── src/
│ ├── lib.rs # Core library with GitToolsHandler
│ └── bin/
│ └── server.rs # Server entry point
├── tests/
│ └── lib_tests.rs # Unit tests
Building
# Debug build
cargo build
# Release build
cargo build --release
# Run tests
cargo test
# Run server
cargo run --release --bin mcp-git-server
Adding New Tools
To add a new Git tool:
- Add the parameter struct in
src/lib.rs:
#[derive(serde::Deserialize, schemars::JsonSchema)]
struct GitMyToolParams {
repo_path: String,
// other parameters...
}
- Add the method in the
GitToolsHandlerimpl block:
#[tool(description = "Description of your tool")]
pub async fn git_my_tool(
&self,
repo_path: String,
// other parameters...
) -> Result<CallToolResult> {
// Implementation
}
- Update the
list_tools()method to include your new tool in the returned list
Dependencies
rmcpv0.14.0 - The official RMCP SDKtokio- Async runtimeserde- Serialization frameworkserde_json- JSON implementationanyhow- Error handlingtracing- Logging frameworktempfile- Testing utilities
License
MIT License
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.