Skip to content

Conversation

@almaleksia
Copy link
Contributor

Adds server instructions for repos toolset that tells a model to retrieve file sha before updating it. This should help decrease the amount of "sha" wasn't supplied. errors.

@almaleksia almaleksia requested a review from a team as a code owner December 12, 2025 14:07
Copilot AI review requested due to automatic review settings December 12, 2025 14:07
Copy link
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 server instructions for the repos toolset to guide AI models to retrieve the file SHA before updating files, which should reduce "sha" wasn't supplied errors. The instruction tells models to call get_file_contents first to get the SHA, then use it in the create_or_update_file call.

Key changes:

  • Added a new case for "repos" in the getToolsetInstructions switch statement that provides guidance on the file update workflow

case "repos":
return `## Repositories
Before updating an existing file, always call 'get_file_contents' to retrieve the SHA of the file blob. Use this SHA as the "sha" parameter in create_or_update_file tool call to avoid conflicts.
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Missing article "the" before "create_or_update_file tool call". The phrase should read "in the create_or_update_file tool call" for grammatical correctness.

Suggested change
Before updating an existing file, always call 'get_file_contents' to retrieve the SHA of the file blob. Use this SHA as the "sha" parameter in create_or_update_file tool call to avoid conflicts.
Before updating an existing file, always call 'get_file_contents' to retrieve the SHA of the file blob. Use this SHA as the "sha" parameter in the create_or_update_file tool call to avoid conflicts.

Copilot uses AI. Check for mistakes.
return `## Repositories
Before updating an existing file, always call 'get_file_contents' to retrieve the SHA of the file blob. Use this SHA as the "sha" parameter in create_or_update_file tool call to avoid conflicts.
`
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Trailing whitespace (tabs) should be removed for consistency. Most other instruction blocks don't have trailing whitespace on their closing lines.

Copilot uses AI. Check for mistakes.
@SamMorrowDrums
Copy link
Collaborator

SamMorrowDrums commented Dec 12, 2025

Nice addition! One thought on the blob SHA requirement:

Since blob SHAs are deterministic (just sha1("blob " + size + "\0" + content)), the model could calculate them client-side for the original file version too. This would enable using mcp_github_create_or_update_file even without git access to the repository.

Workflow:

  1. Model reads current file
  2. Calculates blob SHA locally: sha1("blob " + content.length + "\0" + content)
  3. Calls mcp_github_create_or_update_file with calculated SHA
  4. If SHA mismatch (file changed), API returns clear error and model can retry

This way the tool is useful in more scenarios - not just when you have a local git clone. The model can work entirely through GitHub API when needed.

@almaleksia
Copy link
Contributor Author

@SamMorrowDrums I'd prefer to go with simpler version first and look how it affected error rates. We can improve on it later

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.

3 participants