@@ -13,6 +13,7 @@ import (
1313 "github.com/github/github-mcp-server/v2/internal/githubv4mock"
1414 "github.com/github/github-mcp-server/v2/internal/requeststate"
1515 "github.com/github/github-mcp-server/v2/internal/toolsnaps"
16+ ghcontext "github.com/github/github-mcp-server/v2/pkg/context"
1617 "github.com/github/github-mcp-server/v2/pkg/inventory"
1718 "github.com/github/github-mcp-server/v2/pkg/raw"
1819 "github.com/github/github-mcp-server/v2/pkg/translations"
@@ -40,6 +41,7 @@ type repositoryReadFixture struct {
4041 blobs map [string ][]byte
4142 trees map [string ]* github.Tree
4243 inspect func (* http.Request )
44+ ctx context.Context
4345}
4446
4547func runRepositoryReadFixture (t * testing.T , fixture repositoryReadFixture , args map [string ]any ) (* mcp.CallToolResult , int ) {
@@ -73,7 +75,11 @@ func runRepositoryReadFixture(t *testing.T, fixture repositoryReadFixture, args
7375 tool := GetFileContents (translations .NullTranslationHelper )
7476 handler := tool .Handler (deps )
7577 request := createMCPRequest (args )
76- result , err := handler (ContextWithDeps (context .Background (), deps ), & request )
78+ ctx := fixture .ctx
79+ if ctx == nil {
80+ ctx = context .Background ()
81+ }
82+ result , err := handler (ContextWithDeps (ctx , deps ), & request )
7783 require .NoError (t , err )
7884 return result , counter .count
7985}
@@ -772,6 +778,39 @@ func Test_GetFileContents_SymlinkDisclosure(t *testing.T) {
772778 })
773779}
774780
781+ func Test_GetFileContents_ModernProtocolInlineLimit (t * testing.T ) {
782+ commitSHA := strings .Repeat ("c" , 40 )
783+ content := strings .Repeat ("a" , 600 * 1024 )
784+ encoded := base64 .StdEncoding .EncodeToString ([]byte (content ))
785+ fileSHA := gitBlobSHA ([]byte (content ))
786+ args := map [string ]any {"owner" : "owner" , "repo" : "repo" , "path" : "medium.txt" , "sha" : commitSHA }
787+
788+ fixture := repositoryReadFixture {
789+ contents : & github.RepositoryContent {
790+ Type : new ("file "), Path : new ("medium.txt "), SHA : new (fileSHA ), Size : new (len (content )),
791+ Content : new (encoded ), Encoding : new ("base64 "),
792+ },
793+ }
794+
795+ t .Run ("legacy protocol inlines the file" , func (t * testing.T ) {
796+ result , _ := runRepositoryReadFixture (t , fixture , args )
797+ require .False (t , result .IsError )
798+ _ , ok := result .Content [1 ].(* mcp.EmbeddedResource )
799+ require .True (t , ok , "expected an inline resource on the legacy protocol" )
800+ })
801+
802+ t .Run ("modern protocol returns a ResourceLink" , func (t * testing.T ) {
803+ modern := fixture
804+ modern .ctx = ghcontext .WithMCPMethodInfo (context .Background (), & ghcontext.MCPMethodInfo {
805+ ProtocolVersion : inventory .ProtocolVersionMultiRoundTrip ,
806+ })
807+ result , _ := runRepositoryReadFixture (t , modern , args )
808+ require .False (t , result .IsError )
809+ _ , ok := result .Content [1 ].(* mcp.ResourceLink )
810+ require .True (t , ok , "expected a ResourceLink on the modern protocol" )
811+ })
812+ }
813+
775814func Test_GetFileContents_ContentlessRequestCounts (t * testing.T ) {
776815 commitSHA := strings .Repeat ("c" , 40 )
777816 fileSHA := strings .Repeat ("a" , 40 )
0 commit comments