Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
45 changes: 45 additions & 0 deletions pkg/github/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading