diff --git a/pkg/github/repository_resource.go b/pkg/github/repository_resource.go index 8857dbae3..5dea9f4e9 100644 --- a/pkg/github/repository_resource.go +++ b/pkg/github/repository_resource.go @@ -99,7 +99,15 @@ func RepositoryResourceContentsHandler(getClient GetClientFn, getRawClient raw.G return nil, errors.New("repo is required") } - path := uriValues.Get("path").String() + pathValue := uriValues.Get("path") + pathComponents := pathValue.List() + var path string + + if len(pathComponents) == 0 { + path = pathValue.String() + } else { + path = strings.Join(pathComponents, "/") + } opts := &github.RepositoryContentGetOptions{} rawOpts := &raw.ContentOpts{} diff --git a/pkg/github/repository_resource_test.go b/pkg/github/repository_resource_test.go index da86d1f6d..113f46d89 100644 --- a/pkg/github/repository_resource_test.go +++ b/pkg/github/repository_resource_test.go @@ -123,6 +123,33 @@ func Test_repositoryResourceContents(t *testing.T) { URI: "", }}}, }, + { + name: "successful text content fetch (HEAD)", + mockedClient: mock.NewMockedHTTPClient( + mock.WithRequestMatchHandler( + raw.GetRawReposContentsByOwnerByRepoByPath, + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + + require.Contains(t, r.URL.Path, "pkg/github/actions.go") + _, err := w.Write([]byte("package actions\n\nfunc main() {\n // Sample Go file content\n}\n")) + require.NoError(t, err) + }), + ), + ), + uri: "repo://owner/repo/contents/pkg/github/actions.go", + handlerFn: func(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) mcp.ResourceHandler { + _, handler := GetRepositoryResourceContent(getClient, getRawClient, t) + return handler + }, + expectedResponseType: resourceResponseTypeText, + expectedResult: &mcp.ReadResourceResult{ + Contents: []*mcp.ResourceContents{{ + Text: "package actions\n\nfunc main() {\n // Sample Go file content\n}\n", + MIMEType: "text/plain", + URI: "", + }}}, + }, { name: "successful text content fetch (branch)", mockedClient: mock.NewMockedHTTPClient(