| 126 | } |
| 127 | |
| 128 | func ListDiscussions(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 129 | return NewTool( |
| 130 | ToolsetMetadataDiscussions, |
| 131 | mcp.Tool{ |
| 132 | Name: "list_discussions", |
| 133 | Description: t("TOOL_LIST_DISCUSSIONS_DESCRIPTION", "List discussions for a repository or organisation."), |
| 134 | Annotations: &mcp.ToolAnnotations{ |
| 135 | Title: t("TOOL_LIST_DISCUSSIONS_USER_TITLE", "List discussions"), |
| 136 | ReadOnlyHint: true, |
| 137 | }, |
| 138 | InputSchema: WithCursorPagination(&jsonschema.Schema{ |
| 139 | Type: "object", |
| 140 | Properties: map[string]*jsonschema.Schema{ |
| 141 | "owner": { |
| 142 | Type: "string", |
| 143 | Description: "Repository owner", |
| 144 | }, |
| 145 | "repo": { |
| 146 | Type: "string", |
| 147 | Description: "Repository name. If not provided, discussions will be queried at the organisation level.", |
| 148 | }, |
| 149 | "category": { |
| 150 | Type: "string", |
| 151 | Description: "Optional filter by discussion category ID. If provided, only discussions with this category are listed.", |
| 152 | }, |
| 153 | "orderBy": { |
| 154 | Type: "string", |
| 155 | Description: "Order discussions by field. If provided, the 'direction' also needs to be provided.", |
| 156 | Enum: []any{"CREATED_AT", "UPDATED_AT"}, |
| 157 | }, |
| 158 | "direction": { |
| 159 | Type: "string", |
| 160 | Description: "Order direction.", |
| 161 | Enum: []any{"ASC", "DESC"}, |
| 162 | }, |
| 163 | }, |
| 164 | Required: []string{"owner"}, |
| 165 | }), |
| 166 | }, |
| 167 | []scopes.Scope{scopes.Repo}, |
| 168 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 169 | owner, err := RequiredParam[string](args, "owner") |
| 170 | if err != nil { |
| 171 | return utils.NewToolResultError(err.Error()), nil, nil |
| 172 | } |
| 173 | repo, err := OptionalParam[string](args, "repo") |
| 174 | if err != nil { |
| 175 | return utils.NewToolResultError(err.Error()), nil, nil |
| 176 | } |
| 177 | // when not provided, default to the .github repository |
| 178 | // this will query discussions at the organisation level |
| 179 | if repo == "" { |
| 180 | repo = ".github" |
| 181 | } |
| 182 | |
| 183 | category, err := OptionalParam[string](args, "category") |
| 184 | if err != nil { |
| 185 | return utils.NewToolResultError(err.Error()), nil, nil |