Skip to content

Fix: Specify sha is required for file update #320

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crondinini
Copy link

Closes: #191

The problem

When the LLM sends an update_file request, it doesn't include the sha of the file being replaced, leading to the error:

Failed to call tool create_or_update_file: Error: MCP error -32603: failed to https://api.github.com/repos/evanmcgillivray/Budget/contents/src/components
422 Invalid request. "sha" wasn't supplied. []

This happens because sha is an optional field since the same tool is used for both create and update file operations.

The solution

I did some local testing and the issue seems to be fixed if we specify in the tool description that sha is required when updating a file.

However, a more robust solution might be to split the tool into 2 separate tools and and make a new update_file tool that has a required sha property.

I wasn't sure which approach would be preferred, so I've decided to put forward the simplest solution that works to hear your feedback.

@Copilot Copilot AI review requested due to automatic review settings April 21, 2025 08:10
@crondinini crondinini requested a review from a team as a code owner April 21, 2025 08:10
Copy link
Contributor

@Copilot 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 updates the tool description for file operations to indicate that a SHA is required when updating a file.

  • Updated the tool description for create_or_update_file.
  • Clarified that the SHA field must be provided when updating a file.

@@ -216,7 +216,7 @@ func ListBranches(getClient GetClientFn, t translations.TranslationHelperFunc) (
// CreateOrUpdateFile creates a tool to create or update a file in a GitHub repository.
func CreateOrUpdateFile(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("create_or_update_file",
mcp.WithDescription(t("TOOL_CREATE_OR_UPDATE_FILE_DESCRIPTION", "Create or update a single file in a GitHub repository")),
mcp.WithDescription(t("TOOL_CREATE_OR_UPDATE_FILE_DESCRIPTION", "Create or update a single file in a GitHub repository. If updating, you must provide the SHA of the file you want to update.")),
Copy link
Preview

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

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

The updated tool description indicates that a SHA is required when updating a file, but there is no validation enforcing this constraint. Consider adding a check to ensure that the SHA field is provided when processing an update.

Copilot uses AI. Check for mistakes.

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.

MCP Error -32603: 422 Invalid request - 'sha' wasn't supplied when updating file
1 participant