@@ -15,7 +15,7 @@ import (
15
15
)
16
16
17
17
// 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 GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
19
19
return mcp .NewTool ("get_issue" ,
20
20
mcp .WithDescription (t ("TOOL_GET_ISSUE_DESCRIPTION" , "Get details of a specific issue in a GitHub repository" )),
21
21
mcp .WithString ("owner" ,
@@ -45,6 +45,10 @@ func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool
45
45
return mcp .NewToolResultError (err .Error ()), nil
46
46
}
47
47
48
+ client , err := getClient (ctx )
49
+ if err != nil {
50
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
51
+ }
48
52
issue , resp , err := client .Issues .Get (ctx , owner , repo , issueNumber )
49
53
if err != nil {
50
54
return nil , fmt .Errorf ("failed to get issue: %w" , err )
@@ -69,7 +73,7 @@ func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool
69
73
}
70
74
71
75
// 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 ) {
76
+ func AddIssueComment (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
73
77
return mcp .NewTool ("add_issue_comment" ,
74
78
mcp .WithDescription (t ("TOOL_ADD_ISSUE_COMMENT_DESCRIPTION" , "Add a comment to an existing issue" )),
75
79
mcp .WithString ("owner" ,
@@ -111,6 +115,10 @@ func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc
111
115
Body : github .Ptr (body ),
112
116
}
113
117
118
+ client , err := getClient (ctx )
119
+ if err != nil {
120
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
121
+ }
114
122
createdComment , resp , err := client .Issues .CreateComment (ctx , owner , repo , issueNumber , comment )
115
123
if err != nil {
116
124
return nil , fmt .Errorf ("failed to create comment: %w" , err )
@@ -135,7 +143,7 @@ func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc
135
143
}
136
144
137
145
// 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 ) {
146
+ func SearchIssues (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
139
147
return mcp .NewTool ("search_issues" ,
140
148
mcp .WithDescription (t ("TOOL_SEARCH_ISSUES_DESCRIPTION" , "Search for issues and pull requests across GitHub repositories" )),
141
149
mcp .WithString ("q" ,
@@ -191,6 +199,10 @@ func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (
191
199
},
192
200
}
193
201
202
+ client , err := getClient (ctx )
203
+ if err != nil {
204
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
205
+ }
194
206
result , resp , err := client .Search .Issues (ctx , query , opts )
195
207
if err != nil {
196
208
return nil , fmt .Errorf ("failed to search issues: %w" , err )
@@ -215,7 +227,7 @@ func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (
215
227
}
216
228
217
229
// 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 ) {
230
+ func CreateIssue (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
219
231
return mcp .NewTool ("create_issue" ,
220
232
mcp .WithDescription (t ("TOOL_CREATE_ISSUE_DESCRIPTION" , "Create a new issue in a GitHub repository" )),
221
233
mcp .WithString ("owner" ,
@@ -305,6 +317,10 @@ func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
305
317
Milestone : milestoneNum ,
306
318
}
307
319
320
+ client , err := getClient (ctx )
321
+ if err != nil {
322
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
323
+ }
308
324
issue , resp , err := client .Issues .Create (ctx , owner , repo , issueRequest )
309
325
if err != nil {
310
326
return nil , fmt .Errorf ("failed to create issue: %w" , err )
@@ -329,7 +345,7 @@ func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
329
345
}
330
346
331
347
// 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 ) {
348
+ func ListIssues (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
333
349
return mcp .NewTool ("list_issues" ,
334
350
mcp .WithDescription (t ("TOOL_LIST_ISSUES_DESCRIPTION" , "List issues in a GitHub repository with filtering options" )),
335
351
mcp .WithString ("owner" ,
@@ -419,6 +435,10 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to
419
435
opts .PerPage = int (perPage )
420
436
}
421
437
438
+ client , err := getClient (ctx )
439
+ if err != nil {
440
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
441
+ }
422
442
issues , resp , err := client .Issues .ListByRepo (ctx , owner , repo , opts )
423
443
if err != nil {
424
444
return nil , fmt .Errorf ("failed to list issues: %w" , err )
@@ -443,7 +463,7 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to
443
463
}
444
464
445
465
// 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 ) {
466
+ func UpdateIssue (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
447
467
return mcp .NewTool ("update_issue" ,
448
468
mcp .WithDescription (t ("TOOL_UPDATE_ISSUE_DESCRIPTION" , "Update an existing issue in a GitHub repository" )),
449
469
mcp .WithString ("owner" ,
@@ -557,6 +577,10 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
557
577
issueRequest .Milestone = & milestoneNum
558
578
}
559
579
580
+ client , err := getClient (ctx )
581
+ if err != nil {
582
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
583
+ }
560
584
updatedIssue , resp , err := client .Issues .Edit (ctx , owner , repo , issueNumber , issueRequest )
561
585
if err != nil {
562
586
return nil , fmt .Errorf ("failed to update issue: %w" , err )
@@ -581,7 +605,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
581
605
}
582
606
583
607
// 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 ) {
608
+ func GetIssueComments (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
585
609
return mcp .NewTool ("get_issue_comments" ,
586
610
mcp .WithDescription (t ("TOOL_GET_ISSUE_COMMENTS_DESCRIPTION" , "Get comments for a GitHub issue" )),
587
611
mcp .WithString ("owner" ,
@@ -632,6 +656,10 @@ func GetIssueComments(client *github.Client, t translations.TranslationHelperFun
632
656
},
633
657
}
634
658
659
+ client , err := getClient (ctx )
660
+ if err != nil {
661
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
662
+ }
635
663
comments , resp , err := client .Issues .ListComments (ctx , owner , repo , issueNumber , opts )
636
664
if err != nil {
637
665
return nil , fmt .Errorf ("failed to get issue comments: %w" , err )
0 commit comments