Skip to content

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

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

fix(git): raise error on invalid branch type; normalize git_log output format#4484
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant