@@ -84,16 +84,13 @@ func Test_GetFileContents(t *testing.T) {
8484 GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , "{\" name\" : \" repo\" , \" default_branch\" : \" main\" }" ),
8585 GetReposContentsByOwnerByRepoByPath : func (w http.ResponseWriter , _ * http.Request ) {
8686 w .WriteHeader (http .StatusOK )
87- // Base64 encode the content as GitHub API does
88- encodedContent := base64 .StdEncoding .EncodeToString (mockRawContent )
8987 fileContent := & github.RepositoryContent {
90- Name : github .Ptr ("README.md" ),
91- Path : github .Ptr ("README.md" ),
92- SHA : github .Ptr ("abc123" ),
93- Type : github .Ptr ("file" ),
94- Content : github .Ptr (encodedContent ),
95- Size : github .Ptr (len (mockRawContent )),
96- Encoding : github .Ptr ("base64" ),
88+ Name : github .Ptr ("README.md" ),
89+ Path : github .Ptr ("README.md" ),
90+ SHA : github .Ptr ("abc123" ),
91+ Type : github .Ptr ("file" ),
92+ Content : github .Ptr (string (mockRawContent )),
93+ Size : github .Ptr (len (mockRawContent )),
9794 }
9895 contentBytes , _ := json .Marshal (fileContent )
9996 _ , _ = w .Write (contentBytes )
@@ -144,7 +141,7 @@ func Test_GetFileContents(t *testing.T) {
144141 expectError : false ,
145142 expectedResult : mcp.ResourceContents {
146143 URI : "repo://owner/repo/refs/heads/main/contents/test.png" ,
147- Blob : []byte (base64 . StdEncoding . EncodeToString ([] byte ( "\x89 PNG\r \n \x1a \n \x00 \x00 \x00 \r IHDR\x00 \x00 \x00 \x01 " )) ),
144+ Blob : []byte ("\x89 PNG\r \n \x1a \n \x00 \x00 \x00 \r IHDR\x00 \x00 \x00 \x01 " ),
148145 MIMEType : "image/png" ,
149146 },
150147 },
@@ -180,7 +177,7 @@ func Test_GetFileContents(t *testing.T) {
180177 expectError : false ,
181178 expectedResult : mcp.ResourceContents {
182179 URI : "repo://owner/repo/refs/heads/main/contents/document.pdf" ,
183- Blob : []byte (base64 . StdEncoding . EncodeToString ([] byte ( "%PDF-1.4 fake pdf content" )) ),
180+ Blob : []byte ("%PDF-1.4 fake pdf content" ),
184181 MIMEType : "application/pdf" ,
185182 },
186183 },
@@ -449,6 +446,37 @@ func Test_GetFileContents(t *testing.T) {
449446 resource := getResourceResult (t , result )
450447 assert .Equal (t , expected , * resource )
451448
449+ wireBytes , err := json .Marshal (result )
450+ require .NoError (t , err )
451+ var wireResult struct {
452+ Content []struct {
453+ Type string `json:"type"`
454+ Resource * struct {
455+ MIMEType string `json:"mimeType"`
456+ Text string `json:"text"`
457+ Blob string `json:"blob"`
458+ } `json:"resource"`
459+ } `json:"content"`
460+ }
461+ require .NoError (t , json .Unmarshal (wireBytes , & wireResult ))
462+ require .Len (t , wireResult .Content , 2 )
463+ require .Equal (t , "resource" , wireResult .Content [1 ].Type )
464+ require .NotNil (t , wireResult .Content [1 ].Resource )
465+ wireResource := wireResult .Content [1 ].Resource
466+ require .Equal (t , expected .MIMEType , wireResource .MIMEType )
467+
468+ if expected .Blob != nil {
469+ decodedBlob , err := base64 .StdEncoding .DecodeString (wireResource .Blob )
470+ require .NoError (t , err )
471+ require .Equal (t , expected .Blob , decodedBlob )
472+ if expected .MIMEType == "image/png" {
473+ require .True (t , strings .HasPrefix (string (decodedBlob ), "\x89 PNG\r \n \x1a \n " ))
474+ }
475+ } else {
476+ require .Empty (t , wireResource .Blob )
477+ require .Equal (t , expected .Text , wireResource .Text )
478+ }
479+
452480 // If expectedMsg is set, verify the message text
453481 if tc .expectedMsg != "" {
454482 require .Len (t , result .Content , 2 )
0 commit comments