@@ -31,6 +31,14 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
31
31
mcp .WithString ("category" ,
32
32
mcp .Description ("Optional filter by discussion category ID. If provided, only discussions with this category are listed." ),
33
33
),
34
+ mcp .WithString ("orderBy" ,
35
+ mcp .Description ("Order discussions by field" ),
36
+ mcp .Enum ("CREATED_AT" , "UPDATED_AT" ),
37
+ ),
38
+ mcp .WithString ("direction" ,
39
+ mcp .Description ("Order direction" ),
40
+ mcp .Enum ("ASC" , "DESC" ),
41
+ ),
34
42
),
35
43
func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
36
44
// Required params
@@ -61,6 +69,27 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
61
69
categoryID = & id
62
70
}
63
71
72
+ orderBy , err := OptionalParam [string ](request , "orderBy" )
73
+ if err != nil {
74
+ return mcp .NewToolResultError (err .Error ()), nil
75
+ }
76
+ if orderBy == "" {
77
+ orderBy = "UPDATED_AT" // or "CREATED_AT"
78
+ }
79
+ direction , err := OptionalParam [string ](request , "direction" )
80
+ if err != nil {
81
+ return mcp .NewToolResultError (err .Error ()), nil
82
+ }
83
+ if direction == "" {
84
+ direction = "DESC"
85
+ }
86
+
87
+ /* orderByInput := map[string]interface{}{
88
+ "field": orderBy,
89
+ "direction": direction,
90
+ } */
91
+
92
+
64
93
// Now execute the discussions query
65
94
var discussions []* github.Discussion
66
95
if categoryID != nil {
@@ -81,14 +110,20 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
81
110
} `graphql:"category"`
82
111
URL githubv4.String `graphql:"url"`
83
112
}
84
- } `graphql:"discussions(first: 100, categoryId: $categoryId)"`
113
+ } `graphql:"discussions(first: 100, categoryId: $categoryId, orderBy: {field: $orderByField, direction: $direction} )"`
85
114
} `graphql:"repository(owner: $owner, name: $repo)"`
86
115
}
116
+
117
+
87
118
vars := map [string ]interface {}{
88
119
"owner" : githubv4 .String (owner ),
89
120
"repo" : githubv4 .String (repo ),
90
121
"categoryId" : * categoryID ,
122
+ "orderByField" : githubv4 .DiscussionOrderField (orderBy ),
123
+ "direction" : githubv4 .OrderDirection (direction ),
91
124
}
125
+
126
+
92
127
if err := client .Query (ctx , & query , vars ); err != nil {
93
128
return mcp .NewToolResultError (err .Error ()), nil
94
129
}
@@ -128,13 +163,18 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
128
163
} `graphql:"category"`
129
164
URL githubv4.String `graphql:"url"`
130
165
}
131
- } `graphql:"discussions(first: 100)"`
166
+ } `graphql:"discussions(first: 100, orderBy: {field: $orderByField, direction: $direction} )"`
132
167
} `graphql:"repository(owner: $owner, name: $repo)"`
133
168
}
169
+
170
+
134
171
vars := map [string ]interface {}{
135
- "owner" : githubv4 .String (owner ),
136
- "repo" : githubv4 .String (repo ),
172
+ "owner" : githubv4 .String (owner ),
173
+ "repo" : githubv4 .String (repo ),
174
+ "orderByField" : githubv4 .DiscussionOrderField (orderBy ),
175
+ "direction" : githubv4 .OrderDirection (direction ),
137
176
}
177
+
138
178
if err := client .Query (ctx , & query , vars ); err != nil {
139
179
return mcp .NewToolResultError (err .Error ()), nil
140
180
}
0 commit comments