Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16b43c9

Browse files
authored
Add sort and order parameters to search_repositories tool (#1191)
* add sort and order params* test adding server instructions for sorting* improve server instructions* reorder
1 parentdc7c27c commit16b43c9

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,11 @@ Possible options:
993993

994994
-**search_repositories** - Search repositories
995995
-`minimal_output`: Return minimal repository information (default: true). When false, returns full GitHub API repository objects. (boolean, optional)
996+
-`order`: Sort order (string, optional)
996997
-`page`: Page number for pagination (min 1) (number, optional)
997998
-`perPage`: Results per page for pagination (min 1, max 100) (number, optional)
998999
-`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)
1000+
-`sort`: Sort repositories by field, defaults to best match (string, optional)
9991001

10001002
</details>
10011003

‎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/instructions.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ Tool selection guidance:
3636
3737
Context management:
3838
1. Use pagination whenever possible with batches of 5-10 items.
39-
2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task.`
39+
2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task.
40+
41+
Tool usage guidance:
42+
1. For 'search_*' tools: Use separate 'sort' and 'order' parameters if available for sorting results - do not include 'sort:' syntax in query strings. Query strings should contain only search criteria (e.g., 'org:google language:python'), not sorting instructions.`
4043

4144
allInstructions:= []string{baseInstruction}
4245
allInstructions=append(allInstructions,instructions...)

‎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
iferr!=nil {
3846
returnmcp.NewToolResultError(err.Error()),nil
3947
}
48+
sort,err:=OptionalParam[string](request,"sort")
49+
iferr!=nil {
50+
returnmcp.NewToolResultError(err.Error()),nil
51+
}
52+
order,err:=OptionalParam[string](request,"order")
53+
iferr!=nil {
54+
returnmcp.NewToolResultError(err.Error()),nil
55+
}
4056
pagination,err:=OptionalPaginationParams(request)
4157
iferr!=nil {
4258
returnmcp.NewToolResultError(err.Error()),nil
@@ -46,6 +62,8 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF
4662
returnmcp.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)

[8]ページ先頭

©2009-2025 Movatter.jp