-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add include_sha parameter to get_file_contents tool #605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add include_sha parameter to get_file_contents tool #605
Conversation
- Add include_sha boolean parameter to control metadata vs raw content retrieval - When include_sha=true, always use GitHub Contents API to ensure SHA is returned - When include_sha=false (default), maintain existing behavior with raw content preference - Unify GitHub API processing to handle both files and directories consistently - Improve error handling and fallback logic for better reliability - Update tool description and parameter documentation - Update toolsnap test file to reflect new parameter This enhancement allows users to reliably obtain file metadata (SHA, size, type) regardless of file size, while maintaining backward compatibility with existing clients.
Add optional boolean parameter to retrieve file metadata instead of raw content. When include_sha=true, returns SHA, size, and other metadata via GitHub Contents API. Maintains backward compatibility and performance with Raw API as default. - Add include_sha parameter with comprehensive test coverage - Support metadata retrieval for both files and directories - Update tool description and schema validation
There was a problem hiding this 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 an optional include_sha parameter to the get_file_contents tool, allowing users to choose between fast raw content retrieval and detailed file metadata (including SHA) needed for file update operations.
- Introduce the include_sha boolean parameter to the tool schema and update its description.
- Modify the API call logic to conditionally use either the raw content or the GitHub Contents API based on the include_sha value.
- Update tests and snapshots to cover the new include_sha functionality.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
pkg/github/repositories_test.go | Added schema check for include_sha and new test cases for both metadata and raw content fetching. |
pkg/github/repositories.go | Extended tool description, added the include_sha parameter, and updated API call flow and error handling accordingly. |
pkg/github/toolsnaps/get_file_contents.snap | Updated snapshot description and schema to include the new include_sha parameter. |
Comments suppressed due to low confidence (1)
pkg/github/repositories.go:529
- [nitpick] Consider adding an inline comment explaining why the raw content API call is skipped when include_sha is true, to improve future maintainability and clarity.
if !includeSha && path != "" && !strings.HasSuffix(path, "/") {
This reverts commit f891c92.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yonaka15, thank you for your PR, returning the SHA will be useful! :)
We recommend the following changes:
- Not adding a new argument
include_sha
, but always returning a file's SHA - For files, always return a resource. The SHA can be included with the text output of the tool result but the file should be a resource. This is done on repositories.go#L566-L578
So overall, the flow for files can look like:
- First, get the SHA if not provided as a tool input. For this you can use a cheaper method, like we do for PRs (repositories.go#L516) instead of the file API.
- Then, download the file using
rawClient.GetRawContent
, providing the SHA (to avoid a race condition). This is already done on repositories.go#L531 - Return a
NewToolResultResource
with the file as a resource and a json message containing the SHA. i.e. You can update the "successfully downloaded text file" / "successfully downloaded binary file" text part of the tool result but keep theTextResourceContents
/BlobResourceContents
in repositories.go#L566-L578
Thank you, we look forward to your response!
Summary
This PR addresses issue #595 by adding an optional
include_sha
parameter to theget_file_contents
tool, providing a more flexible and performant solution than the previous approach in PR #599.Problem
The
get_file_contents
tool was missing the SHA hash in its response, which is essential for subsequent file update operations usingcreate_or_update_file
. The SHA is required by the GitHub API for any update operation.Solution
Instead of always returning metadata (as in PR #599), this PR adds an
include_sha
boolean parameter that allows users to explicitly choose between:Key Features
Usage Examples
Changes Made
include_sha
boolean parameter to tool schemaTesting
Supersedes
This PR supersedes #599 by providing a more user-friendly and performant solution to the same problem.
Closes #595
Supersedes #599