From 463ff83270bf9ae771d365c3f1276edc734c6bf7 Mon Sep 17 00:00:00 2001 From: kerobbi Date: Tue, 7 Oct 2025 13:28:12 +0100 Subject: [PATCH 1/4] add sort and order params --- README.md | 2 ++ .../__toolsnaps__/search_repositories.snap | 18 ++++++++++++++++++ pkg/github/search.go | 18 ++++++++++++++++++ pkg/github/search_test.go | 6 ++++++ 4 files changed, 44 insertions(+) diff --git a/README.md b/README.md index f95810c65..fd81bdb01 100644 --- a/README.md +++ b/README.md @@ -1009,9 +1009,11 @@ The following sets of tools are available (all are on by default): - **search_repositories** - Search repositories - `minimal_output`: Return minimal repository information (default: true). When false, returns full GitHub API repository objects. (boolean, optional) + - `order`: Sort order (string, optional) - `page`: Page number for pagination (min 1) (number, optional) - `perPage`: Results per page for pagination (min 1, max 100) (number, optional) - `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) + - `sort`: Sort repositories by field, defaults to best match (string, optional) diff --git a/pkg/github/__toolsnaps__/search_repositories.snap b/pkg/github/__toolsnaps__/search_repositories.snap index f350c8e2b..99828380e 100644 --- a/pkg/github/__toolsnaps__/search_repositories.snap +++ b/pkg/github/__toolsnaps__/search_repositories.snap @@ -11,6 +11,14 @@ "description": "Return minimal repository information (default: true). When false, returns full GitHub API repository objects.", "type": "boolean" }, + "order": { + "description": "Sort order", + "enum": [ + "asc", + "desc" + ], + "type": "string" + }, "page": { "description": "Page number for pagination (min 1)", "minimum": 1, @@ -25,6 +33,16 @@ "query": { "description": "Repository search query. Examples: 'machine learning in:name stars:\u003e1000 language:python', 'topic:react', 'user:facebook'. Supports advanced search syntax for precise filtering.", "type": "string" + }, + "sort": { + "description": "Sort repositories by field, defaults to best match", + "enum": [ + "stars", + "forks", + "help-wanted-issues", + "updated" + ], + "type": "string" } }, "required": [ diff --git a/pkg/github/search.go b/pkg/github/search.go index 55e4cf8b4..a735c894b 100644 --- a/pkg/github/search.go +++ b/pkg/github/search.go @@ -26,6 +26,14 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF mcp.Required(), 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."), ), + mcp.WithString("sort", + mcp.Description("Sort repositories by field, defaults to best match"), + mcp.Enum("stars", "forks", "help-wanted-issues", "updated"), + ), + mcp.WithString("order", + mcp.Description("Sort order"), + mcp.Enum("asc", "desc"), + ), mcp.WithBoolean("minimal_output", mcp.Description("Return minimal repository information (default: true). When false, returns full GitHub API repository objects."), mcp.DefaultBool(true), @@ -37,6 +45,14 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF if err != nil { return mcp.NewToolResultError(err.Error()), nil } + sort, err := OptionalParam[string](request, "sort") + if err != nil { + return mcp.NewToolResultError(err.Error()), nil + } + order, err := OptionalParam[string](request, "order") + if err != nil { + return mcp.NewToolResultError(err.Error()), nil + } pagination, err := OptionalPaginationParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil @@ -46,6 +62,8 @@ func SearchRepositories(getClient GetClientFn, t translations.TranslationHelperF return mcp.NewToolResultError(err.Error()), nil } opts := &github.SearchOptions{ + Sort: sort, + Order: order, ListOptions: github.ListOptions{ Page: pagination.Page, PerPage: pagination.PerPage, diff --git a/pkg/github/search_test.go b/pkg/github/search_test.go index 91ca45af5..9ccf17664 100644 --- a/pkg/github/search_test.go +++ b/pkg/github/search_test.go @@ -23,6 +23,8 @@ func Test_SearchRepositories(t *testing.T) { assert.Equal(t, "search_repositories", tool.Name) assert.NotEmpty(t, tool.Description) assert.Contains(t, tool.InputSchema.Properties, "query") + assert.Contains(t, tool.InputSchema.Properties, "sort") + assert.Contains(t, tool.InputSchema.Properties, "order") assert.Contains(t, tool.InputSchema.Properties, "page") assert.Contains(t, tool.InputSchema.Properties, "perPage") assert.ElementsMatch(t, tool.InputSchema.Required, []string{"query"}) @@ -66,6 +68,8 @@ func Test_SearchRepositories(t *testing.T) { mock.GetSearchRepositories, expectQueryParams(t, map[string]string{ "q": "golang test", + "sort": "stars", + "order": "desc", "page": "2", "per_page": "10", }).andThen( @@ -75,6 +79,8 @@ func Test_SearchRepositories(t *testing.T) { ), requestArgs: map[string]interface{}{ "query": "golang test", + "sort": "stars", + "order": "desc", "page": float64(2), "perPage": float64(10), }, From b08f8e0e4bc3360a87e5336fd18858aab279a7da Mon Sep 17 00:00:00 2001 From: kerobbi Date: Wed, 8 Oct 2025 16:21:16 +0100 Subject: [PATCH 2/4] test adding server instructions for sorting --- pkg/github/instructions.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/github/instructions.go b/pkg/github/instructions.go index 7eefe53f0..ab1800178 100644 --- a/pkg/github/instructions.go +++ b/pkg/github/instructions.go @@ -36,7 +36,12 @@ Tool selection guidance: Context management: 1. Use pagination whenever possible with batches of 5-10 items. - 2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task.` + 2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task. + +For 'search_*' tools specifically: + 1. Use separate 'sort' and 'order' parameters for sorting results if available - do not include 'sort:' syntax in query strings. + 2. Query strings should contain only search criteria (e.g., 'org:google language:python'), not sorting instructions. + 3. For best results: use 'query' for what to find, 'sort' for how to order results, 'order' for direction.` allInstructions := []string{baseInstruction} allInstructions = append(allInstructions, instructions...) From 8eb9fc9c43699c5ca77727b8568c4c955aa97b9e Mon Sep 17 00:00:00 2001 From: kerobbi Date: Wed, 8 Oct 2025 16:49:34 +0100 Subject: [PATCH 3/4] improve server instructions --- pkg/github/instructions.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/github/instructions.go b/pkg/github/instructions.go index ab1800178..7df86f74e 100644 --- a/pkg/github/instructions.go +++ b/pkg/github/instructions.go @@ -38,10 +38,8 @@ Context management: 1. Use pagination whenever possible with batches of 5-10 items. 2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task. -For 'search_*' tools specifically: - 1. Use separate 'sort' and 'order' parameters for sorting results if available - do not include 'sort:' syntax in query strings. - 2. Query strings should contain only search criteria (e.g., 'org:google language:python'), not sorting instructions. - 3. For best results: use 'query' for what to find, 'sort' for how to order results, 'order' for direction.` +Tool usage guidance: + 1. For 'search_*' tools: Use separate 'sort' and 'order' parameters for sorting if available - do not include 'sort:' syntax in query strings. Query strings should contain only search criteria (e.g., 'org:google language:python'), not sorting instructions.` allInstructions := []string{baseInstruction} allInstructions = append(allInstructions, instructions...) From 9544db3e860b6298142d84250797a17116ab593d Mon Sep 17 00:00:00 2001 From: kerobbi Date: Wed, 8 Oct 2025 17:23:28 +0100 Subject: [PATCH 4/4] reorder --- pkg/github/instructions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/github/instructions.go b/pkg/github/instructions.go index 7df86f74e..3d58011aa 100644 --- a/pkg/github/instructions.go +++ b/pkg/github/instructions.go @@ -39,7 +39,7 @@ Context management: 2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task. Tool usage guidance: - 1. For 'search_*' tools: Use separate 'sort' and 'order' parameters for sorting if available - do not include 'sort:' syntax in query strings. Query strings should contain only search criteria (e.g., 'org:google language:python'), not sorting instructions.` + 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.` allInstructions := []string{baseInstruction} allInstructions = append(allInstructions, instructions...)