git: git_create_branch is marked non-destructive but silently resets an existing packed branch
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
Research direction
Start at src/git/src/mcp_server_git/server.py: the git_create_branch handler (around L183-L195) and its annotation block (L396-L404). Reproduce with the issue's pack-refs scratch repo, then add an existing-branch check before repo.create_head so packed refs are refused (or gated behind an explicit force argument), and adjust destructiveHint accordingly. Done when a packed branch is no longer silently moved and the git server's tests pass.
Written by the indexing model from the issue text.
Description
Summary
git_create_branch is annotated destructiveHint: false, but if a branch with the requested name already exists as a packed ref (as after git gc, git pack-refs, or in a fresh clone), the call silently moves that branch to the new base. The previous tip becomes unreachable from every ref, and no reflog entry records the reset. git branch <name> on the CLI would refuse.
Where
- Annotation:
src/git/src/mcp_server_git/server.py#L396-L404. - Handler calls
repo.create_head(branch_name, base)without checking whether the branch exists:server.py#L183-L195. - GitPython only refuses to overwrite an existing loose ref file, so a packed ref is overwritten.
Reproduce
- In a scratch repo: create
main, then a branchfeaturewith one extra commit, and rungit pack-refs --all. - Start the git server on that repo.
- Call
git_create_branchwith{"repo_path": "<repo>", "branch_name": "feature", "base_branch": "main"}. - The call reports
Created branch 'feature' from 'main';featurenow points atmain, its previous commit is unreachable, andgit reflog show featurehas no entry for the move.
Why it matters
MCP clients relax confirmation for tools that declare destructiveHint: false, so this call can be auto-approved, and it can discard commits.
Possible fix
Check for an existing branch (loose or packed) and return an error, or require an explicit force argument, matching the git CLI. While a force path exists, destructiveHint: true would be accurate.
Found during an audit of MCP tool annotations (AI-assisted source review, then reproduced locally). Happy to send a PR.
- Dominant language
- JavaScript
- Stars
- 91.2k
- Forks
- 11.8k
- Avg merge
- 6h 52m
- Merged PRs (30d)
- 107
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/servers
-
documentation v2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelcontextprotocol/servers#5133 ·
Maintainers usually reply within 1 day
-
sequentialthinking: the thought box's header row is 2 columns narrower than its borderPossibly taken @nightcityblade claimed this 1 day ago. Openbug server-sequentialthinking v2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
modelcontextprotocol/servers#5108 · 2 comments ·
Maintainers usually reply within 1 day
-
bug server-git v2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
modelcontextprotocol/servers#5107 ·
Maintainers usually reply within 1 day
-
chore v2
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
modelcontextprotocol/servers#5091 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelcontextprotocol/servers#5071 · 2 comments ·
Maintainers usually reply within 1 day
All issues in modelcontextprotocol/servers
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
enhancement
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
holepunchto/hrpc-test#28 ·
-
good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
anoopcodehack/DevBoard#616 ·
Maintainers usually reply within 2 days
-
idnits3
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
ietf-tools/idnits#319 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
521xueweihan/HelloGitHub#3939 ·