Skip to content

Commit 948fe76

Browse files
authored
Fix handling of multi path resources (#1458)
* Migrate repo resources to Go SDK * Enable resources for repos * Properly handle encoding and closing of the buffer * Remove outdated comment * Switch to StdEncoding, as it was originally * fix casing for linter * Update licenses * Handle multiple path components
1 parent 0a19bf4 commit 948fe76

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pkg/github/repository_resource.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,15 @@ func RepositoryResourceContentsHandler(getClient GetClientFn, getRawClient raw.G
9999
return nil, errors.New("repo is required")
100100
}
101101

102-
path := uriValues.Get("path").String()
102+
pathValue := uriValues.Get("path")
103+
pathComponents := pathValue.List()
104+
var path string
105+
106+
if len(pathComponents) == 0 {
107+
path = pathValue.String()
108+
} else {
109+
path = strings.Join(pathComponents, "/")
110+
}
103111

104112
opts := &github.RepositoryContentGetOptions{}
105113
rawOpts := &raw.ContentOpts{}

pkg/github/repository_resource_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,33 @@ func Test_repositoryResourceContents(t *testing.T) {
123123
URI: "",
124124
}}},
125125
},
126+
{
127+
name: "successful text content fetch (HEAD)",
128+
mockedClient: mock.NewMockedHTTPClient(
129+
mock.WithRequestMatchHandler(
130+
raw.GetRawReposContentsByOwnerByRepoByPath,
131+
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
132+
w.Header().Set("Content-Type", "text/plain")
133+
134+
require.Contains(t, r.URL.Path, "pkg/github/actions.go")
135+
_, err := w.Write([]byte("package actions\n\nfunc main() {\n // Sample Go file content\n}\n"))
136+
require.NoError(t, err)
137+
}),
138+
),
139+
),
140+
uri: "repo://owner/repo/contents/pkg/github/actions.go",
141+
handlerFn: func(getClient GetClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc) mcp.ResourceHandler {
142+
_, handler := GetRepositoryResourceContent(getClient, getRawClient, t)
143+
return handler
144+
},
145+
expectedResponseType: resourceResponseTypeText,
146+
expectedResult: &mcp.ReadResourceResult{
147+
Contents: []*mcp.ResourceContents{{
148+
Text: "package actions\n\nfunc main() {\n // Sample Go file content\n}\n",
149+
MIMEType: "text/plain",
150+
URI: "",
151+
}}},
152+
},
126153
{
127154
name: "successful text content fetch (branch)",
128155
mockedClient: mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)