@@ -162,15 +162,7 @@ func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (
162
162
mcp .Description ("Sort order ('asc' or 'desc')" ),
163
163
mcp .Enum ("asc" , "desc" ),
164
164
),
165
- mcp .WithNumber ("per_page" ,
166
- mcp .Description ("Results per page (max 100)" ),
167
- mcp .Min (1 ),
168
- mcp .Max (100 ),
169
- ),
170
- mcp .WithNumber ("page" ,
171
- mcp .Description ("Page number" ),
172
- mcp .Min (1 ),
173
- ),
165
+ withPagination (),
174
166
),
175
167
func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
176
168
query , err := requiredParam [string ](request , "q" )
@@ -185,11 +177,7 @@ func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (
185
177
if err != nil {
186
178
return mcp .NewToolResultError (err .Error ()), nil
187
179
}
188
- perPage , err := optionalIntParamWithDefault (request , "per_page" , 30 )
189
- if err != nil {
190
- return mcp .NewToolResultError (err .Error ()), nil
191
- }
192
- page , err := optionalIntParamWithDefault (request , "page" , 1 )
180
+ pagination , err := optionalPaginationParams (request )
193
181
if err != nil {
194
182
return mcp .NewToolResultError (err .Error ()), nil
195
183
}
@@ -198,8 +186,8 @@ func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (
198
186
Sort : sort ,
199
187
Order : order ,
200
188
ListOptions : github.ListOptions {
201
- PerPage : perPage ,
202
- Page : page ,
189
+ PerPage : pagination . perPage ,
190
+ Page : pagination . page ,
203
191
},
204
192
}
205
193
@@ -375,12 +363,7 @@ func listIssues(client *github.Client, t translations.TranslationHelperFunc) (to
375
363
mcp .WithString ("since" ,
376
364
mcp .Description ("Filter by date (ISO 8601 timestamp)" ),
377
365
),
378
- mcp .WithNumber ("page" ,
379
- mcp .Description ("Page number" ),
380
- ),
381
- mcp .WithNumber ("per_page" ,
382
- mcp .Description ("Results per page" ),
383
- ),
366
+ withPagination (),
384
367
),
385
368
func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
386
369
owner , err := requiredParam [string ](request , "owner" )
@@ -432,7 +415,7 @@ func listIssues(client *github.Client, t translations.TranslationHelperFunc) (to
432
415
opts .Page = int (page )
433
416
}
434
417
435
- if perPage , ok := request .Params .Arguments ["per_page " ].(float64 ); ok {
418
+ if perPage , ok := request .Params .Arguments ["perPage " ].(float64 ); ok {
436
419
opts .PerPage = int (perPage )
437
420
}
438
421
@@ -597,6 +580,81 @@ func updateIssue(client *github.Client, t translations.TranslationHelperFunc) (t
597
580
}
598
581
}
599
582
583
+ // 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 ) {
585
+ return mcp .NewTool ("get_issue_comments" ,
586
+ mcp .WithDescription (t ("TOOL_GET_ISSUE_COMMENTS_DESCRIPTION" , "Get comments for a GitHub issue" )),
587
+ mcp .WithString ("owner" ,
588
+ mcp .Required (),
589
+ mcp .Description ("Repository owner" ),
590
+ ),
591
+ mcp .WithString ("repo" ,
592
+ mcp .Required (),
593
+ mcp .Description ("Repository name" ),
594
+ ),
595
+ mcp .WithNumber ("issue_number" ,
596
+ mcp .Required (),
597
+ mcp .Description ("Issue number" ),
598
+ ),
599
+ mcp .WithNumber ("page" ,
600
+ mcp .Description ("Page number" ),
601
+ ),
602
+ mcp .WithNumber ("per_page" ,
603
+ mcp .Description ("Number of records per page" ),
604
+ ),
605
+ ),
606
+ func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
607
+ owner , err := requiredParam [string ](request , "owner" )
608
+ if err != nil {
609
+ return mcp .NewToolResultError (err .Error ()), nil
610
+ }
611
+ repo , err := requiredParam [string ](request , "repo" )
612
+ if err != nil {
613
+ return mcp .NewToolResultError (err .Error ()), nil
614
+ }
615
+ issueNumber , err := requiredInt (request , "issue_number" )
616
+ if err != nil {
617
+ return mcp .NewToolResultError (err .Error ()), nil
618
+ }
619
+ page , err := optionalIntParamWithDefault (request , "page" , 1 )
620
+ if err != nil {
621
+ return mcp .NewToolResultError (err .Error ()), nil
622
+ }
623
+ perPage , err := optionalIntParamWithDefault (request , "per_page" , 30 )
624
+ if err != nil {
625
+ return mcp .NewToolResultError (err .Error ()), nil
626
+ }
627
+
628
+ opts := & github.IssueListCommentsOptions {
629
+ ListOptions : github.ListOptions {
630
+ Page : page ,
631
+ PerPage : perPage ,
632
+ },
633
+ }
634
+
635
+ comments , resp , err := client .Issues .ListComments (ctx , owner , repo , issueNumber , opts )
636
+ if err != nil {
637
+ return nil , fmt .Errorf ("failed to get issue comments: %w" , err )
638
+ }
639
+ defer func () { _ = resp .Body .Close () }()
640
+
641
+ if resp .StatusCode != http .StatusOK {
642
+ body , err := io .ReadAll (resp .Body )
643
+ if err != nil {
644
+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
645
+ }
646
+ return mcp .NewToolResultError (fmt .Sprintf ("failed to get issue comments: %s" , string (body ))), nil
647
+ }
648
+
649
+ r , err := json .Marshal (comments )
650
+ if err != nil {
651
+ return nil , fmt .Errorf ("failed to marshal response: %w" , err )
652
+ }
653
+
654
+ return mcp .NewToolResultText (string (r )), nil
655
+ }
656
+ }
657
+
600
658
// parseISOTimestamp parses an ISO 8601 timestamp string into a time.Time object.
601
659
// Returns the parsed time or an error if parsing fails.
602
660
// Example formats supported: "2023-01-15T14:30:00Z", "2023-01-15"
0 commit comments