fix+docs(git): consistent error idiom for git_branch + expanded tool descriptions - #4048
Closed
yakuphanycl wants to merge 1 commit into
Closed
Conversation
…descriptions External MCP audit (using https://github.com/yakuphanycl/wrg-skills/tree/main/skills/mcp-audit) surfaced two improvements to `src/git/src/mcp_server_git/server.py`. Batched per the audit's disclosure SOP §2 — Low + Info findings into one PR. ## Fix — git_branch error idiom inconsistency (Low) `git_branch` returned an error string on invalid `branch_type` while every other helper in this module raises (`git_diff`, `git_checkout`, `git_show`, `git_create_branch`, `git_log`). The string return reaches the MCP client masquerading as a successful tool result, which is the opposite of what the rest of the surface does. Changed to `raise ValueError(...)` with a message naming the valid options. Added `test_git_branch_rejects_invalid_branch_type` in the same style as the existing flag-injection guard tests. ## Docs — expand 12 Tool() descriptions (Info) The in-code Tool() descriptions in `@server.list_tools()` were concise WHAT-statements ("Shows the working tree status", "Switches branches") that lacked when-to-use guidance and return-shape documentation. The README has more detail, but agents reading the MCP tool surface see only the in-code description. Rewrote all 12 to follow the same shape: - WHAT (preserved from the existing description) - when-to-use guidance (one short clause) - return-shape hint (text / list of commit entries / unified diff / etc.) For tools with flag-injection guards (git_diff, git_checkout, git_show) the description now mentions that refs starting with `-` are rejected, making the safety guarantee discoverable from the tool surface. No behavioural change to any tool dispatch path, no schema change, no new dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
External MCP audit of
src/git/(using themcp-auditskill) surfaced one Low and one Info finding. Batched into a single PR per the audit's disclosure SOP §2.No behavioural change to any tool dispatch path, no schema change, no new dependencies. The mutation tool gating (
--repository+validate_repo_path), flag-injection guards, and security tests are untouched.Findings addressed
F-001 —
git_brancherror idiom inconsistent with peers (Low)Severity rubric:
ERR-002— mixedraisevs in-band string across surface.git_branchreturnedf\"Invalid branch type: {branch_type}\"(a normal-looking string) on invalid input, while every other helper in the module raises (git_diff,git_checkout,git_show,git_create_branch,git_logall useraise BadName/ValueError). The string return reaches the MCP client masquerading as a successful tool result.Fix: change to
raise ValueError(...)with a message that names the valid options ('local','remote','all'). Addedtest_git_branch_rejects_invalid_branch_typein the same style as the existing flag-injection guard tests.F-003 — In-code Tool() descriptions lack when-to-use + return-shape (Info, surface-wide)
Severity rubric:
DISC-002+DISC-004— discoverability axis, applied surface-wide.All 12 in-code descriptions in
@server.list_tools()were concise WHAT-statements (e.g., "Shows the working tree status", "Switches branches"). The README has more detail, but agents reading the MCP tool surface only see the in-code description.Fix: rewrote all 12 descriptions to follow a consistent shape:
For tools with flag-injection guards (
git_diff,git_checkout,git_show), the description now mentions that refs starting with-are rejected — the existing safety guarantee is now discoverable from the tool surface, not only from reading the source.Findings deferred
F-002 — No MCP-layer dispatch test (Low, deferred)
The existing tests exercise the helper functions (
git_status,git_commit, …) directly. None round-trip through the@server.call_tool()dispatcher with(name, arguments)to verify thematchcases and theTextContentwrapping. This is a real coverage gap, but adding async dispatch fixtures is a separate scope worth its own PR — flagged in the audit's next-session backlog rather than batched here.Test plan
test_git_branch_rejects_invalid_branch_typepasses.shutil.rmtreeflake (PermissionError: WinError 32); test bodies pass, only fixture teardown errors. Unrelated to this PR — Linux CI will be clean.Audit reference
yakuphanycl/wrg-skillswrg-skills/docs/case-studies/git-mcp-2026-04-26.md🤖 Generated with Claude Code