| 18 | ) |
| 19 | |
| 20 | func GetCodeScanningAlert(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 21 | return NewTool( |
| 22 | ToolsetMetadataCodeSecurity, |
| 23 | mcp.Tool{ |
| 24 | Name: "get_code_scanning_alert", |
| 25 | Description: t("TOOL_GET_CODE_SCANNING_ALERT_DESCRIPTION", "Get details of a specific code scanning alert in a GitHub repository."), |
| 26 | Annotations: &mcp.ToolAnnotations{ |
| 27 | Title: t("TOOL_GET_CODE_SCANNING_ALERT_USER_TITLE", "Get code scanning alert"), |
| 28 | ReadOnlyHint: true, |
| 29 | }, |
| 30 | InputSchema: &jsonschema.Schema{ |
| 31 | Type: "object", |
| 32 | Properties: map[string]*jsonschema.Schema{ |
| 33 | "owner": { |
| 34 | Type: "string", |
| 35 | Description: "The owner of the repository.", |
| 36 | }, |
| 37 | "repo": { |
| 38 | Type: "string", |
| 39 | Description: "The name of the repository.", |
| 40 | }, |
| 41 | "alertNumber": { |
| 42 | Type: "number", |
| 43 | Description: "The number of the alert.", |
| 44 | }, |
| 45 | }, |
| 46 | Required: []string{"owner", "repo", "alertNumber"}, |
| 47 | }, |
| 48 | }, |
| 49 | []scopes.Scope{scopes.SecurityEvents}, |
| 50 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 51 | owner, err := RequiredParam[string](args, "owner") |
| 52 | if err != nil { |
| 53 | return utils.NewToolResultError(err.Error()), nil, nil |
| 54 | } |
| 55 | repo, err := RequiredParam[string](args, "repo") |
| 56 | if err != nil { |
| 57 | return utils.NewToolResultError(err.Error()), nil, nil |
| 58 | } |
| 59 | alertNumber, err := RequiredInt(args, "alertNumber") |
| 60 | if err != nil { |
| 61 | return utils.NewToolResultError(err.Error()), nil, nil |
| 62 | } |
| 63 | |
| 64 | client, err := deps.GetClient(ctx) |
| 65 | if err != nil { |
| 66 | return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil |
| 67 | } |
| 68 | |
| 69 | alert, resp, err := client.CodeScanning.GetAlert(ctx, owner, repo, int64(alertNumber)) |
| 70 | if err != nil { |
| 71 | return ghErrors.NewGitHubAPIErrorResponse(ctx, |
| 72 | "failed to get alert", |
| 73 | resp, |
| 74 | err, |
| 75 | ), nil, nil |
| 76 | } |
| 77 | defer func() { _ = resp.Body.Close() }() |