Skip to content

Commit 796afb7

Browse files
fix(repos): return a resource link for files over 1 MB in get_file_contents (#3419)
The Contents API returns files over 1 MB with an empty content field and encoding "none". Since the symlink read checks, get_file_contents tried to decode that content and failed with "unsupported content encoding: none" before reaching the large-file branch. Treat that response as content not available so the tool returns the resource link again. Co-authored-by: Iryna Kulakova <52420926+IrynaKulakova@users.noreply.github.com>
1 parent c59e8c1 commit 796afb7

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎pkg/github/repositories_helper.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ func inspectRepositoryFile(ctx context.Context, client *github.Client, owner, re
214214
}
215215

216216
func repositoryContentBytes(file *github.RepositoryContent) ([]byte, bool, error) {
217-
if file.Content == nil {
217+
// Files over 1 MB come back with encoding "none" and no content.
218+
if file.Content == nil || file.GetEncoding() == "none" {
218219
return []byte{}, file.GetType() != "symlink" && file.GetSize() == 0, nil
219220
}
220221
content, err := file.GetContent()

‎pkg/github/repositories_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,22 @@ func Test_GetFileContents_ContentlessRequestCounts(t *testing.T) {
795795
require.True(t, ok)
796796
})
797797

798+
t.Run("large file with encoding none", func(t *testing.T) {
799+
result, requests := runRepositoryReadFixture(t, repositoryReadFixture{
800+
contents: &github.RepositoryContent{
801+
Type: new("file"), Path: new("large.bin"), SHA: new(fileSHA), Size: new(largeSize),
802+
Content: new(""), Encoding: new("none"),
803+
},
804+
trees: map[string]*github.Tree{commitSHA: {Entries: []*github.TreeEntry{
805+
{Path: new("large.bin"), Mode: new("100644"), Type: new("blob"), SHA: new(fileSHA)},
806+
}}},
807+
}, args("large.bin"))
808+
require.False(t, result.IsError)
809+
assert.Equal(t, 2, requests)
810+
_, ok := result.Content[1].(*mcp.ResourceLink)
811+
require.True(t, ok)
812+
})
813+
798814
t.Run("internal large link uses exact-path tree descent", func(t *testing.T) {
799815
target := "../target.bin"
800816
linkSHA := gitBlobSHA([]byte(target))

0 commit comments

Comments
 (0)