git_diff_staged
Display staged file diffs to review changes before committing, with adjustable context lines for better readability.
Instructions
Shows changes that are staged for commit
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | ||
| context_lines | No |
Implementation Reference
- The core handler function that executes git_diff_staged logic. It calls `repo.git.diff('--unified=<context_lines>', '--cached')` to show staged changes.
def git_diff_staged(repo: git.Repo, context_lines: int = DEFAULT_CONTEXT_LINES) -> str: return repo.git.diff(f"--unified={context_lines}", "--cached") - Pydantic model defining the input schema for git_diff_staged: repo_path (str) and optional context_lines (int with default 3).
class GitDiffStaged(BaseModel): repo_path: str context_lines: int = DEFAULT_CONTEXT_LINES - src/git/src/mcp_server_git/server.py:99-99 (registration)Enum entry mapping the tool name 'git_diff_staged' to the GitTools enum.
DIFF_STAGED = "git_diff_staged" - src/git/src/mcp_server_git/server.py:331-340 (registration)Tool registration where GitDiffStaged is added to the list of tools with its schema and annotations.
Tool( name=GitTools.DIFF_STAGED, description="Shows changes that are staged for commit", inputSchema=GitDiffStaged.model_json_schema(), annotations=ToolAnnotations( readOnlyHint=True, destructiveHint=False, idempotentHint=True, openWorldHint=False, ), - The dispatch/call-site in the handler loop that invokes git_diff_staged when the tool name matches DIFF_STAGED.
case GitTools.DIFF_STAGED: diff = git_diff_staged(repo, arguments.get("context_lines", DEFAULT_CONTEXT_LINES)) return [TextContent( type="text", text=f"Staged changes:\n{diff}" )]