Skip to content

Conversation

@JavieHush
Copy link
Contributor

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)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

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

Additional context

:)

JavieHush and others added 6 commits May 28, 2025 16:18
This commit introduces the `git branch` tool to the MCP Git server, allowing users to list branches with various filtering options.

Changes include:
- Implemented `git_branch` function in `src/git/src/mcp_server_git/server.py` to support listing local, remote, and all branches, as well as filtering by `contains` and `not_contains` SHA values.
- Added comprehensive unit tests for the `git branch` functionality in `src/git/tests/test_server.py`, covering different branch types and commit filtering scenarios.
- Updated `src/git/README.md`.
@JavieHush
Copy link
Contributor Author

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

@olaservo olaservo added enhancement New feature or request server-git Reference implementation for the Git MCP server - src/git and removed add-community-server labels Jun 13, 2025
Copy link
Member

@olaservo olaservo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR! Looks like there is one minor conflict to resolve after merging in some updates to deprecated Pydantic functions from another recent merge. Other than that LGTM. 👍

This commit introduces the `git branch` tool to the MCP Git server, allowing users to list branches with various filtering options.

Changes include:
- Implemented `git_branch` function in `src/git/src/mcp_server_git/server.py` to support listing local, remote, and all branches, as well as filtering by `contains` and `not_contains` SHA values.
- Added comprehensive unit tests for the `git branch` functionality in `src/git/tests/test_server.py`, covering different branch types and commit filtering scenarios.
- Updated `src/git/README.md`.
@JavieHush JavieHush requested a review from olaservo June 25, 2025 07:31
@JavieHush
Copy link
Contributor Author

@olaservo Hi ola, all conflicts resolved!

@olaservo olaservo merged commit 0f9f95a into modelcontextprotocol:main Jun 25, 2025
15 checks passed
PazerOP referenced this pull request in PazerOP/mcp-template Jul 15, 2025
Add Git Branch tool to mcp-server-git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request server-git Reference implementation for the Git MCP server - src/git

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants