Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(tools): Ensure get_file_contents returns file SHA#599

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
yonaka15 wants to merge2 commits intogithub:main
base:main
Choose a base branch
Loading
fromyonaka15:fix/get-file-contents-sha

Conversation

yonaka15
Copy link

This PR addresses the issue where theget_file_contents tool fails to return the SHA hash of the file content. The SHA is a crucial piece of metadata, especially for subsequent update operations which require it.

  • What was the problem?
    Theget_file_contents tool's response struct did not include thesha field from the GitHub API response, making it impossible to get a file's SHA through the tool. This breaks workflows that need to read a file and then update it, ascreate_or_update_file requires the blob's SHA.

  • How does this PR fix it?
    TheFileContent struct inpkg/github/content.go has been updated to include theSHA field. TheGetFileContents function now correctly populates this field from the GitHub API response.

  • Verification
    This change was manually verified in a sandbox environment. By calling theget_file_contents tool via the@modelcontextprotocol/inspector, I confirmed that the JSON response now correctly includes the"sha" key and its corresponding value.

This change is backward-compatible as it only adds a field to the response.

Fixes#595

The previous implementation of `get_file_contents` had two issues:1. When fetching a file, it used the raw content endpoint, which does not provide the file's SHA.2. When fetching a directory, it returned a raw JSON array, which was not easily parsable by the agent.This commit refactors the `get_file_contents` tool to always use the `client.Repositories.GetContents` method. This method returns a `RepositoryContent` object (or a slice of them for directories), which always includes the SHA and other metadata.The function now marshals this object (or slice) into a JSON string, providing a consistent and parsable output that includes the necessary SHA for subsequent file operations.
@CopilotCopilotAI review requested due to automatic review settingsJune 27, 2025 08:56
@yonaka15yonaka15 requested a review froma team as acode ownerJune 27, 2025 08:56
Copy link
Contributor

@CopilotCopilotAI 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 ensures theget_file_contents tool includes the file SHA in its response and cleans up the implementation. Key changes include:

  • Added thesha field to theFileContent struct and propagate it throughGetFileContents.
  • Removed the raw content fallback logic for simplicity.
  • Standardized error handling usingfmt.Errorf and GitHub API error wrappers.
Comments suppressed due to low confidence (4)

pkg/github/repositories.go:550

  • Now that SHA is included in theresult, consider adding automated tests to verify thatGetFileContents properly populatessha for file responses and that directory responses remain unchanged.
r, err := json.Marshal(result)

pkg/github/repositories.go:515

  • This return uses a genericfmt.Errorf instead of wrapping the error in an MCP tool result (e.g.,mcp.NewToolResultError). Consider returning a consistentToolResult error so callers receive the standardized error structure.
return nil, fmt.Errorf("failed to get GitHub client: %w", err)

pkg/github/repositories.go:536

  • Similar to the client error above, this returns a rawfmt.Errorf. To maintain consistent tool output, wrap this inmcp.NewToolResultError instead of returning a plain error.
return nil, fmt.Errorf("failed to read response body: %w", err)

pkg/github/repositories.go:552

  • This marshal error is returned as a plain error. For uniform tool behavior, returnmcp.NewToolResultError with the error message.
return nil, fmt.Errorf("failed to marshal response: %w", err)

@SamMorrowDrums
Copy link
Collaborator

SamMorrowDrums commentedJun 27, 2025
edited
Loading

Hey thanks for contribution. I want to highlight that this removes the resource response and regresses lots of improvements in the file handling (you don't get a proper mime type from the API for example). The file API is jst not the same.

We can look at adding more than one bit of response content adding an API call too (possibly with a param), and returning the SHA part of the response., I agree it is useful (the reasons you specify are real), but while you have been very focused on what you wanted to add, you have removed things that make the tool faster and more flexible for other use cases.

I will need to think about this a bit more, but it will not be able to merged in the current state.

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

Copilot code reviewCopilotCopilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Toolget_file_contents is missing the requiredsha in its response
2 participants
@yonaka15@SamMorrowDrums

[8]ページ先頭

©2009-2025 Movatter.jp