Skip to content

feat(mcp-server-git): Add context_lines to git_diff* tools #1326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mceachen
Copy link

@mceachen mceachen commented Apr 8, 2025

  • Added context_lines parameter to git_diff_unstaged, git_diff_staged, and git_diff functions
  • Updated README.md to document the new environment variable and its implications.

Description

Server Details

  • Server: git
  • Changes to: git_diff_unstaged, git_diff_staged, and git_diff.

Motivation and Context

The standard unified git diff only includes 3 lines of context. When Claude is being asked to review pending changes, it is blind to the remainder of any touched file unless the lines of context are increased.

At the limit, a context_lines value that is the same size of your largest source file means every touched file gets automatically included in the context. Claude seems to handle this with aplomb and provides strictly better git review guidance. ChatGPT 4o seems to get distracted by the larger diff contexts, so YMMV.

How Has This Been Tested?

MCP Inspector and vscode/copilot

Breaking Changes

No--by default, no behavior changes with this PR.

Users simply add a reference to setting "context_lines" in their prompt.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

The first commit used an environment variable. The current PR uses a proper parameter, which is more flexible and seems to be more idiomatic.

mceachen added 2 commits April 8, 2025 15:41
…INES

- Introduced `GIT_DIFF_CONTEXT_LINES` environment variable to customize the number of context lines shown in git diff output.
- Updated `git_diff_unstaged`, `git_diff_staged`, and `git_diff` functions to utilize the new context line setting.
- Enhanced README.md to document the new environment variable and its implications.
@mceachen mceachen changed the title feat(mcp-server-git): Add support for configurable GIT_DIFF_CONTEXT_LINES feat(mcp-server-git): Add context_lines support to git_diff* tools Apr 9, 2025
@mceachen mceachen changed the title feat(mcp-server-git): Add context_lines support to git_diff* tools feat(mcp-server-git): Add context_lines to git_diff* tools Apr 9, 2025
@olaservo olaservo added enhancement New feature or request server-git Reference implementation for the Git MCP server - src/git labels Apr 18, 2025
@mceachen mceachen force-pushed the main branch 2 times, most recently from a4df44e to ba54c9d Compare April 29, 2025 23:04
@mceachen
Copy link
Author

(Oof: I clicked the "update with rebase" button next to "This branch is out-of-date with the base branch" in GitHub, and it did terrible things. I just reverted with a second force-push).

@olaservo anything I can do to expedite? (It really does substantively improve Claude's code reviews quality!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server-git Reference implementation for the Git MCP server - src/git
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants