Skip to content

Conversation

@mceachen
Copy link
Contributor

@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
Contributor 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!)

@olaservo
Copy link
Member

Hi @mceachen just getting to this now, sorry for the miss on the earlier tag. Should the DEFAULT_CONTEXT_LINES also be able to be changed using an ENV variable rather than being hard-coded?

@olaservo
Copy link
Member

Adding more from discord convo for visibility: to clarify, I think it makes sense to make this something that can get set as an optional parameter. So re: my env variable question I was more thinking that when the parameter isn't being set, does it make sense for the default to be configurable in the server config.
from what I can tell, the current behavior without your fix (i.e. default without parameters) is decided by git outside of the server/tool, and that is what you're using as your hard-coded default (3)
so I'm just thinking of a situation where someone wants a longer number of lines by default?

Copy link
Member

@olaservo olaservo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, will leave the environment variable option as a future enhancement since the default is already the same as the git default.

@olaservo olaservo merged commit 1252f48 into modelcontextprotocol:main Jun 25, 2025
PazerOP referenced this pull request in PazerOP/mcp-template Jul 15, 2025
feat(mcp-server-git): Add context_lines to git_diff* tools
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