UnstarRepository creates a tool to unstar a repository.
(t translations.TranslationHelperFunc)
| 2203 | |
| 2204 | // UnstarRepository creates a tool to unstar a repository. |
| 2205 | func UnstarRepository(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 2206 | return NewTool( |
| 2207 | ToolsetMetadataStargazers, |
| 2208 | mcp.Tool{ |
| 2209 | Name: "unstar_repository", |
| 2210 | Description: t("TOOL_UNSTAR_REPOSITORY_DESCRIPTION", "Unstar a GitHub repository"), |
| 2211 | Annotations: &mcp.ToolAnnotations{ |
| 2212 | Title: t("TOOL_UNSTAR_REPOSITORY_USER_TITLE", "Unstar repository"), |
| 2213 | ReadOnlyHint: false, |
| 2214 | }, |
| 2215 | InputSchema: &jsonschema.Schema{ |
| 2216 | Type: "object", |
| 2217 | Properties: map[string]*jsonschema.Schema{ |
| 2218 | "owner": { |
| 2219 | Type: "string", |
| 2220 | Description: "Repository owner", |
| 2221 | }, |
| 2222 | "repo": { |
| 2223 | Type: "string", |
| 2224 | Description: "Repository name", |
| 2225 | }, |
| 2226 | }, |
| 2227 | Required: []string{"owner", "repo"}, |
| 2228 | }, |
| 2229 | }, |
| 2230 | []scopes.Scope{scopes.Repo}, |
| 2231 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 2232 | owner, err := RequiredParam[string](args, "owner") |
| 2233 | if err != nil { |
| 2234 | return utils.NewToolResultError(err.Error()), nil, nil |
| 2235 | } |
| 2236 | repo, err := RequiredParam[string](args, "repo") |
| 2237 | if err != nil { |
| 2238 | return utils.NewToolResultError(err.Error()), nil, nil |
| 2239 | } |
| 2240 | |
| 2241 | client, err := deps.GetClient(ctx) |
| 2242 | if err != nil { |
| 2243 | return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err) |
| 2244 | } |
| 2245 | |
| 2246 | resp, err := client.Activity.Unstar(ctx, owner, repo) |
| 2247 | if err != nil { |
| 2248 | return ghErrors.NewGitHubAPIErrorResponse(ctx, |
| 2249 | fmt.Sprintf("failed to unstar repository %s/%s", owner, repo), |
| 2250 | resp, |
| 2251 | err, |
| 2252 | ), nil, nil |
| 2253 | } |
| 2254 | defer func() { _ = resp.Body.Close() }() |
| 2255 | |
| 2256 | if resp.StatusCode != 204 { |
| 2257 | body, err := io.ReadAll(resp.Body) |
| 2258 | if err != nil { |
| 2259 | return nil, nil, fmt.Errorf("failed to read response body: %w", err) |
| 2260 | } |
| 2261 | return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to unstar repository", resp, body), nil, nil |
| 2262 | } |