@@ -31,6 +31,7 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
3131 mcp .WithString ("category" ,
3232 mcp .Description ("Optional filter by discussion category ID. If provided, only discussions with this category are listed." ),
3333 ),
34+ WithGraphQLPagination (),
3435 ),
3536 func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
3637 // Required params
@@ -49,6 +50,12 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
4950 return mcp .NewToolResultError (err .Error ()), nil
5051 }
5152
53+ // Get pagination parameters
54+ pagination , err := OptionalGraphQLPaginationParams (request )
55+ if err != nil {
56+ return mcp .NewToolResultError (err .Error ()), nil
57+ }
58+
5259 client , err := getGQLClient (ctx )
5360 if err != nil {
5461 return mcp .NewToolResultError (fmt .Sprintf ("failed to get GitHub GQL client: %v" , err )), nil
@@ -61,7 +68,13 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
6168 categoryID = & id
6269 }
6370
64- // Now execute the discussions query
71+ // Build GraphQL query arguments
72+ // Use default of 30 if neither first nor last is specified
73+ if pagination .First == nil && pagination .Last == nil {
74+ defaultFirst := int32 (30 )
75+ pagination .First = & defaultFirst
76+ }
77+
6578 var discussions []* github.Discussion
6679 if categoryID != nil {
6780 // Query with category filter (server-side filtering)
@@ -77,13 +90,21 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
7790 } `graphql:"category"`
7891 URL githubv4.String `graphql:"url"`
7992 }
80- } `graphql:"discussions(first: 100, categoryId: $categoryId)"`
93+ PageInfo struct {
94+ HasNextPage bool
95+ EndCursor string
96+ }
97+ } `graphql:"discussions(first: $first, last: $last, after: $after, before: $before, categoryId: $categoryId)"`
8198 } `graphql:"repository(owner: $owner, name: $repo)"`
8299 }
83100 vars := map [string ]interface {}{
84101 "owner" : githubv4 .String (owner ),
85102 "repo" : githubv4 .String (repo ),
86103 "categoryId" : * categoryID ,
104+ "first" : (* githubv4 .Int )(pagination .First ),
105+ "last" : (* githubv4 .Int )(pagination .Last ),
106+ "after" : (* githubv4 .String )(pagination .After ),
107+ "before" : (* githubv4 .String )(pagination .Before ),
87108 }
88109 if err := client .Query (ctx , & query , vars ); err != nil {
89110 return mcp .NewToolResultError (err .Error ()), nil
@@ -102,6 +123,20 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
102123 }
103124 discussions = append (discussions , di )
104125 }
126+
127+ // Include pagination info in response
128+ response := map [string ]interface {}{
129+ "discussions" : discussions ,
130+ "pageInfo" : map [string ]interface {}{
131+ "hasNextPage" : query .Repository .Discussions .PageInfo .HasNextPage ,
132+ "endCursor" : query .Repository .Discussions .PageInfo .EndCursor ,
133+ },
134+ }
135+ out , err := json .Marshal (response )
136+ if err != nil {
137+ return nil , fmt .Errorf ("failed to marshal discussions: %w" , err )
138+ }
139+ return mcp .NewToolResultText (string (out )), nil
105140 } else {
106141 // Query without category filter
107142 var query struct {
@@ -116,12 +151,20 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
116151 } `graphql:"category"`
117152 URL githubv4.String `graphql:"url"`
118153 }
119- } `graphql:"discussions(first: 100)"`
154+ PageInfo struct {
155+ HasNextPage bool
156+ EndCursor string
157+ }
158+ } `graphql:"discussions(first: $first, last: $last, after: $after, before: $before)"`
120159 } `graphql:"repository(owner: $owner, name: $repo)"`
121160 }
122161 vars := map [string ]interface {}{
123- "owner" : githubv4 .String (owner ),
124- "repo" : githubv4 .String (repo ),
162+ "owner" : githubv4 .String (owner ),
163+ "repo" : githubv4 .String (repo ),
164+ "first" : (* githubv4 .Int )(pagination .First ),
165+ "last" : (* githubv4 .Int )(pagination .Last ),
166+ "after" : (* githubv4 .String )(pagination .After ),
167+ "before" : (* githubv4 .String )(pagination .Before ),
125168 }
126169 if err := client .Query (ctx , & query , vars ); err != nil {
127170 return mcp .NewToolResultError (err .Error ()), nil
@@ -140,14 +183,21 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
140183 }
141184 discussions = append (discussions , di )
142185 }
143- }
144186
145- // Marshal and return
146- out , err := json .Marshal (discussions )
147- if err != nil {
148- return nil , fmt .Errorf ("failed to marshal discussions: %w" , err )
187+ // Include pagination info in response
188+ response := map [string ]interface {}{
189+ "discussions" : discussions ,
190+ "pageInfo" : map [string ]interface {}{
191+ "hasNextPage" : query .Repository .Discussions .PageInfo .HasNextPage ,
192+ "endCursor" : query .Repository .Discussions .PageInfo .EndCursor ,
193+ },
194+ }
195+ out , err := json .Marshal (response )
196+ if err != nil {
197+ return nil , fmt .Errorf ("failed to marshal discussions: %w" , err )
198+ }
199+ return mcp .NewToolResultText (string (out )), nil
149200 }
150- return mcp .NewToolResultText (string (out )), nil
151201 }
152202}
153203
0 commit comments