Skip to content

fix(git): raise error on invalid branch type; normalize git_log output format - #4484

Closed
isheng-eqi wants to merge 2 commits into
modelcontextprotocol:mainfrom
isheng-eqi:fix/git-branch-error-and-log-consistency
Closed

isheng-eqi wants to merge 2 commits into
modelcontextprotocol:mainfrom
isheng-eqi:fix/git-branch-error-and-log-consistency

Conversation

@isheng-eqi

Copy link
Copy Markdown

Summary

Two fixes in the git server.

Problem 1: Invalid branch_type silently succeeds

git_branch accepted any branch_type value via a match default case that returned an error string (line 300). Since the caller treats all non-exception returns as successful output, an invalid type like "blah" would produce output "Invalid branch type: blah" — indistinguishable from a successful branch listing to the LLM consumer.

Problem 2: git_log format inconsistency between code paths

The git_log function has two paths:

  • Filtered (with --since/--until): Commit: abc123 (plain format)
  • Unfiltered (no date filter): Commit: abc123 (repr format with !r)

This means the LLM sees different output formats depending on whether date filters are used, making it harder to parse. Also the Message: prefix was inconsistent — the filtered path used Message: while the fix normalizes both to a 4-space indent for message lines.

Changes

  • src/git/src/mcp_server_git/server.py (+5/-5):
    • git_branch: return f"Invalid..." → raise ValueError(...) with descriptive message listing valid values
    • git_log: removed !r from unfiltered path; normalized message indentation to 4 spaces in both paths

…t format

Two fixes in the git server:

1. git_branch: Invalid branch_type values (not 'local'/'remote'/'all')
   returned an error string that was silently treated as successful
   branch output. Now raises ValueError so the caller can properly
   report the error to the client.

2. git_log: The filtered (--since/--until) and unfiltered paths
   produced inconsistent output. The unfiltered path used !r (repr)
   formatting which adds quotes around values (e.g., Commit: 'abc123'),
   while the filtered path had no quotes. Both paths now use consistent
   plain formatting. Message field indentation normalized to 4 spaces
   in both paths.
@isheng-eqi
isheng-eqi force-pushed the fix/git-branch-error-and-log-consistency branch from 2e2e51d to 012b468 Compare July 6, 2026 19:04
@cliffhall cliffhall added the closed-superseded-v2 Closed: fixed or made obsolete by the v2 / 2026-07-28 refactor (#4875) label Oct 20, 2026
@cliffhall

Copy link
Copy Markdown
Member

Thank you for this pull request, and apologies for the long wait for a response.

Since it was opened, the reference servers have been rebuilt for the 2026-07-28 MCP specification (#4857) and released as v2 (2.0.0 on npm for the TypeScript servers, 2026.10.19 on PyPI for the Python servers). The code this PR changes has been replaced, and the behavior it addresses has either been fixed in v2 or no longer exists in the same form.

This is not a judgment on the change or on you; it's a consequence of the code it targets having been replaced. If the problem still happens on v2, please open a fresh issue with the version you're running and steps to reproduce. Note that this repository now accepts contributions as issues rather than pull requests from anyone but its maintainers; see CONTRIBUTING.md.

This is part of the backlog triage in #4875.

@cliffhall cliffhall closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closed-superseded-v2 Closed: fixed or made obsolete by the v2 / 2026-07-28 refactor (#4875)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants