@@ -315,16 +315,51 @@ func ListDiscussionCategories(getGQLClient GetGQLClientFn, t translations.Transl
315315 mcp .Required (),
316316 mcp .Description ("Repository name" ),
317317 ),
318+ mcp .WithNumber ("first" ,
319+ mcp .Description ("Number of categories to return per page (min 1, max 100)" ),
320+ mcp .Min (1 ),
321+ mcp .Max (100 ),
322+ ),
323+ mcp .WithNumber ("last" ,
324+ mcp .Description ("Number of categories to return from the end (min 1, max 100)" ),
325+ mcp .Min (1 ),
326+ mcp .Max (100 ),
327+ ),
328+ mcp .WithString ("after" ,
329+ mcp .Description ("Cursor for pagination, use the 'after' field from the previous response" ),
330+ ),
331+ mcp .WithString ("before" ,
332+ mcp .Description ("Cursor for pagination, use the 'before' field from the previous response" ),
333+ ),
318334 ),
319335 func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
320- owner , err := requiredParam [string ](request , "owner" )
321- if err != nil {
322- return mcp .NewToolResultError (err .Error ()), nil
336+ // Decode params
337+ var params struct {
338+ Owner string
339+ Repo string
340+ First int32
341+ Last int32
342+ After string
343+ Before string
323344 }
324- repo , err := requiredParam [string ](request , "repo" )
325- if err != nil {
345+ if err := mapstructure .Decode (request .Params .Arguments , & params ); err != nil {
326346 return mcp .NewToolResultError (err .Error ()), nil
327347 }
348+
349+ // Validate pagination parameters
350+ if params .First != 0 && params .Last != 0 {
351+ return mcp .NewToolResultError ("only one of 'first' or 'last' may be specified" ), nil
352+ }
353+ if params .After != "" && params .Before != "" {
354+ return mcp .NewToolResultError ("only one of 'after' or 'before' may be specified" ), nil
355+ }
356+ if params .After != "" && params .Last != 0 {
357+ return mcp .NewToolResultError ("'after' cannot be used with 'last'. Did you mean to use 'before' instead?" ), nil
358+ }
359+ if params .Before != "" && params .First != 0 {
360+ return mcp .NewToolResultError ("'before' cannot be used with 'first'. Did you mean to use 'after' instead?" ), nil
361+ }
362+
328363 client , err := getGQLClient (ctx )
329364 if err != nil {
330365 return mcp .NewToolResultError (fmt .Sprintf ("failed to get GitHub GQL client: %v" , err )), nil
@@ -336,12 +371,16 @@ func ListDiscussionCategories(getGQLClient GetGQLClientFn, t translations.Transl
336371 ID githubv4.ID
337372 Name githubv4.String
338373 }
339- } `graphql:"discussionCategories(first: 30 )"`
374+ } `graphql:"discussionCategories(first: $first, last: $last, after: $after, before: $before )"`
340375 } `graphql:"repository(owner: $owner, name: $repo)"`
341376 }
342377 vars := map [string ]interface {}{
343- "owner" : githubv4 .String (owner ),
344- "repo" : githubv4 .String (repo ),
378+ "owner" : githubv4 .String (params .Owner ),
379+ "repo" : githubv4 .String (params .Repo ),
380+ "first" : githubv4 .Int (params .First ),
381+ "last" : githubv4 .Int (params .Last ),
382+ "after" : githubv4 .String (params .After ),
383+ "before" : githubv4 .String (params .Before ),
345384 }
346385 if err := client .Query (ctx , & q , vars ); err != nil {
347386 return mcp .NewToolResultError (err .Error ()), nil
0 commit comments