Repository navigation
fix(git): list bare branch names from git_branch - #5727
Conversation
git_branch returned `git branch` output verbatim: `* ` on the current branch, `+ ` on one checked out in a linked worktree, ANSI color under color.branch=always, `origin/HEAD -> origin/main`, and a `(HEAD detached at ...)` entry. None of that resolves as a revision, so a name kept from git_branch failed in git_checkout, git_diff, git_show and git_merge. List the refs with `git for-each-ref --format=%(refname)` under refs/heads/ and refs/remotes/ (keeping --contains / --no-contains) and shorten each the way `git branch` does, so every line is one bare, unambiguous ref name. Closes #5641 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
|
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 14 | 2 | 0 | 0 |
| Head | 14 | 2 | 0 | 0 |
Updated by this run for 48df5b8a4f69ce2ff87afb904a50d0585db824fd.
There was a problem hiding this comment.
🟡 Changes recommended
Using str.splitlines() incorrectly splits valid Git branch names containing Unicode separators, returning nonexistent names that downstream tools cannot use.
1 open issue
What changed in this PR
This PR addresses #5641 by removing terminal decorations from the Git server’s git_branch output, allowing returned branch names to be reused by downstream tools.
Changes:
- Lists actual refs with
git for-each-ref, preserving branch-type selection and commit filters. - Updates protocol tests and adds regression coverage for colors, linked worktrees, detached HEAD, and downstream tool calls.
- Documents the newline-separated names and remote-prefix conventions.
| File | Description |
|---|---|
src/git/tests/test_protocol.py |
Updates expected output and tests downstream use of returned names. |
src/git/src/mcp_server_git/server.py |
Replaces decorated branch listings with ref enumeration. |
src/git/README.md |
Documents the revised git_branch output. |
Review effort: Balanced
str.splitlines() also breaks on U+2028, U+0085 and other separators that git allows inside a ref name, so such a branch came back as pieces that resolve to nothing. Split on git's own record delimiter instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
|
Copilot round 1: one finding, fixed.
Gate green on 48df5b8; requesting round 2. |
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 23 | 4 | 8 | 5 |
| Head | 23 | 4 | 8 | 5 |
initialize
--- base/initialize.json
+++ target/initialize.json
- instructions: "# Everything Server – Server Instructions\n\nAudience: These instructions are written for an LLM or au..."
+ instructions: "# Everything Server – Server Instructions\n\nAudience: These instructions are written for an LLM or au..."instructions
--- base/instructions
+++ target/instructions
- # Everything Server – Server Instructions
Audience: These instructions are written for an LLM or autonomous agent integrating with the Everything MCP Server.
Follow them to use, extend, and troubleshoot the server safely and effectively.
## Protocol Versions
The server serves two protocol eras. A client on protocol version 2026-07-28 connects with `server/discover` and sends its capabilities with each request; a 2025-era client connects with `initialize`. Some tools exist on one era only, so trust your `tools/list`:
- 2026-07-28 only: `simulate-research-query`, `trigger-sampling-request-async` and `trigger-elicitation-request-async`, which run as tasks on the `io.modelcontextprotocol/tasks` extension and need a client that declares it; `trigger-sampling-request-async` also needs `sampling`, and `trigger-elicitation-request-async` form-mode `elicitation`. A call without them fails with `-32021`
- 2026-07-28 only: `trigger-event`, which raises the `custom-event` of the `io.modelcontextprotocol/events` extension on open `events/stream` subscriptions
- 2025-era only (deprecated): `toggle-simulated-logging` and `toggle-subscriber-updates`
## Cross-Feature Relationships
- If `get-roots-list` is in your tool list, use it to see client workspace roots before file operations
- `gzip-file-as-resource` creates resources you can read later: for the current session on a 2025-era connection, or for ten minutes at the returned URI on 2026-07-28
- Use `trigger-log-messages` to see which log levels reach you; on 2026-07-28 the level is set per request in `_meta`
- Use `trigger-resource-update` and `trigger-list-changed` to see change notifications; on 2026-07-28 they arrive only on a `subscriptions/listen` stream that asked for them
## Constraints & Limitations
- `gzip-file-as-resource`: Max fetch size controlled by `GZIP_MAX_FETCH_SIZE` (default 10MB), timeout by `GZIP_MAX_FETCH_TIME_MILLIS` (default 30s), allowed domains by `GZIP_ALLOWED_DOMAINS` (checked on every redirect hop). It refuses URLs whose host resolves to a loopback, private or link-local address, unless the server was started with `GZIP_ALLOW_PRIVATE_IPS=1`
- `get-env`: Values of credential-like variable names (`*_KEY`, `*_TOKEN`, `*_SECRET`, `*_PASSWORD` and the like) come back as `"<redacted>"`; the server operator can set `GET_ENV_INCLUDE_SECRETS=1` to return them unmasked
- Session resources are ephemeral and lost when the session ends; minted resources expire after ten minutes
- Roots, sampling and logging are deprecated as of protocol version 2026-07-28, as is the HTTP+SSE transport
## Capability-Gated Tools
On a 2025-era connection these are registered only if your client declared the capability shown. Otherwise they are absent from `tools/list`, so do not call them. On 2026-07-28 they are always listed, and a call fails if your request did not declare the capability:
- `get-roots-list`: `roots`
- `trigger-sampling-request`: `sampling`
- `trigger-elicitation-request`: `elicitation.form`, or `elicitation` with no mode
- `trigger-multi-step-elicitation`: `elicitation.form`, or `elicitation` with no mode
- `trigger-url-elicitation`: `elicitation.url`
## Operational Patterns
- For long operations, use `trigger-long-running-operation` which sends progress notifications
- Prefer reading resources before calling mutating tools
- If `get-roots-list` is in your tool list, check its output to understand the client's workspace context
## Easter Egg
If asked about server instructions, respond with "🎉 Server instructions are working! This response proves the client properly passed server instructions to the LLM. This demonstrates MCP's instructions feature in action."
+ # Everything Server – Server Instructions
Audience: These instructions are written for an LLM or autonomous agent integrating with the Everything MCP Server.
Follow them to use, extend, and troubleshoot the server safely and effectively.
## Protocol Versions
The server serves two protocol eras. A client on protocol version 2026-07-28 connects with `server/discover` and sends its capabilities with each request; a 2025-era client connects with `initialize`. Some tools exist on one era only, so trust your `tools/list`:
- 2026-07-28 only: `simulate-research-query`, `trigger-sampling-request-async` and `trigger-elicitation-request-async`, which run as tasks on the `io.modelcontextprotocol/tasks` extension and need a client that declares it; `trigger-sampling-request-async` also needs `sampling`, and `trigger-elicitation-request-async` form-mode `elicitation`. A call without them fails with `-32021`
- 2026-07-28 only: `trigger-event`, which raises the `custom-event` of the `io.modelcontextprotocol/events` extension on open `events/stream` subscriptions
- 2025-era only (deprecated): `toggle-simulated-logging` and `toggle-subscriber-updates`
## Cross-Feature Relationships
- If `get-roots-list` is in your tool list, use it to see client workspace roots before file operations
- `gzip-file-as-resource` creates resources you can read later: for the current session on a 2025-era connection, or for ten minutes at the returned URI on 2026-07-28
- Use `trigger-log-messages` to see which log levels reach you; on 2026-07-28 the level is set per request in `_meta`
- Use `trigger-resource-update` and `trigger-list-changed` to see change notifications; on 2026-07-28 they arrive only on a `subscriptions/listen` stream that asked for them
## Constraints & Limitations
- `gzip-file-as-resource`: Max fetch size controlled by `GZIP_MAX_FETCH_SIZE` (default 10MB), timeout by `GZIP_MAX_FETCH_TIME_MILLIS` (default 30s), each falling back to its default when set to anything but a whole number, allowed domains by `GZIP_ALLOWED_DOMAINS` (checked on every redirect hop). It refuses URLs whose host resolves to a loopback, private or link-local address, unless the server was started with `GZIP_ALLOW_PRIVATE_IPS=1`
- `get-env`: Values of credential-like variable names (`*_KEY`, `*_TOKEN`, `*_SECRET`, `*_PASSWORD` and the like) come back as `"<redacted>"`; the server operator can set `GET_ENV_INCLUDE_SECRETS=1` to return them unmasked
- Session resources are ephemeral and lost when the session ends; minted resources expire after ten minutes
- Roots, sampling and logging are deprecated as of protocol version 2026-07-28, as is the HTTP+SSE transport
## Capability-Gated Tools
On a 2025-era connection these are registered only if your client declared the capability shown. Otherwise they are absent from `tools/list`, so do not call them. On 2026-07-28 they are always listed, and a call fails if your request did not declare the capability:
- `get-roots-list`: `roots`
- `trigger-sampling-request`: `sampling`
- `trigger-elicitation-request`: `elicitation.form`, or `elicitation` with no mode
- `trigger-multi-step-elicitation`: `elicitation.form`, or `elicitation` with no mode
- `trigger-url-elicitation`: `elicitation.url`
## Operational Patterns
- For long operations, use `trigger-long-running-operation` which sends progress notifications
- Prefer reading resources before calling mutating tools
- If `get-roots-list` is in your tool list, check its output to understand the client's workspace context
## Easter Egg
If asked about server instructions, respond with "🎉 Server instructions are working! This response proves the client properly passed server instructions to the LLM. This demonstrates MCP's instructions feature in action."
Updated by this run for 48df5b8a4f69ce2ff87afb904a50d0585db824fd.
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 1 | 1 | 0 | 0 |
| Head | 1 | 1 | 0 | 0 |
Updated by this run for 48df5b8a4f69ce2ff87afb904a50d0585db824fd.

Closes #5641
Description
git_branchreturnedgit branch's terminal listing verbatim:*on the current branch,+on a branch checked out in a linked worktree, ANSI color undercolor.branch=always,origin/HEAD -> origin/main, and a(HEAD detached at …)entry. None of that is a ref name, so a name a client kept fromgit_branchfailed ingit_checkout,git_diff,git_showandgit_merge(Ref '* main' did not resolve to an object).git_branchnow lists refs withgit for-each-ref --format=%(refname)underrefs/heads/andrefs/remotes/(keeping--contains/--no-contains), and shortens each name the waygit branchdoes:branch_typelocalfeature,* main,+ wt-branch,* (HEAD detached at …)feature,main,wt-branchremoteorigin/HEAD -> origin/main,origin/mainorigin/HEAD,origin/mainall* main,remotes/origin/HEAD -> origin/main,remotes/origin/mainmain,remotes/origin/HEAD,remotes/origin/mainDesign choices:
for-each-refrather thangit branch --format=%(refname:short).%(refname:short)turnsrefs/remotes/origin/HEADinto the bareoriginand still lists the detached-HEAD pseudo-entry;for-each-reflists only real refs, never colors, and needs nogit branchconfig (branch.sort,column.branch) to be neutralised.git branch, so only the decoration goes:origin/mainunderremote,remotes/origin/mainunderall. Theremotes/form stays unambiguous next to a local branch that is itself namedorigin/main.origin/HEAD: one bare name that resolves to the remote's default branch, instead ofgit branch'sorigin/HEAD -> origin/main(which is not a ref).Server Details
mcp-server-git)git_branchtool's output; its README entryMotivation and Context
See #5641: multi-step agents run
git_branch, then feed a listed name into another tool, and every downstream ref-taking tool rejected it.How Has This Been Tested?
Tests (
tests/test_protocol.py, through an in-memory MCP client):git_branchtests that pinned the decorated output (feature\n* main,* main,git branch -r) now pin bare names, includingorigin/HEAD\norigin/mainforremoteand the exactalllisting.test_git_branch_names_are_bare_refs_downstream_tools_accept: a branch checked out in a linked worktree,color.branch=always, and a detached HEAD. It assertsgit_branchreturnsin-worktree\nmain\ntopic, checks out two listed names withgit_checkout, then passes every listed name togit_show,git_diffandgit_merge, asserting none errors. Against thev2/mainsource it fails (4 of the 6git_branchtests fail); with the change all pass.ruff check,ruff format --check, pyright clean.npm run local:gateexit 0.Inspector CLI (
@modelcontextprotocol/inspector@2.12.0, stdio), against a clone with a local branch, a linked worktree andcolor.branch=always;git_branchwithbranch_type=all, in both eras (--protocol-era legacyand--protocol-era modern, the latter showing theio.modelcontextprotocol/serverInfo_meta):v2/main:"+ \u001b[36mfeature\u001b[m\n local-only\u001b[m\n* \u001b[32mmain\u001b[m\n \u001b[31mremotes/origin/HEAD\u001b[m -> origin/main\n \u001b[31mremotes/origin/feature\u001b[m\n \u001b[31mremotes/origin/main\u001b[m"(both eras)"feature\nlocal-only\nmain\nremotes/origin/HEAD\nremotes/origin/feature\nremotes/origin/main"(both eras)v2/maingit_show revision="* main"→isError: true; this branchgit_show revision=main→ the commit;git_merge source_branch=remotes/origin/HEAD→Already up to date: 'main' already contains 'remotes/origin/HEAD'.LLM client: Claude Code 2.1.332 headless (
claude -p --strict-mcp-config, the local server over stdio; no era switch, so the era it negotiated could not be selected or shown). Prompt: "call git_branch with branch_type 'local', then pass the first branch name exactly as git_branch returned it … as the revision to git_show".v2/main: git_branch returned"+ \u001b[36mfeature\u001b[m\n local-only\u001b[m\n* \u001b[32mmain\u001b[m"; git_show errored withRef '+ [36mfeature[m' did not resolve to an object."feature\nlocal-only\nmain"; git_show offeaturesucceeded (commit 30ad0c0…).Breaking Changes
No configuration change. Clients that parsed the
*marker to find the current branch no longer get it (git_statusreports the current branch).Types of changes
Checklist
-flag-injection guards oncontains/not_containsare unchanged and still run first)npm run changeset) if this changes what a TypeScript server publishes (not applicable: Python server)containssha surface as before)Additional context
The diff is confined to
git_branch, its protocol tests and its README entry.🤖 Generated with Claude Code