Skip to content

Conversation

@almaleksia
Copy link
Contributor

Summary

This PR improves ref resolution handling in get_file_contents tool.

  1. Sometimes LLM passes sha in ref parameter which results in failure. This PR autocorrects it allowing shas to be passed as refs.
  2. Return custom errors when tool tried to resolve main branch and failed - suggest to try master instead.

Why

We have lots of errors like failed to resolve git reference: could not resolve ref "50e4e8b9178ca5c4e3c60d0022b3b041cc58c188" as a branch or a tag

Which means sha is passed as ref, this change aims to decrease amounts of such failures.

What changed

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

Prompts tested (tool changes only)

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

@almaleksia almaleksia requested a review from a team as a code owner December 19, 2025 13:59
Copilot AI review requested due to automatic review settings December 19, 2025 13:59
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 enhances the get_file_contents tool's ref resolution by auto-detecting Git commit SHAs passed in the ref parameter and providing clearer error messages when the 'main' branch is not found.

  • Adds looksLikeSHA() function to detect full 40-character commit SHAs and bypass branch/tag resolution
  • Implements custom error messages suggesting 'master' when 'main' branch is not found
  • Adds comprehensive test coverage for the SHA detection logic

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
pkg/github/repositories.go Adds looksLikeSHA() helper function and integrates SHA detection into resolveGitReference(); adds custom error messages for missing 'main' branch
pkg/github/repositories_test.go Adds unit tests for looksLikeSHA() function and integration tests for SHA-based ref resolution in Test_resolveGitReference()

@almaleksia almaleksia force-pushed the almaleksia/get_file_contents-fetch-refs-improvements branch from 8988b78 to f76807b Compare December 19, 2025 14:04
@almaleksia almaleksia changed the title Almaleksia/get file contents fetch refs improvements get_file_contents fetch refs improvements Dec 19, 2025
Copy link
Contributor

@mattdholloway mattdholloway left a comment

Choose a reason for hiding this comment

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

looks great! looksLikeSHA is a really good idea

Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums left a comment

Choose a reason for hiding this comment

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

Very nice. Out of interest, do we have a way of looking up the default ref? And should we just try master or versa and just say what we did as part of the response? I guess it's just how things are that we need heuristics like this. But higher % success of achieving actual intent feels reasonable.

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.

4 participants