git_diff
Compare code changes in Git repositories to identify modifications between commits, branches, or files for review and analysis.
Instructions
Shows git diff
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | ||
| target | Yes |
Implementation Reference
- Core implementation of git_diff tool executing git diff via gitpython library.async def diff(self, repo_path: str, target: str | None = None) -> str: """Show git diff.""" repo = git.Repo(repo_path) return repo.git.diff(target) if target else repo.git.diff()
- Pydantic model defining the input schema for the git_diff tool.class GitDiff(BaseModel): repo_path: str target: str
- src/mcp_server_code_assist/server.py:126-130 (registration)Registration of the git_diff tool in the MCP server's list_tools() function.Tool( name=CodeAssistTools.GIT_DIFF, description="Shows git diff", inputSchema=GitDiff.model_json_schema(), ),
- MCP server @call_tool handler that validates input with GitDiff model and delegates to GitTools.diff.case CodeAssistTools.GIT_DIFF: model = GitDiff(repo_path=arguments["repo_path"], target=arguments.get("target", "")) result = await git_tools.diff(model.repo_path, model.target) return [TextContent(type="text", text=result)]
- Singleton factory for GitTools instance used by git_diff handler.def get_git_tools(allowed_paths: list[str]) -> GitTools: """Get or create GitTools instance with given allowed paths. Args: allowed_paths: List of paths that tools can operate on Returns: GitTools instance with updated paths """ global _git_tools if not _git_tools or not all(path in _git_tools.allowed_paths for path in allowed_paths): _git_tools = GitTools(allowed_paths=allowed_paths) return _git_tools