@@ -78,19 +78,20 @@ func Test_GetFileContents(t *testing.T) {
7878 GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , "{\" name\" : \" repo\" , \" default_branch\" : \" main\" }" ),
7979 GetReposContentsByOwnerByRepoByPath : func (w http.ResponseWriter , _ * http.Request ) {
8080 w .WriteHeader (http .StatusOK )
81+ // Base64 encode the content as GitHub API does
82+ encodedContent := base64 .StdEncoding .EncodeToString (mockRawContent )
8183 fileContent := & github.RepositoryContent {
82- Name : github .Ptr ("README.md" ),
83- Path : github .Ptr ("README.md" ),
84- SHA : github .Ptr ("abc123" ),
85- Type : github .Ptr ("file" ),
84+ Name : github .Ptr ("README.md" ),
85+ Path : github .Ptr ("README.md" ),
86+ SHA : github .Ptr ("abc123" ),
87+ Type : github .Ptr ("file" ),
88+ Content : github .Ptr (encodedContent ),
89+ Size : github .Ptr (len (mockRawContent )),
90+ Encoding : github .Ptr ("base64" ),
8691 }
8792 contentBytes , _ := json .Marshal (fileContent )
8893 _ , _ = w .Write (contentBytes )
8994 },
90- GetRawReposContentsByOwnerByRepoByBranchByPath : func (w http.ResponseWriter , _ * http.Request ) {
91- w .Header ().Set ("Content-Type" , "text/markdown" )
92- _ , _ = w .Write (mockRawContent )
93- },
9495 }),
9596 requestArgs : map [string ]interface {}{
9697 "owner" : "owner" ,
@@ -102,7 +103,7 @@ func Test_GetFileContents(t *testing.T) {
102103 expectedResult : mcp.ResourceContents {
103104 URI : "repo://owner/repo/refs/heads/main/contents/README.md" ,
104105 Text : "# Test Repository\n \n This is a test repository." ,
105- MIMEType : "text/markdown " ,
106+ MIMEType : "text/plain " ,
106107 },
107108 },
108109 {
@@ -112,19 +113,20 @@ func Test_GetFileContents(t *testing.T) {
112113 GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , "{\" name\" : \" repo\" , \" default_branch\" : \" main\" }" ),
113114 GetReposContentsByOwnerByRepoByPath : func (w http.ResponseWriter , _ * http.Request ) {
114115 w .WriteHeader (http .StatusOK )
116+ // Base64 encode the content as GitHub API does
117+ encodedContent := base64 .StdEncoding .EncodeToString (mockRawContent )
115118 fileContent := & github.RepositoryContent {
116- Name : github .Ptr ("test.png" ),
117- Path : github .Ptr ("test.png" ),
118- SHA : github .Ptr ("def456" ),
119- Type : github .Ptr ("file" ),
119+ Name : github .Ptr ("test.png" ),
120+ Path : github .Ptr ("test.png" ),
121+ SHA : github .Ptr ("def456" ),
122+ Type : github .Ptr ("file" ),
123+ Content : github .Ptr (encodedContent ),
124+ Size : github .Ptr (len (mockRawContent )),
125+ Encoding : github .Ptr ("base64" ),
120126 }
121127 contentBytes , _ := json .Marshal (fileContent )
122128 _ , _ = w .Write (contentBytes )
123129 },
124- GetRawReposContentsByOwnerByRepoByBranchByPath : func (w http.ResponseWriter , _ * http.Request ) {
125- w .Header ().Set ("Content-Type" , "image/png" )
126- _ , _ = w .Write (mockRawContent )
127- },
128130 }),
129131 requestArgs : map [string ]interface {}{
130132 "owner" : "owner" ,
@@ -135,8 +137,8 @@ func Test_GetFileContents(t *testing.T) {
135137 expectError : false ,
136138 expectedResult : mcp.ResourceContents {
137139 URI : "repo://owner/repo/refs/heads/main/contents/test.png" ,
138- Blob : mockRawContent ,
139- MIMEType : "image/png " ,
140+ Text : "# Test Repository \n \n This is a test repository." ,
141+ MIMEType : "text/plain " ,
140142 },
141143 },
142144 {
@@ -146,19 +148,20 @@ func Test_GetFileContents(t *testing.T) {
146148 GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , "{\" name\" : \" repo\" , \" default_branch\" : \" main\" }" ),
147149 GetReposContentsByOwnerByRepoByPath : func (w http.ResponseWriter , _ * http.Request ) {
148150 w .WriteHeader (http .StatusOK )
151+ // Base64 encode the content as GitHub API does
152+ encodedContent := base64 .StdEncoding .EncodeToString (mockRawContent )
149153 fileContent := & github.RepositoryContent {
150- Name : github .Ptr ("document.pdf" ),
151- Path : github .Ptr ("document.pdf" ),
152- SHA : github .Ptr ("pdf123" ),
153- Type : github .Ptr ("file" ),
154+ Name : github .Ptr ("document.pdf" ),
155+ Path : github .Ptr ("document.pdf" ),
156+ SHA : github .Ptr ("pdf123" ),
157+ Type : github .Ptr ("file" ),
158+ Content : github .Ptr (encodedContent ),
159+ Size : github .Ptr (len (mockRawContent )),
160+ Encoding : github .Ptr ("base64" ),
154161 }
155162 contentBytes , _ := json .Marshal (fileContent )
156163 _ , _ = w .Write (contentBytes )
157164 },
158- GetRawReposContentsByOwnerByRepoByBranchByPath : func (w http.ResponseWriter , _ * http.Request ) {
159- w .Header ().Set ("Content-Type" , "application/pdf" )
160- _ , _ = w .Write (mockRawContent )
161- },
162165 }),
163166 requestArgs : map [string ]interface {}{
164167 "owner" : "owner" ,
@@ -169,8 +172,8 @@ func Test_GetFileContents(t *testing.T) {
169172 expectError : false ,
170173 expectedResult : mcp.ResourceContents {
171174 URI : "repo://owner/repo/refs/heads/main/contents/document.pdf" ,
172- Blob : mockRawContent ,
173- MIMEType : "application/pdf " ,
175+ Text : "# Test Repository \n \n This is a test repository." ,
176+ MIMEType : "text/plain " ,
174177 },
175178 },
176179 {
@@ -200,19 +203,20 @@ func Test_GetFileContents(t *testing.T) {
200203 GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , "{\" name\" : \" repo\" , \" default_branch\" : \" main\" }" ),
201204 GetReposContentsByOwnerByRepoByPath : func (w http.ResponseWriter , _ * http.Request ) {
202205 w .WriteHeader (http .StatusOK )
206+ // Base64 encode the content as GitHub API does
207+ encodedContent := base64 .StdEncoding .EncodeToString (mockRawContent )
203208 fileContent := & github.RepositoryContent {
204- Name : github .Ptr ("README.md" ),
205- Path : github .Ptr ("README.md" ),
206- SHA : github .Ptr ("abc123" ),
207- Type : github .Ptr ("file" ),
209+ Name : github .Ptr ("README.md" ),
210+ Path : github .Ptr ("README.md" ),
211+ SHA : github .Ptr ("abc123" ),
212+ Type : github .Ptr ("file" ),
213+ Content : github .Ptr (encodedContent ),
214+ Size : github .Ptr (len (mockRawContent )),
215+ Encoding : github .Ptr ("base64" ),
208216 }
209217 contentBytes , _ := json .Marshal (fileContent )
210218 _ , _ = w .Write (contentBytes )
211219 },
212- GetRawReposContentsByOwnerByRepoByBranchByPath : func (w http.ResponseWriter , _ * http.Request ) {
213- w .Header ().Set ("Content-Type" , "text/markdown" )
214- _ , _ = w .Write (mockRawContent )
215- },
216220 }),
217221 requestArgs : map [string ]interface {}{
218222 "owner" : "owner" ,
@@ -224,7 +228,7 @@ func Test_GetFileContents(t *testing.T) {
224228 expectedResult : mcp.ResourceContents {
225229 URI : "repo://owner/repo/refs/heads/main/contents/README.md" ,
226230 Text : "# Test Repository\n \n This is a test repository." ,
227- MIMEType : "text/markdown " ,
231+ MIMEType : "text/plain " ,
228232 },
229233 },
230234 {
@@ -283,27 +287,20 @@ func Test_GetFileContents(t *testing.T) {
283287 },
284288 GetReposContentsByOwnerByRepoByPath : func (w http.ResponseWriter , _ * http.Request ) {
285289 w .WriteHeader (http .StatusOK )
290+ // Base64 encode the content as GitHub API does
291+ encodedContent := base64 .StdEncoding .EncodeToString (mockRawContent )
286292 fileContent := & github.RepositoryContent {
287- Name : github .Ptr ("README.md" ),
288- Path : github .Ptr ("README.md" ),
289- SHA : github .Ptr ("abc123" ),
290- Type : github .Ptr ("file" ),
293+ Name : github .Ptr ("README.md" ),
294+ Path : github .Ptr ("README.md" ),
295+ SHA : github .Ptr ("abc123" ),
296+ Type : github .Ptr ("file" ),
297+ Content : github .Ptr (encodedContent ),
298+ Size : github .Ptr (len (mockRawContent )),
299+ Encoding : github .Ptr ("base64" ),
291300 }
292301 contentBytes , _ := json .Marshal (fileContent )
293302 _ , _ = w .Write (contentBytes )
294303 },
295- "GET /owner/repo/refs/heads/develop/README.md" : func (w http.ResponseWriter , _ * http.Request ) {
296- w .Header ().Set ("Content-Type" , "text/markdown" )
297- _ , _ = w .Write (mockRawContent )
298- },
299- "GET /owner/repo/refs%2Fheads%2Fdevelop/README.md" : func (w http.ResponseWriter , _ * http.Request ) {
300- w .Header ().Set ("Content-Type" , "text/markdown" )
301- _ , _ = w .Write (mockRawContent )
302- },
303- "GET /owner/repo/abc123def456/README.md" : func (w http.ResponseWriter , _ * http.Request ) {
304- w .Header ().Set ("Content-Type" , "text/markdown" )
305- _ , _ = w .Write (mockRawContent )
306- },
307304 }),
308305 requestArgs : map [string ]interface {}{
309306 "owner" : "owner" ,
@@ -315,10 +312,43 @@ func Test_GetFileContents(t *testing.T) {
315312 expectedResult : mcp.ResourceContents {
316313 URI : "repo://owner/repo/abc123def456/contents/README.md" ,
317314 Text : "# Test Repository\n \n This is a test repository." ,
318- MIMEType : "text/markdown " ,
315+ MIMEType : "text/plain " ,
319316 },
320317 expectedMsg : " Note: the provided ref 'main' does not exist, default branch 'refs/heads/develop' was used instead." ,
321318 },
319+ {
320+ name : "large file returns ResourceLink" ,
321+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
322+ GetReposGitRefByOwnerByRepoByRef : mockResponse (t , http .StatusOK , "{\" ref\" : \" refs/heads/main\" , \" object\" : {\" sha\" : \" \" }}" ),
323+ GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , "{\" name\" : \" repo\" , \" default_branch\" : \" main\" }" ),
324+ GetReposContentsByOwnerByRepoByPath : func (w http.ResponseWriter , _ * http.Request ) {
325+ w .WriteHeader (http .StatusOK )
326+ // File larger than 1MB - Contents API returns metadata but no content
327+ fileContent := & github.RepositoryContent {
328+ Name : github .Ptr ("large-file.bin" ),
329+ Path : github .Ptr ("large-file.bin" ),
330+ SHA : github .Ptr ("largesha123" ),
331+ Type : github .Ptr ("file" ),
332+ Size : github .Ptr (2 * 1024 * 1024 ), // 2MB
333+ DownloadURL : github .Ptr ("https://raw.githubusercontent.com/owner/repo/main/large-file.bin" ),
334+ }
335+ contentBytes , _ := json .Marshal (fileContent )
336+ _ , _ = w .Write (contentBytes )
337+ },
338+ }),
339+ requestArgs : map [string ]interface {}{
340+ "owner" : "owner" ,
341+ "repo" : "repo" ,
342+ "path" : "large-file.bin" ,
343+ "ref" : "refs/heads/main" ,
344+ },
345+ expectError : false ,
346+ expectedResult : & mcp.ResourceLink {
347+ URI : "repo://owner/repo/refs/heads/main/contents/large-file.bin" ,
348+ Name : "large-file.bin" ,
349+ Title : "File: large-file.bin" ,
350+ },
351+ },
322352 {
323353 name : "content fetch fails" ,
324354 mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
@@ -395,6 +425,14 @@ func Test_GetFileContents(t *testing.T) {
395425 assert .Equal (t , * expected [i ].Path , * content .Path )
396426 assert .Equal (t , * expected [i ].Type , * content .Type )
397427 }
428+ case * mcp.ResourceLink :
429+ // Large file returns a ResourceLink
430+ require .Len (t , result .Content , 2 )
431+ resourceLink , ok := result .Content [1 ].(* mcp.ResourceLink )
432+ require .True (t , ok , "expected Content[1] to be ResourceLink" )
433+ assert .Equal (t , expected .URI , resourceLink .URI )
434+ assert .Equal (t , expected .Name , resourceLink .Name )
435+ assert .Equal (t , expected .Title , resourceLink .Title )
398436 case mcp.TextContent :
399437 textContent := getErrorResult (t , result )
400438 require .Equal (t , textContent , expected )
0 commit comments