diff_with_ref
Compare code changes between HEAD and a specified reference branch to analyze differences in a project. Ideal for reviewing PRs or tracking updates in development workflows.
Instructions
Return a summary of the diff between HEAD and the given ref.
You probably want the ref to be the 'base' branch like develop or main, off which PRs are made - and you can likely determine this by viewing the most recently checked out branches.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | Yes | ||
| ref | Yes |
Implementation Reference
- mcpunk/tools.py:431-456 (handler)The handler function for the 'diff_with_ref' tool. It computes the git diff between the specified ref and HEAD for the given project, ignoring blank lines and space at EOL, and returns the diff as MCPToolOutput with character limit.def diff_with_ref( project_name: str, ref: Annotated[str, Field(max_length=100)], ) -> ToolResponse: """Return a summary of the diff between HEAD and the given ref. You probably want the ref to be the 'base' branch like develop or main, off which PRs are made - and you can likely determine this by viewing the most recently checked out branches. """ project = _get_project_or_error(project_name) repo = Repo(project.git_path) # head = repo.head.commit # compare_from = repo.commit(ref) # diffs = compare_from.diff(head, create_patch=True) # print(repo.git.diff(f"{ref}s...HEAD", ignore_blank_lines=True, ignore_space_at_eol=True)) diff = repo.git.diff( f"{ref}...HEAD", ignore_blank_lines=True, ignore_space_at_eol=True, ) return MCPToolOutput( text=diff, max_chars=deps.settings().default_git_diff_response_max_chars, ).render()
- mcpunk/tools.py:429-430 (registration)MCP tool registration via @mcp.tool() decorator, with additional logging decorator.@mcp.tool() @log_inputs_outputs()
- mcpunk/tools.py:431-434 (schema)Input schema defined via type annotations and Annotated Field for parameters.def diff_with_ref( project_name: str, ref: Annotated[str, Field(max_length=100)], ) -> ToolResponse: