Skip to content

Commit 463ff83

Browse files
committed
add sort and order params
1 parent 8a69a5c commit 463ff83

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,11 @@ The following sets of tools are available (all are on by default):
10091009

10101010
- **search_repositories** - Search repositories
10111011
- `minimal_output`: Return minimal repository information (default: true). When false, returns full GitHub API repository objects. (boolean, optional)
1012+
- `order`: Sort order (string, optional)
10121013
- `page`: Page number for pagination (min 1) (number, optional)
10131014
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
10141015
- `query`: Repository search query. Examples: 'machine learning in:name stars:>1000 language:python', 'topic:react', 'user:facebook'. Supports advanced search syntax for precise filtering. (string, required)
1016+
- `sort`: Sort repositories by field, defaults to best match (string, optional)
10151017

10161018
</details>
10171019

pkg/github/__toolsnaps__/search_repositories.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
"description": "Return minimal repository information (default: true). When false, returns full GitHub API repository objects.",
1212
"type": "boolean"
1313
},
14+
"order": {
15+
"description": "Sort order",
16+
"enum": [
17+
"asc",
18+
"desc"
19+
],
20+
"type": "string"
21+
},
1422
"page": {
1523
"description": "Page number for pagination (min 1)",
1624
"minimum": 1,
@@ -25,6 +33,16 @@
2533
"query": {
2634
"description": "Repository search query. Examples: 'machine learning in:name stars:\u003e1000 language:python', 'topic:react', 'user:facebook'. Supports advanced search syntax for precise filtering.",
2735
"type": "string"
36+
},
37+
"sort": {
38+
"description": "Sort repositories by field, defaults to best match",
39+
"enum": [
40+
"stars",
41+
"forks",
42+
"help-wanted-issues",
43+
"updated"
44+
],
45+
"type": "string"
2846
}
2947
},
3048
"required": [

pkg/github/search.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF
2626
mcp.Required(),
2727
mcp.Description("Repository search query. Examples: 'machine learning in:name stars:>1000 language:python', 'topic:react', 'user:facebook'. Supports advanced search syntax for precise filtering."),
2828
),
29+
mcp.WithString("sort",
30+
mcp.Description("Sort repositories by field, defaults to best match"),
31+
mcp.Enum("stars", "forks", "help-wanted-issues", "updated"),
32+
),
33+
mcp.WithString("order",
34+
mcp.Description("Sort order"),
35+
mcp.Enum("asc", "desc"),
36+
),
2937
mcp.WithBoolean("minimal_output",
3038
mcp.Description("Return minimal repository information (default: true). When false, returns full GitHub API repository objects."),
3139
mcp.DefaultBool(true),
@@ -37,6 +45,14 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF
3745
if err != nil {
3846
return mcp.NewToolResultError(err.Error()), nil
3947
}
48+
sort, err := OptionalParam[string](request, "sort")
49+
if err != nil {
50+
return mcp.NewToolResultError(err.Error()), nil
51+
}
52+
order, err := OptionalParam[string](request, "order")
53+
if err != nil {
54+
return mcp.NewToolResultError(err.Error()), nil
55+
}
4056
pagination, err := OptionalPaginationParams(request)
4157
if err != nil {
4258
return mcp.NewToolResultError(err.Error()), nil
@@ -46,6 +62,8 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF
4662
return mcp.NewToolResultError(err.Error()), nil
4763
}
4864
opts := &github.SearchOptions{
65+
Sort: sort,
66+
Order: order,
4967
ListOptions: github.ListOptions{
5068
Page: pagination.Page,
5169
PerPage: pagination.PerPage,

pkg/github/search_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func Test_SearchRepositories(t *testing.T) {
2323
assert.Equal(t, "search_repositories", tool.Name)
2424
assert.NotEmpty(t, tool.Description)
2525
assert.Contains(t, tool.InputSchema.Properties, "query")
26+
assert.Contains(t, tool.InputSchema.Properties, "sort")
27+
assert.Contains(t, tool.InputSchema.Properties, "order")
2628
assert.Contains(t, tool.InputSchema.Properties, "page")
2729
assert.Contains(t, tool.InputSchema.Properties, "perPage")
2830
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"query"})
@@ -66,6 +68,8 @@ func Test_SearchRepositories(t *testing.T) {
6668
mock.GetSearchRepositories,
6769
expectQueryParams(t, map[string]string{
6870
"q": "golang test",
71+
"sort": "stars",
72+
"order": "desc",
6973
"page": "2",
7074
"per_page": "10",
7175
}).andThen(
@@ -75,6 +79,8 @@ func Test_SearchRepositories(t *testing.T) {
7579
),
7680
requestArgs: map[string]interface{}{
7781
"query": "golang test",
82+
"sort": "stars",
83+
"order": "desc",
7884
"page": float64(2),
7985
"perPage": float64(10),
8086
},

0 commit comments

Comments
 (0)