Skip to content

Commit 834f0fa

Browse files
Switch to getClient idiom
1 parent eb706e8 commit 834f0fa

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

pkg/github/organizations.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
// ListCommits creates a tool to get commits of a branch in a repository.
16-
func ListRepositories(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
16+
func ListRepositories(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1717
return mcp.NewTool("list_repositories",
1818
mcp.WithDescription(t("TOOL_LIST_REPOSITORIES_DESCRIPTION", "Get list of repositories in a GitHub organization")),
1919
mcp.WithString("org",
@@ -70,6 +70,11 @@ func ListRepositories(client *github.Client, t translations.TranslationHelperFun
7070
opts.Direction = direction
7171
}
7272

73+
client, err := getClient(ctx)
74+
if err != nil {
75+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
76+
}
77+
7378
repos, resp, err := client.Repositories.ListByOrg(ctx, org, opts)
7479
if err != nil {
7580
return nil, fmt.Errorf("failed to list repositories: %w", err)

pkg/github/organizations_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func Test_ListRepositories(t *testing.T) {
1717
// Verify tool definition once
1818
mockClient := github.NewClient(nil)
19-
tool, _ := ListRepositories(mockClient, translations.NullTranslationHelper)
19+
tool, _ := ListRepositories(stubGetClientFn(mockClient), translations.NullTranslationHelper)
2020

2121
assert.Equal(t, "list_repositories", tool.Name)
2222
assert.NotEmpty(t, tool.Description)
@@ -172,7 +172,7 @@ func Test_ListRepositories(t *testing.T) {
172172
t.Run(tc.name, func(t *testing.T) {
173173
// Setup client with mock
174174
client := github.NewClient(tc.mockedClient)
175-
_, handler := ListRepositories(client, translations.NullTranslationHelper)
175+
_, handler := ListRepositories(stubGetClientFn(client), translations.NullTranslationHelper)
176176

177177
// Create call request
178178
request := createMCPRequest(tc.requestArgs)

pkg/github/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func NewServer(getClient GetClientFn, version string, readOnly bool, t translati
8080
}
8181

8282
// Add GitHub tools - Organizations
83-
s.AddTool(ListRepositories(client, t))
83+
s.AddTool(ListRepositories(getClient, t))
8484

8585
// Add GitHub tools - Search
8686
s.AddTool(SearchCode(getClient, t))
@@ -181,7 +181,6 @@ func requiredParam[T comparable](r mcp.CallToolRequest, p string) (T, error) {
181181

182182
if r.Params.Arguments[p].(T) == zero {
183183
return zero, fmt.Errorf("missing required parameter: %s", p)
184-
185184
}
186185

187186
return r.Params.Arguments[p].(T), nil

0 commit comments

Comments
 (0)