Skip to content

Commit 32ae6d9

Browse files
chore: groundwork for multi-user to server
1 parent 56c1fce commit 32ae6d9

15 files changed

+184
-139
lines changed

pkg/features/features.go

Whitespace-only changes.

pkg/github/code_scanning.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/mark3labs/mcp-go/server"
1414
)
1515

16-
func GetCodeScanningAlert(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
16+
func GetCodeScanningAlert(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1717
return mcp.NewTool("get_code_scanning_alert",
1818
mcp.WithDescription(t("TOOL_GET_CODE_SCANNING_ALERT_DESCRIPTION", "Get details of a specific code scanning alert in a GitHub repository.")),
1919
mcp.WithString("owner",
@@ -43,6 +43,7 @@ func GetCodeScanningAlert(client *github.Client, t translations.TranslationHelpe
4343
return mcp.NewToolResultError(err.Error()), nil
4444
}
4545

46+
client := getClient(ctx)
4647
alert, resp, err := client.CodeScanning.GetAlert(ctx, owner, repo, int64(alertNumber))
4748
if err != nil {
4849
return nil, fmt.Errorf("failed to get alert: %w", err)
@@ -66,7 +67,7 @@ func GetCodeScanningAlert(client *github.Client, t translations.TranslationHelpe
6667
}
6768
}
6869

69-
func ListCodeScanningAlerts(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
70+
func ListCodeScanningAlerts(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
7071
return mcp.NewTool("list_code_scanning_alerts",
7172
mcp.WithDescription(t("TOOL_LIST_CODE_SCANNING_ALERTS_DESCRIPTION", "List code scanning alerts in a GitHub repository.")),
7273
mcp.WithString("owner",
@@ -110,6 +111,7 @@ func ListCodeScanningAlerts(client *github.Client, t translations.TranslationHel
110111
return mcp.NewToolResultError(err.Error()), nil
111112
}
112113

114+
client := getClient(ctx)
113115
alerts, resp, err := client.CodeScanning.ListAlertsForRepo(ctx, owner, repo, &github.AlertListOptions{Ref: ref, State: state, Severity: severity})
114116
if err != nil {
115117
return nil, fmt.Errorf("failed to list alerts: %w", err)

pkg/github/code_scanning_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func Test_GetCodeScanningAlert(t *testing.T) {
1717
// Verify tool definition once
1818
mockClient := github.NewClient(nil)
19-
tool, _ := GetCodeScanningAlert(mockClient, translations.NullTranslationHelper)
19+
tool, _ := GetCodeScanningAlert(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
2020

2121
assert.Equal(t, "get_code_scanning_alert", tool.Name)
2222
assert.NotEmpty(t, tool.Description)
@@ -82,7 +82,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
8282
t.Run(tc.name, func(t *testing.T) {
8383
// Setup client with mock
8484
client := github.NewClient(tc.mockedClient)
85-
_, handler := GetCodeScanningAlert(client, translations.NullTranslationHelper)
85+
_, handler := GetCodeScanningAlert(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
8686

8787
// Create call request
8888
request := createMCPRequest(tc.requestArgs)
@@ -118,7 +118,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
118118
func Test_ListCodeScanningAlerts(t *testing.T) {
119119
// Verify tool definition once
120120
mockClient := github.NewClient(nil)
121-
tool, _ := ListCodeScanningAlerts(mockClient, translations.NullTranslationHelper)
121+
tool, _ := ListCodeScanningAlerts(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
122122

123123
assert.Equal(t, "list_code_scanning_alerts", tool.Name)
124124
assert.NotEmpty(t, tool.Description)
@@ -201,7 +201,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
201201
t.Run(tc.name, func(t *testing.T) {
202202
// Setup client with mock
203203
client := github.NewClient(tc.mockedClient)
204-
_, handler := ListCodeScanningAlerts(client, translations.NullTranslationHelper)
204+
_, handler := ListCodeScanningAlerts(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
205205

206206
// Create call request
207207
request := createMCPRequest(tc.requestArgs)

pkg/github/issues.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
// GetIssue creates a tool to get details of a specific issue in a GitHub repository.
18-
func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
18+
func GetIssue(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1919
return mcp.NewTool("get_issue",
2020
mcp.WithDescription(t("TOOL_GET_ISSUE_DESCRIPTION", "Get details of a specific issue in a GitHub repository")),
2121
mcp.WithString("owner",
@@ -45,6 +45,7 @@ func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool
4545
return mcp.NewToolResultError(err.Error()), nil
4646
}
4747

48+
client := getClient(ctx)
4849
issue, resp, err := client.Issues.Get(ctx, owner, repo, issueNumber)
4950
if err != nil {
5051
return nil, fmt.Errorf("failed to get issue: %w", err)
@@ -69,7 +70,7 @@ func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool
6970
}
7071

7172
// AddIssueComment creates a tool to add a comment to an issue.
72-
func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
73+
func AddIssueComment(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
7374
return mcp.NewTool("add_issue_comment",
7475
mcp.WithDescription(t("TOOL_ADD_ISSUE_COMMENT_DESCRIPTION", "Add a comment to an existing issue")),
7576
mcp.WithString("owner",
@@ -111,6 +112,7 @@ func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc
111112
Body: github.Ptr(body),
112113
}
113114

115+
client := getClient(ctx)
114116
createdComment, resp, err := client.Issues.CreateComment(ctx, owner, repo, issueNumber, comment)
115117
if err != nil {
116118
return nil, fmt.Errorf("failed to create comment: %w", err)
@@ -135,7 +137,7 @@ func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc
135137
}
136138

137139
// SearchIssues creates a tool to search for issues and pull requests.
138-
func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
140+
func SearchIssues(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
139141
return mcp.NewTool("search_issues",
140142
mcp.WithDescription(t("TOOL_SEARCH_ISSUES_DESCRIPTION", "Search for issues and pull requests across GitHub repositories")),
141143
mcp.WithString("q",
@@ -191,6 +193,7 @@ func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (
191193
},
192194
}
193195

196+
client := getClient(ctx)
194197
result, resp, err := client.Search.Issues(ctx, query, opts)
195198
if err != nil {
196199
return nil, fmt.Errorf("failed to search issues: %w", err)
@@ -215,7 +218,7 @@ func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (
215218
}
216219

217220
// CreateIssue creates a tool to create a new issue in a GitHub repository.
218-
func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
221+
func CreateIssue(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
219222
return mcp.NewTool("create_issue",
220223
mcp.WithDescription(t("TOOL_CREATE_ISSUE_DESCRIPTION", "Create a new issue in a GitHub repository")),
221224
mcp.WithString("owner",
@@ -305,6 +308,7 @@ func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
305308
Milestone: milestoneNum,
306309
}
307310

311+
client := getClient(ctx)
308312
issue, resp, err := client.Issues.Create(ctx, owner, repo, issueRequest)
309313
if err != nil {
310314
return nil, fmt.Errorf("failed to create issue: %w", err)
@@ -329,7 +333,7 @@ func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
329333
}
330334

331335
// ListIssues creates a tool to list and filter repository issues
332-
func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
336+
func ListIssues(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
333337
return mcp.NewTool("list_issues",
334338
mcp.WithDescription(t("TOOL_LIST_ISSUES_DESCRIPTION", "List issues in a GitHub repository with filtering options")),
335339
mcp.WithString("owner",
@@ -419,6 +423,7 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to
419423
opts.PerPage = int(perPage)
420424
}
421425

426+
client := getClient(ctx)
422427
issues, resp, err := client.Issues.ListByRepo(ctx, owner, repo, opts)
423428
if err != nil {
424429
return nil, fmt.Errorf("failed to list issues: %w", err)
@@ -443,7 +448,7 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to
443448
}
444449

445450
// UpdateIssue creates a tool to update an existing issue in a GitHub repository.
446-
func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
451+
func UpdateIssue(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
447452
return mcp.NewTool("update_issue",
448453
mcp.WithDescription(t("TOOL_UPDATE_ISSUE_DESCRIPTION", "Update an existing issue in a GitHub repository")),
449454
mcp.WithString("owner",
@@ -557,6 +562,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
557562
issueRequest.Milestone = &milestoneNum
558563
}
559564

565+
client := getClient(ctx)
560566
updatedIssue, resp, err := client.Issues.Edit(ctx, owner, repo, issueNumber, issueRequest)
561567
if err != nil {
562568
return nil, fmt.Errorf("failed to update issue: %w", err)
@@ -581,7 +587,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
581587
}
582588

583589
// GetIssueComments creates a tool to get comments for a GitHub issue.
584-
func GetIssueComments(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
590+
func GetIssueComments(getClient func(ctx context.Context) *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
585591
return mcp.NewTool("get_issue_comments",
586592
mcp.WithDescription(t("TOOL_GET_ISSUE_COMMENTS_DESCRIPTION", "Get comments for a GitHub issue")),
587593
mcp.WithString("owner",
@@ -632,6 +638,7 @@ func GetIssueComments(client *github.Client, t translations.TranslationHelperFun
632638
},
633639
}
634640

641+
client := getClient(ctx)
635642
comments, resp, err := client.Issues.ListComments(ctx, owner, repo, issueNumber, opts)
636643
if err != nil {
637644
return nil, fmt.Errorf("failed to get issue comments: %w", err)

pkg/github/issues_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func Test_GetIssue(t *testing.T) {
1919
// Verify tool definition once
2020
mockClient := github.NewClient(nil)
21-
tool, _ := GetIssue(mockClient, translations.NullTranslationHelper)
21+
tool, _ := GetIssue(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
2222

2323
assert.Equal(t, "get_issue", tool.Name)
2424
assert.NotEmpty(t, tool.Description)
@@ -82,7 +82,7 @@ func Test_GetIssue(t *testing.T) {
8282
t.Run(tc.name, func(t *testing.T) {
8383
// Setup client with mock
8484
client := github.NewClient(tc.mockedClient)
85-
_, handler := GetIssue(client, translations.NullTranslationHelper)
85+
_, handler := GetIssue(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
8686

8787
// Create call request
8888
request := createMCPRequest(tc.requestArgs)
@@ -114,7 +114,7 @@ func Test_GetIssue(t *testing.T) {
114114
func Test_AddIssueComment(t *testing.T) {
115115
// Verify tool definition once
116116
mockClient := github.NewClient(nil)
117-
tool, _ := AddIssueComment(mockClient, translations.NullTranslationHelper)
117+
tool, _ := AddIssueComment(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
118118

119119
assert.Equal(t, "add_issue_comment", tool.Name)
120120
assert.NotEmpty(t, tool.Description)
@@ -185,7 +185,7 @@ func Test_AddIssueComment(t *testing.T) {
185185
t.Run(tc.name, func(t *testing.T) {
186186
// Setup client with mock
187187
client := github.NewClient(tc.mockedClient)
188-
_, handler := AddIssueComment(client, translations.NullTranslationHelper)
188+
_, handler := AddIssueComment(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
189189

190190
// Create call request
191191
request := mcp.CallToolRequest{
@@ -237,7 +237,7 @@ func Test_AddIssueComment(t *testing.T) {
237237
func Test_SearchIssues(t *testing.T) {
238238
// Verify tool definition once
239239
mockClient := github.NewClient(nil)
240-
tool, _ := SearchIssues(mockClient, translations.NullTranslationHelper)
240+
tool, _ := SearchIssues(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
241241

242242
assert.Equal(t, "search_issues", tool.Name)
243243
assert.NotEmpty(t, tool.Description)
@@ -352,7 +352,7 @@ func Test_SearchIssues(t *testing.T) {
352352
t.Run(tc.name, func(t *testing.T) {
353353
// Setup client with mock
354354
client := github.NewClient(tc.mockedClient)
355-
_, handler := SearchIssues(client, translations.NullTranslationHelper)
355+
_, handler := SearchIssues(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
356356

357357
// Create call request
358358
request := createMCPRequest(tc.requestArgs)
@@ -393,7 +393,7 @@ func Test_SearchIssues(t *testing.T) {
393393
func Test_CreateIssue(t *testing.T) {
394394
// Verify tool definition once
395395
mockClient := github.NewClient(nil)
396-
tool, _ := CreateIssue(mockClient, translations.NullTranslationHelper)
396+
tool, _ := CreateIssue(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
397397

398398
assert.Equal(t, "create_issue", tool.Name)
399399
assert.NotEmpty(t, tool.Description)
@@ -505,7 +505,7 @@ func Test_CreateIssue(t *testing.T) {
505505
t.Run(tc.name, func(t *testing.T) {
506506
// Setup client with mock
507507
client := github.NewClient(tc.mockedClient)
508-
_, handler := CreateIssue(client, translations.NullTranslationHelper)
508+
_, handler := CreateIssue(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
509509

510510
// Create call request
511511
request := createMCPRequest(tc.requestArgs)
@@ -566,7 +566,7 @@ func Test_CreateIssue(t *testing.T) {
566566
func Test_ListIssues(t *testing.T) {
567567
// Verify tool definition
568568
mockClient := github.NewClient(nil)
569-
tool, _ := ListIssues(mockClient, translations.NullTranslationHelper)
569+
tool, _ := ListIssues(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
570570

571571
assert.Equal(t, "list_issues", tool.Name)
572572
assert.NotEmpty(t, tool.Description)
@@ -697,7 +697,7 @@ func Test_ListIssues(t *testing.T) {
697697
t.Run(tc.name, func(t *testing.T) {
698698
// Setup client with mock
699699
client := github.NewClient(tc.mockedClient)
700-
_, handler := ListIssues(client, translations.NullTranslationHelper)
700+
_, handler := ListIssues(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
701701

702702
// Create call request
703703
request := createMCPRequest(tc.requestArgs)
@@ -742,7 +742,7 @@ func Test_ListIssues(t *testing.T) {
742742
func Test_UpdateIssue(t *testing.T) {
743743
// Verify tool definition
744744
mockClient := github.NewClient(nil)
745-
tool, _ := UpdateIssue(mockClient, translations.NullTranslationHelper)
745+
tool, _ := UpdateIssue(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
746746

747747
assert.Equal(t, "update_issue", tool.Name)
748748
assert.NotEmpty(t, tool.Description)
@@ -881,7 +881,7 @@ func Test_UpdateIssue(t *testing.T) {
881881
t.Run(tc.name, func(t *testing.T) {
882882
// Setup client with mock
883883
client := github.NewClient(tc.mockedClient)
884-
_, handler := UpdateIssue(client, translations.NullTranslationHelper)
884+
_, handler := UpdateIssue(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
885885

886886
// Create call request
887887
request := createMCPRequest(tc.requestArgs)
@@ -999,7 +999,7 @@ func Test_ParseISOTimestamp(t *testing.T) {
999999
func Test_GetIssueComments(t *testing.T) {
10001000
// Verify tool definition once
10011001
mockClient := github.NewClient(nil)
1002-
tool, _ := GetIssueComments(mockClient, translations.NullTranslationHelper)
1002+
tool, _ := GetIssueComments(func(_ context.Context) *github.Client { return mockClient }, translations.NullTranslationHelper)
10031003

10041004
assert.Equal(t, "get_issue_comments", tool.Name)
10051005
assert.NotEmpty(t, tool.Description)
@@ -1099,7 +1099,7 @@ func Test_GetIssueComments(t *testing.T) {
10991099
t.Run(tc.name, func(t *testing.T) {
11001100
// Setup client with mock
11011101
client := github.NewClient(tc.mockedClient)
1102-
_, handler := GetIssueComments(client, translations.NullTranslationHelper)
1102+
_, handler := GetIssueComments(func(_ context.Context) *github.Client { return client }, translations.NullTranslationHelper)
11031103

11041104
// Create call request
11051105
request := createMCPRequest(tc.requestArgs)

0 commit comments

Comments
 (0)