From 26e1b7ae087c73ea21113ce6148aae0baa004da1 Mon Sep 17 00:00:00 2001 From: Ksenia Bobrova Date: Wed, 17 Dec 2025 14:17:49 +0100 Subject: [PATCH 1/2] Fix: path param should be optional --- pkg/github/repositories.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 179c08475..14e998531 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -670,10 +670,13 @@ func GetFileContents(t translations.TranslationHelperFunc) inventory.ServerTool if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } - path, err := RequiredParam[string](args, "path") + + path, err := OptionalParam[string](args, "path") if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } + path = strings.TrimPrefix(path, "/") + ref, err := OptionalParam[string](args, "ref") if err != nil { return utils.NewToolResultError(err.Error()), nil, nil From 3a3bd1e05f7ad28efbe43f2c9d28bbb9a5255823 Mon Sep 17 00:00:00 2001 From: Ksenia Bobrova Date: Wed, 17 Dec 2025 14:38:33 +0100 Subject: [PATCH 2/2] Add test --- 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 4e978a81a..5e338c7e7 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -245,6 +245,51 @@ func Test_GetFileContents(t *testing.T) { expectError: false, expectedResult: mockDirContent, }, + { + name: "successful text content fetch with leading slash in path", + 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("README.md"), + Path: github.Ptr("README.md"), + SHA: github.Ptr("abc123"), + 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", "text/markdown") + _, _ = w.Write(mockRawContent) + }), + ), + ), + requestArgs: map[string]interface{}{ + "owner": "owner", + "repo": "repo", + "path": "/README.md", + "ref": "refs/heads/main", + }, + expectError: false, + expectedResult: mcp.ResourceContents{ + URI: "repo://owner/repo/refs/heads/main/contents/README.md", + Text: "# Test Repository\n\nThis is a test repository.", + MIMEType: "text/markdown", + }, + }, { name: "content fetch fails", mockedClient: mock.NewMockedHTTPClient(