From 807bb923fce569dcdb1a38c96e2773478e490f11 Mon Sep 17 00:00:00 2001 From: kerobbi Date: Mon, 6 Oct 2025 17:02:26 +0100 Subject: [PATCH 1/3] tighten content filtering logic --- pkg/github/repositories.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 0622f3101..c84512461 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -601,7 +601,13 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t } } - if strings.HasPrefix(contentType, "application") || strings.HasPrefix(contentType, "text") { + // Determine if content is text or binary + isTextContent := strings.HasPrefix(contentType, "text/") || + contentType == "application/json" || + strings.HasSuffix(contentType, "+json") || + strings.HasSuffix(contentType, "+xml") + + if isTextContent { result := mcp.TextResourceContents{ URI: resourceURI, Text: string(body), From e9277362c2f7cc1327bbf988c3bff7cc53575f96 Mon Sep 17 00:00:00 2001 From: kerobbi Date: Mon, 6 Oct 2025 17:04:02 +0100 Subject: [PATCH 2/3] add pdf retrieval test case --- pkg/github/repositories_test.go | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 11f11493c..22014148d 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -157,6 +157,51 @@ func Test_GetFileContents(t *testing.T) { MIMEType: "image/png", }, }, + { + name: "successful PDF file content fetch", + mockedClient: mock.NewMockedHTTPClient( + mock.WithRequestMatchHandler( + mock.GetReposGitRefByOwnerByRepoByRef, + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"ref": "refs/heads/main", "object": {"sha": ""}}`)) + }), + ), + mock.WithRequestMatchHandler( + mock.GetReposContentsByOwnerByRepoByPath, + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + fileContent := &github.RepositoryContent{ + Name: github.Ptr("document.pdf"), + Path: github.Ptr("document.pdf"), + SHA: github.Ptr("pdf123"), + Type: github.Ptr("file"), + } + contentBytes, _ := json.Marshal(fileContent) + _, _ = w.Write(contentBytes) + }), + ), + mock.WithRequestMatchHandler( + raw.GetRawReposContentsByOwnerByRepoByBranchByPath, + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/pdf") + _, _ = w.Write(mockRawContent) + }), + ), + ), + requestArgs: map[string]interface{}{ + "owner": "owner", + "repo": "repo", + "path": "document.pdf", + "ref": "refs/heads/main", + }, + expectError: false, + expectedResult: mcp.BlobResourceContents{ + URI: "repo://owner/repo/refs/heads/main/contents/document.pdf", + Blob: base64.StdEncoding.EncodeToString(mockRawContent), + MIMEType: "application/pdf", + }, + }, { name: "successful directory content fetch", mockedClient: mock.NewMockedHTTPClient( From 75a6dddc406b737143b7467491c3bb1bd4834bff Mon Sep 17 00:00:00 2001 From: kerobbi Date: Mon, 6 Oct 2025 17:16:57 +0100 Subject: [PATCH 3/3] add application/xml check --- pkg/github/repositories.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index c84512461..dfd718f7e 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -604,6 +604,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t // Determine if content is text or binary isTextContent := strings.HasPrefix(contentType, "text/") || contentType == "application/json" || + contentType == "application/xml" || strings.HasSuffix(contentType, "+json") || strings.HasSuffix(contentType, "+xml")