servers icon indicating copy to clipboard operation
servers copied to clipboard

Add Git Branch tool to mcp-server-git

Open JavieHush opened this issue 7 months ago • 1 comments

Description

This commit introduces the git branch tool to the MCP Git server, allowing model to read branch info with various filtering options. git branch tool enable model to:

  • List local, remote, or all branches within a Git repository.
  • Filter branches based on whether they contain a specific commit SHA.
  • Filter branches based on whether they do not contain a specific commit SHA.

This functionality enhances the server's capabilities by providing comprehensive branch management options.

Server Details

  • Server: git
  • Changes to:
    • src/git/src/mcp_server_git/server.py (add new git branch tool)
    • src/git/tests/test_server.py (add corresponding unit test)
    • src/git/README.md (add git branch introduction)

Motivation and Context

Our team have benefit a lot from mcp-server-git when need models to interact with our private code hosting platform. Everything works perfectly except model cannot access git branch info using this server.

When giving prompt like Check if commit 3339591a is already on branch A, if not, apply this commit to this branch manually or Do I have a branch with 'dev' in its name? If so, checkout to it. , the agent will firstly try to check if specified branch exists. It will struggle to call this server multiple times, and fail each time, of course. and then attempt to use terminal to achieve this goal(Not every time will it use terminal as its last choice, sometimes it may try to call the tool for more than 10 times, which brings us a really bad experience).

So we add this git branch tool to solve this problem, everything works perfectly, and we hope to share this little new tool to those who meet same problems like we do :)

How Has This Been Tested?

Comprehensive unit tests have been added for the git branch functionality in test_server.py , covering different branch types and commit filtering scenarios. These tests ensure the correct behavior of the new git_branch tool.

Plus, we've tested this new feature with mainstream models like Claude, GPT, Gemini, etc. Alongwith LLM clients like Cursor and Trae.

This new feature works properly with these models, clients, and can cooperate well with other tools within this server.

Breaking Changes

No, this change introduces new functionality and does not break existing configurations.

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [x] Documentation update

Checklist

  • [x] I have read the MCP Protocol Documentation
  • [x] My changes follows MCP security best practices
  • [x] I have updated the server's README accordingly
  • [x] I have tested this with an LLM client
  • [x] My code follows the repository's style guidelines
  • [x] New and existing tests pass locally
  • [x] I have added appropriate error handling
  • [x] I have documented all environment variables and configuration options

Additional context

:)

JavieHush avatar May 28 '25 10:05 JavieHush

@dsp-ant This PR is ready, would u please help review and merge it?

JavieHush avatar Jun 03 '25 01:06 JavieHush

@olaservo Hi ola, all conflicts resolved!

JavieHush avatar Jun 25 '25 07:06 JavieHush