@@ -724,7 +724,7 @@ func CreateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
724724}
725725
726726// ListIssues creates a tool to list and filter repository issues
727- func ListIssues (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
727+ func ListIssues (getGQLClient GetGQLClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
728728 return mcp .NewTool ("list_issues" ,
729729 mcp .WithDescription (t ("TOOL_LIST_ISSUES_DESCRIPTION" , "List issues in a GitHub repository." )),
730730 mcp .WithToolAnnotation (mcp.ToolAnnotation {
@@ -818,30 +818,62 @@ func ListIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (to
818818 opts .ListOptions .PerPage = int (perPage )
819819 }
820820
821- client , err := getClient (ctx )
821+ client , err := getGQLClient (ctx )
822822 if err != nil {
823- return nil , fmt .Errorf ("failed to get GitHub client: %w " , err )
823+ return mcp . NewToolResultError ( fmt .Sprintf ("failed to get GitHub GQL client: %v " , err )), nil
824824 }
825- issues , resp , err := client .Issues .ListByRepo (ctx , owner , repo , opts )
826- if err != nil {
827- return nil , fmt .Errorf ("failed to list issues: %w" , err )
825+
826+ var q struct {
827+ Repository struct {
828+ DiscussionCategories struct {
829+ Nodes []struct {
830+ ID githubv4.ID
831+ Name githubv4.String
832+ }
833+ PageInfo struct {
834+ HasNextPage githubv4.Boolean
835+ HasPreviousPage githubv4.Boolean
836+ StartCursor githubv4.String
837+ EndCursor githubv4.String
838+ }
839+ TotalCount int
840+ } `graphql:"discussionCategories(first: $first)"`
841+ } `graphql:"repository(owner: $owner, name: $repo)"`
842+ }
843+ vars := map [string ]interface {}{
844+ //"owner": githubv4.String(params.Owner),
845+ //"repo": githubv4.String(params.Repo),
846+ "first" : githubv4 .Int (25 ),
847+ }
848+ if err := client .Query (ctx , & q , vars ); err != nil {
849+ return mcp .NewToolResultError (err .Error ()), nil
828850 }
829- defer func () { _ = resp .Body .Close () }()
830851
831- if resp . StatusCode != http . StatusOK {
832- body , err := io . ReadAll ( resp . Body )
833- if err != nil {
834- return nil , fmt .Errorf ( "failed to read response body: %w" , err )
835- }
836- return mcp . NewToolResultError ( fmt . Sprintf ( "failed to list issues: %s" , string ( body ))), nil
852+ var categories [] map [ string ] string
853+ for _ , c := range q . Repository . DiscussionCategories . Nodes {
854+ categories = append ( categories , map [ string ] string {
855+ "id" : fmt .Sprint ( c . ID ),
856+ "name" : string ( c . Name ),
857+ })
837858 }
838859
839- r , err := json .Marshal (issues )
840- if err != nil {
841- return nil , fmt .Errorf ("failed to marshal issues: %w" , err )
860+ // Create response with pagination info
861+ response := map [string ]interface {}{
862+ "categories" : categories ,
863+ "pageInfo" : map [string ]interface {}{
864+ "hasNextPage" : q .Repository .DiscussionCategories .PageInfo .HasNextPage ,
865+ "hasPreviousPage" : q .Repository .DiscussionCategories .PageInfo .HasPreviousPage ,
866+ "startCursor" : string (q .Repository .DiscussionCategories .PageInfo .StartCursor ),
867+ "endCursor" : string (q .Repository .DiscussionCategories .PageInfo .EndCursor ),
868+ },
869+ "totalCount" : q .Repository .DiscussionCategories .TotalCount ,
842870 }
843871
844- return mcp .NewToolResultText (string (r )), nil
872+ out , err := json .Marshal (response )
873+ if err != nil {
874+ return nil , fmt .Errorf ("failed to marshal discussion categories: %w" , err )
875+ }
876+ return mcp .NewToolResultText (string (out )), nil
845877 }
846878}
847879
0 commit comments