Skip to content

Commit 8260a40

Browse files
committed
hide implementation detail for org-level queries
1 parent ff6e859 commit 8260a40

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

pkg/github/discussions.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func GetDiscussionComments(getGQLClient GetGQLClientFn, t translations.Translati
443443

444444
func ListDiscussionCategories(getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
445445
return mcp.NewTool("list_discussion_categories",
446-
mcp.WithDescription(t("TOOL_LIST_DISCUSSION_CATEGORIES_DESCRIPTION", "List discussion categories with their id and name, for a repository")),
446+
mcp.WithDescription(t("TOOL_LIST_DISCUSSION_CATEGORIES_DESCRIPTION", "List discussion categories with their id and name, for a repository or organisation.")),
447447
mcp.WithToolAnnotation(mcp.ToolAnnotation{
448448
Title: t("TOOL_LIST_DISCUSSION_CATEGORIES_USER_TITLE", "List discussion categories"),
449449
ReadOnlyHint: ToBoolPtr(true),
@@ -453,19 +453,23 @@ func ListDiscussionCategories(getGQLClient GetGQLClientFn, t translations.Transl
453453
mcp.Description("Repository owner"),
454454
),
455455
mcp.WithString("repo",
456-
mcp.Required(),
457-
mcp.Description("Repository name"),
456+
mcp.Description("Repository name. If not provided, discussion categories will be queried at the organisation level."),
458457
),
459458
),
460459
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
461-
// Decode params
462-
var params struct {
463-
Owner string
464-
Repo string
460+
owner, err := RequiredParam[string](request, "owner")
461+
if err != nil {
462+
return mcp.NewToolResultError(err.Error()), nil
465463
}
466-
if err := mapstructure.Decode(request.Params.Arguments, &params); err != nil {
464+
repo, err := OptionalParam[string](request, "repo")
465+
if err != nil {
467466
return mcp.NewToolResultError(err.Error()), nil
468467
}
468+
// when not provided, default to the .github repository
469+
// this will query discussion categories at the organisation level
470+
if repo == "" {
471+
repo = ".github"
472+
}
469473

470474
client, err := getGQLClient(ctx)
471475
if err != nil {
@@ -490,8 +494,8 @@ func ListDiscussionCategories(getGQLClient GetGQLClientFn, t translations.Transl
490494
} `graphql:"repository(owner: $owner, name: $repo)"`
491495
}
492496
vars := map[string]interface{}{
493-
"owner": githubv4.String(params.Owner),
494-
"repo": githubv4.String(params.Repo),
497+
"owner": githubv4.String(owner),
498+
"repo": githubv4.String(repo),
495499
"first": githubv4.Int(25),
496500
}
497501
if err := client.Query(ctx, &q, vars); err != nil {

0 commit comments

Comments
 (0)