Skip to content

feat: add get_file_blame tool for retrieving git blame information#1538

Open
MayorFaj wants to merge 5 commits into
github:mainfrom
MayorFaj:feat/git-blame-tool
Open

feat: add get_file_blame tool for retrieving git blame information#1538
MayorFaj wants to merge 5 commits into
github:mainfrom
MayorFaj:feat/git-blame-tool

Conversation

@MayorFaj
Copy link
Copy Markdown
Contributor

@MayorFaj MayorFaj commented Dec 4, 2025

This pull request adds a new tool for retrieving git blame information for files in a GitHub repository, along with comprehensive tests and documentation updates. The main focus is on enabling users to see who last modified each line in a file, with support for specifying branches, tags, or commit SHAs.

New Git Blame Tool Integration

  • Added the get_file_blame tool to the codebase, which uses the GitHub GraphQL API to fetch blame information for a file, including author details, commit SHA, message, and line ranges. The tool supports specifying the repository owner, name, file path, and git reference, defaulting to the repository's default branch if not provided. (pkg/github/repositories.go)
  • Registered the new get_file_blame tool in the default toolset group so it is available for use alongside other repository tools. (pkg/github/tools.go)

Documentation and Tool Snapshots

  • Updated README.md to document the new get_file_blame tool, including its parameters and usage.
  • Added a tool snapshot definition for get_file_blame for validation and testing purposes. (pkg/github/__toolsnaps__/get_file_blame.snap)
Screenshot 2025-12-04 at 18 09 06 Screenshot 2025-12-04 at 18 11 28

Closes: #504

Copilot AI review requested due to automatic review settings December 4, 2025 18:26
@MayorFaj MayorFaj requested a review from a team as a code owner December 4, 2025 18:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new get_file_blame tool that enables users to retrieve git blame information for files in GitHub repositories using the GraphQL API. The implementation includes comprehensive test coverage, proper error handling, and complete documentation updates.

Key Changes

  • Added GetFileBlame function that queries GitHub's GraphQL API to retrieve blame information showing who last modified each line of a file
  • Integrated the new tool into the default toolset alongside other repository management tools
  • Created comprehensive unit tests covering successful operations, error scenarios, and edge cases like missing default branches

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/github/repositories.go Implements the GetFileBlame tool with GraphQL queries for default branch resolution and blame data retrieval, including proper type conversions and JSON response formatting
pkg/github/tools.go Registers GetFileBlame in the DefaultToolsetGroup for availability in the standard tool collection
pkg/github/repositories_test.go Adds comprehensive test coverage including tool schema validation, default branch handling, specific ref queries, and error scenarios
pkg/github/toolsnaps/get_file_blame.snap Tool schema snapshot documenting the API surface with ReadOnly annotation
README.md Documents the new tool with parameter descriptions and usage information

@MayorFaj MayorFaj marked this pull request as draft December 4, 2025 18:36
@MayorFaj MayorFaj force-pushed the feat/git-blame-tool branch from 1222293 to 8e494d9 Compare December 4, 2025 19:15
@MayorFaj MayorFaj marked this pull request as ready for review December 4, 2025 19:16
@MayorFaj
Copy link
Copy Markdown
Contributor Author

MayorFaj commented Dec 5, 2025

cc @SamMorrowDrums, @JoannaaKL

@gallejesus
Copy link
Copy Markdown

Just wanted to add a +1 to this PR! 👍

Having a git blame tool would be incredibly helpful for giving AI agents much better context. I understand you are busy, but I would love to see this merged when a maintainer has some bandwidth.

Thanks for the hard work!

@JoannaaKL
Copy link
Copy Markdown
Contributor

Hi @MayorFaj could you please resolve conflicts in this pr? :)

MayorFaj and others added 2 commits May 12, 2026 12:25
# Conflicts:
#	docs/remote-server.md
#	pkg/github/repositories_test.go
#	pkg/github/tools.go
@MayorFaj
Copy link
Copy Markdown
Contributor Author

Hi @MayorFaj could you please resolve conflicts in this pr? :)

Hi @JoannaaKL , conflicts resolved

Copy link
Copy Markdown
Contributor

@JoannaaKL JoannaaKL 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 adding this tool — blame support is a great addition! I have a few concerns I'd love to see addressed:

  1. Redundant GraphQL call for default branch: When ref is empty, there's a separate query just to fetch the default branch before the blame query. Please consider using HEAD as the expression or combining both into a single query to avoid the extra round-trip.

  2. No pagination or size limit: A blame response for a large file (thousands of lines) could produce a massive JSON payload that blows past MCP response size limits or LLM context windows. Please add some form of truncation or line-range filtering — other tools in this codebase handle pagination, and this one should too.

  3. No validation that object resolved to a Commit: If the ref expression resolves to a Tree or Blob, the ... on Commit fragment silently returns zero data and the tool returns an empty ranges array with no error. Let's add a nil/empty check on the commit object with a meaningful error message so users aren't left guessing.

  4. No validation on path input: The path parameter is passed directly into the GraphQL query with no sanitization. Please add checks for empty strings, absolute paths, or path traversal patterns (../) — other tools in the codebase validate their path inputs.

  5. Inline struct types: BlameRange and BlameResult are defined inside the handler closure. Let's move these to package-level types, consistent with how other tools structure their response types — it makes them testable and reusable.

  6. age field is opaque: The age integer from GitHub's GraphQL API represents relative age compared to other ranges, not an absolute value. Please add some documentation in the tool description or response so an LLM consuming this doesn't misinterpret it.

  7. Commit message not truncated: Full commit messages (including multi-line bodies) are included for every blame range. For a file with many ranges, this creates enormous redundant output — the same commit message repeated for every range it touches. Please consider including only the first line (subject), or deduplicating commits into a separate section.

  8. e2e test changes are unrelated: The e2e/e2e_test.go changes (NewMCPServerNewStdioMCPServer, adding Version, Logger) look like merge conflict resolution artifacts. Let's clean these up with a rebase so the PR diff only contains blame-related changes.

  9. Missing newline at end of snap file: get_file_blame.snap is missing a trailing newline — minor, but please add one to avoid noisy diffs later.

  10. No test for empty blame ranges: There's no test case for when the blame query returns successfully but with zero ranges (e.g., empty file). Please add one to verify the response structure is still valid in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git blame tool (to get the latest contributors of the class)

5 participants