Add support for violations (alerts) management tools#153
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a configurable ChangesViolations toolset and cluster resolution
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant MCPServer
participant listViolationsTool
participant cluster.ResolveClusterID
participant StackRoxAPI
MCPServer->>listViolationsTool: list_violations request
listViolationsTool->>cluster.ResolveClusterID: resolve cluster ID or name
cluster.ResolveClusterID->>StackRoxAPI: GetClusters by name
listViolationsTool->>StackRoxAPI: ListAlerts with filters and pagination
StackRoxAPI-->>listViolationsTool: alert results
listViolationsTool-->>MCPServer: ViolationResult page and nextCursor
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/cluster/resolver.go`:
- Around line 12-14: Update ResolveClusterID to wrap failures from the
GetClusters API call with client.NewError before returning them, while
preserving the existing not-found behavior and successful cluster ID resolution.
Ensure every error propagated by this exported resolver follows the user-facing
client error mapping.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 545aa2c1-daa6-4778-a962-6a584471c58e
📒 Files selected for processing (10)
examples/config-read-only.yamlinternal/app/app.gointernal/cluster/resolver.gointernal/cluster/resolver_test.gointernal/config/config.gointernal/toolsets/violations/tools.gointernal/toolsets/violations/toolset.gointernal/toolsets/vulnerability/clusters.gointernal/toolsets/vulnerability/deployments.gointernal/toolsets/vulnerability/nodes.go
| // ResolveClusterID resolves a cluster name to its ID. | ||
| // Returns error if cluster name is not found or if API call fails. | ||
| func resolveClusterID(ctx context.Context, conn *grpc.ClientConn, | ||
| func ResolveClusterID(ctx context.Context, conn *grpc.ClientConn, |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Convert cluster API failures with client.NewError.
The exported resolver returns the raw GetClusters gRPC error through every consuming MCP handler, potentially exposing backend details and bypassing consistent error mapping.
Proposed fix
import (
+ "github.com/stackrox/stackrox-mcp/internal/client"
)
// ...
if err != nil {
- return "", fmt.Errorf("failed to fetch clusters: %w", err)
+ return "", client.NewError(err, "GetClusters")
}As per path instructions, Go MCP server code requires “Proper error wrapping with client.NewError for user-facing errors.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/cluster/resolver.go` around lines 12 - 14, Update ResolveClusterID
to wrap failures from the GetClusters API call with client.NewError before
returning them, while preserving the existing not-found behavior and successful
cluster ID resolution. Ensure every error propagated by this exported resolver
follows the user-facing client error mapping.
Source: Path instructions
Description
Adds support for listing violations data. Note that this change also exports ResolveClusterID from a shared location.
Validation
Tested with Claude Code (Opus 4.6) and RHACS 4.11: