@@ -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 GetClientFn , 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,10 @@ func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool
4545 return mcp .NewToolResultError (err .Error ()), nil
4646 }
4747
48+ client , err := getClient (ctx )
49+ if err != nil {
50+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
51+ }
4852 issue , resp , err := client .Issues .Get (ctx , owner , repo , issueNumber )
4953 if err != nil {
5054 return nil , fmt .Errorf ("failed to get issue: %w" , err )
@@ -69,7 +73,7 @@ func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool
6973}
7074
7175// 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 ) {
7377 return mcp .NewTool ("add_issue_comment" ,
7478 mcp .WithDescription (t ("TOOL_ADD_ISSUE_COMMENT_DESCRIPTION" , "Add a comment to an existing issue" )),
7579 mcp .WithString ("owner" ,
@@ -111,6 +115,10 @@ func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc
111115 Body : github .Ptr (body ),
112116 }
113117
118+ client , err := getClient (ctx )
119+ if err != nil {
120+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
121+ }
114122 createdComment , resp , err := client .Issues .CreateComment (ctx , owner , repo , issueNumber , comment )
115123 if err != nil {
116124 return nil , fmt .Errorf ("failed to create comment: %w" , err )
@@ -135,7 +143,7 @@ func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc
135143}
136144
137145// 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 ) {
139147 return mcp .NewTool ("search_issues" ,
140148 mcp .WithDescription (t ("TOOL_SEARCH_ISSUES_DESCRIPTION" , "Search for issues and pull requests across GitHub repositories" )),
141149 mcp .WithString ("q" ,
@@ -191,6 +199,10 @@ func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (
191199 },
192200 }
193201
202+ client , err := getClient (ctx )
203+ if err != nil {
204+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
205+ }
194206 result , resp , err := client .Search .Issues (ctx , query , opts )
195207 if err != nil {
196208 return nil , fmt .Errorf ("failed to search issues: %w" , err )
@@ -215,7 +227,7 @@ func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) (
215227}
216228
217229// 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 ) {
219231 return mcp .NewTool ("create_issue" ,
220232 mcp .WithDescription (t ("TOOL_CREATE_ISSUE_DESCRIPTION" , "Create a new issue in a GitHub repository" )),
221233 mcp .WithString ("owner" ,
@@ -305,6 +317,10 @@ func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
305317 Milestone : milestoneNum ,
306318 }
307319
320+ client , err := getClient (ctx )
321+ if err != nil {
322+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
323+ }
308324 issue , resp , err := client .Issues .Create (ctx , owner , repo , issueRequest )
309325 if err != nil {
310326 return nil , fmt .Errorf ("failed to create issue: %w" , err )
@@ -329,7 +345,7 @@ func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
329345}
330346
331347// 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 ) {
333349 return mcp .NewTool ("list_issues" ,
334350 mcp .WithDescription (t ("TOOL_LIST_ISSUES_DESCRIPTION" , "List issues in a GitHub repository with filtering options" )),
335351 mcp .WithString ("owner" ,
@@ -419,6 +435,10 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to
419435 opts .PerPage = int (perPage )
420436 }
421437
438+ client , err := getClient (ctx )
439+ if err != nil {
440+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
441+ }
422442 issues , resp , err := client .Issues .ListByRepo (ctx , owner , repo , opts )
423443 if err != nil {
424444 return nil , fmt .Errorf ("failed to list issues: %w" , err )
@@ -443,7 +463,7 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to
443463}
444464
445465// 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 ) {
447467 return mcp .NewTool ("update_issue" ,
448468 mcp .WithDescription (t ("TOOL_UPDATE_ISSUE_DESCRIPTION" , "Update an existing issue in a GitHub repository" )),
449469 mcp .WithString ("owner" ,
@@ -557,6 +577,10 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
557577 issueRequest .Milestone = & milestoneNum
558578 }
559579
580+ client , err := getClient (ctx )
581+ if err != nil {
582+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
583+ }
560584 updatedIssue , resp , err := client .Issues .Edit (ctx , owner , repo , issueNumber , issueRequest )
561585 if err != nil {
562586 return nil , fmt .Errorf ("failed to update issue: %w" , err )
@@ -581,7 +605,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
581605}
582606
583607// 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 ) {
585609 return mcp .NewTool ("get_issue_comments" ,
586610 mcp .WithDescription (t ("TOOL_GET_ISSUE_COMMENTS_DESCRIPTION" , "Get comments for a GitHub issue" )),
587611 mcp .WithString ("owner" ,
@@ -632,6 +656,10 @@ func GetIssueComments(client *github.Client, t translations.TranslationHelperFun
632656 },
633657 }
634658
659+ client , err := getClient (ctx )
660+ if err != nil {
661+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
662+ }
635663 comments , resp , err := client .Issues .ListComments (ctx , owner , repo , issueNumber , opts )
636664 if err != nil {
637665 return nil , fmt .Errorf ("failed to get issue comments: %w" , err )
0 commit comments