Skip to content
Merged
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
22 changes: 17 additions & 5 deletions cmd/cli/cmd/findings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/nullify-platform/cli/internal/auth"
"github.com/nullify-platform/cli/internal/client"
Expand Down Expand Up @@ -77,10 +78,12 @@ Results are paginated automatically up to --limit total findings.`,
Total int `json:"total"`
HasMoreData bool `json:"hasMoreData"`
ScrollID *string `json:"scrollId"`
Page int `json:"page"`
}

allFindings := make([]json.RawMessage, 0)
var scrollID string
nextPage := 1
var lastTotal int

for {
Expand All @@ -95,15 +98,20 @@ Results are paginated automatically up to --limit total findings.`,

query := map[string]any{
"pageSize": pageSize,
"page": nextPage,
}
if repo != "" {
query["repository"] = []string{repo}
}
if severity != "" {
query["severity"] = []string{severity}
query["severity"] = []string{strings.ToUpper(severity)}
}
if findingType != "" {
query["type"] = []string{findingType}
if apiType, ok := findingTypeToAPI[findingType]; ok {
query["type"] = []string{apiType}
} else {
query["type"] = []string{findingType}
}
}
if scrollID != "" {
query["scrollId"] = scrollID
Expand Down Expand Up @@ -161,13 +169,17 @@ Results are paginated automatically up to --limit total findings.`,
lastTotal = resp.Total

if debug {
fmt.Fprintf(os.Stderr, "[debug] page fetched: %d findings, hasMoreData=%v, total=%d\n", len(resp.Findings), resp.HasMoreData, resp.Total)
fmt.Fprintf(os.Stderr, "[debug] page %d fetched: %d findings, hasMoreData=%v, total=%d\n", nextPage, len(resp.Findings), resp.HasMoreData, resp.Total)
}

if !resp.HasMoreData || resp.ScrollID == nil || *resp.ScrollID == "" {
if !resp.HasMoreData || len(resp.Findings) == 0 {
break
}
scrollID = *resp.ScrollID
if resp.ScrollID != nil && *resp.ScrollID != "" {
scrollID = *resp.ScrollID
} else {
nextPage = resp.Page + 1
}
}

result := findingsOutput{
Expand Down
12 changes: 12 additions & 0 deletions cmd/cli/cmd/scanners.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package cmd

// findingTypeToAPI maps CLI type slugs to the API's FindingType values.
// The unified /admin/findings endpoint uses PascalCase type names.
var findingTypeToAPI = map[string]string{
"sast": "Code",
"sca_dependencies": "Dependencies",
"sca_containers": "Containers",
"secrets": "Secrets",
"pentest": "Pentest",
"bughunt": "BugHunting",
"cspm": "Cloud",
}

// scannerEndpoint represents a scanner type and its API path.
type scannerEndpoint struct {
name string
Expand Down
31 changes: 27 additions & 4 deletions internal/mcp/tools_unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ import (
"github.com/mark3labs/mcp-go/server"
)

// findingTypeToAPI maps CLI type slugs to the API's FindingType values
// used by the unified /admin/findings endpoint.
var findingTypeToAPI = map[string]string{
"sast": "Code",
"sca_dependencies": "Dependencies",
"sca_containers": "Containers",
"secrets": "Secrets",
"pentest": "Pentest",
"bughunt": "BugHunting",
"cspm": "Cloud",
}

type findingTypeConfig struct {
basePath string
triage bool
Expand Down Expand Up @@ -93,6 +105,7 @@ func registerUnifiedTools(s *server.MCPServer, c *client.NullifyClient, queryPar
Total int `json:"total"`
HasMoreData bool `json:"hasMoreData"`
ScrollID *string `json:"scrollId"`
Page int `json:"page"`
}

type searchOutput struct {
Expand All @@ -102,6 +115,7 @@ func registerUnifiedTools(s *server.MCPServer, c *client.NullifyClient, queryPar

allFindings := make([]json.RawMessage, 0)
var scrollID string
nextPage := 1
var lastTotal int

for {
Expand All @@ -116,18 +130,23 @@ func registerUnifiedTools(s *server.MCPServer, c *client.NullifyClient, queryPar

query := map[string]any{
"pageSize": pageSize,
"page": nextPage,
}
if repository != "" {
query["repository"] = []string{repository}
}
if severity != "" {
query["severity"] = []string{severity}
query["severity"] = []string{strings.ToUpper(severity)}
}
if typeName != "" {
if _, err := resolveFindingType(typeName); err != nil {
return toolError(err), nil
}
query["type"] = []string{typeName}
if apiType, ok := findingTypeToAPI[typeName]; ok {
query["type"] = []string{apiType}
} else {
query["type"] = []string{typeName}
}
}
if scrollID != "" {
query["scrollId"] = scrollID
Expand Down Expand Up @@ -168,10 +187,14 @@ func registerUnifiedTools(s *server.MCPServer, c *client.NullifyClient, queryPar
allFindings = append(allFindings, resp.Findings...)
lastTotal = resp.Total

if !resp.HasMoreData || resp.ScrollID == nil || *resp.ScrollID == "" {
if !resp.HasMoreData || len(resp.Findings) == 0 {
break
}
scrollID = *resp.ScrollID
if resp.ScrollID != nil && *resp.ScrollID != "" {
scrollID = *resp.ScrollID
} else {
nextPage = resp.Page + 1
}
}

out, _ := json.MarshalIndent(searchOutput{Findings: allFindings, Total: lastTotal}, "", " ")
Expand Down
Loading