Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ The following sets of tools are available:
- `owner`: Repository owner (username or organization name) (string, required)
- `repo`: Repository name (string, required)

- **list_label** - List labels from a repository
- **list_label** - List labels from a repository, ordered by issue count (descending) so the most-used labels are returned first
- **Required OAuth Scopes**: `repo`
- `owner`: Repository owner (username or organization name) - required for all operations (string, required)
- `repo`: Repository name - required for all operations (string, required)
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/__toolsnaps__/list_label.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"readOnlyHint": true,
"title": "List labels from a repository"
},
"description": "List labels from a repository",
"description": "List labels from a repository, ordered by issue count (descending) so the most-used labels are returned first",
"inputSchema": {
"properties": {
"owner": {
Expand Down
12 changes: 10 additions & 2 deletions pkg/github/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/shurcooL/githubv4"
)

// labelOrderFieldIssueCount orders labels by the number of issues they are assigned to.
// It is not part of the githubv4.LabelOrderField constants shipped with the client library
// (or GitHub's public GraphQL schema docs), but the API accepts it, so we define it locally.
const labelOrderFieldIssueCount githubv4.LabelOrderField = "ISSUE_COUNT"

// GetLabel retrieves a specific label by name from a GitHub repository
func GetLabel(t translations.TranslationHelperFunc) inventory.ServerTool {
return NewTool(
Expand Down Expand Up @@ -129,7 +134,7 @@ func ListLabels(t translations.TranslationHelperFunc) inventory.ServerTool {
ToolsetLabels,
mcp.Tool{
Name: "list_label",
Description: t("TOOL_LIST_LABEL_DESCRIPTION", "List labels from a repository"),
Description: t("TOOL_LIST_LABEL_DESCRIPTION", "List labels from a repository, ordered by issue count (descending) so the most-used labels are returned first"),
Annotations: &mcp.ToolAnnotations{
Title: t("TOOL_LIST_LABEL_DESCRIPTION", "List labels from a repository"),
ReadOnlyHint: true,
Comment on lines +137 to 140
Expand Down Expand Up @@ -176,13 +181,16 @@ func ListLabels(t translations.TranslationHelperFunc) inventory.ServerTool {
Description githubv4.String
}
TotalCount githubv4.Int
} `graphql:"labels(first: 100)"`
} `graphql:"labels(first: 100, orderBy: {field: $orderByField, direction: $orderByDirection})"`
} `graphql:"repository(owner: $owner, name: $repo)"`
}

vars := map[string]any{
"owner": githubv4.String(owner),
"repo": githubv4.String(repo),
// Order labels by issue count (descending) so the most-used labels are returned first.
"orderByField": labelOrderFieldIssueCount,
"orderByDirection": githubv4.OrderDirectionDesc,
}

if err := client.Query(ctx, &query, vars); err != nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/github/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ func TestListLabels(t *testing.T) {
Description githubv4.String
}
TotalCount githubv4.Int
} `graphql:"labels(first: 100)"`
} `graphql:"labels(first: 100, orderBy: {field: $orderByField, direction: $orderByDirection})"`
} `graphql:"repository(owner: $owner, name: $repo)"`
}{},
map[string]any{
"owner": githubv4.String("owner"),
"repo": githubv4.String("repo"),
"owner": githubv4.String("owner"),
"repo": githubv4.String("repo"),
"orderByField": labelOrderFieldIssueCount,
"orderByDirection": githubv4.OrderDirectionDesc,
},
githubv4mock.DataResponse(map[string]any{
"repository": map[string]any{
Expand Down
Loading