Skip to content

feat: critical-first sort and improved MCP pagination#21

Open
algorni wants to merge 5 commits into
mainfrom
feat/critical-first
Open

feat: critical-first sort and improved MCP pagination#21
algorni wants to merge 5 commits into
mainfrom
feat/critical-first

Conversation

@algorni

@algorni algorni commented May 29, 2026

Copy link
Copy Markdown

Summary

  • Critical-first by default: for severity-based analysis types (cve, hardening, password-hash, capabilities) the default sort order is now desc so the most critical findings appear first. All other types keep asc (alphabetical by name/type).
  • New --sort-order flag on analyzer scan results (CLI) and sort_order param on the MCP get_analysis_results tool to override the default.
  • Pagination envelope in get_analysis_results JSON response: the response now wraps findings in { current_page, total_pages, total_findings, findings } so the LLM always knows exactly how many pages remain without guessing.
  • Updated MCP server instructions with explicit fetch-all pattern documentation.
  • Introduces ResultsOptions struct to keep run_results within clippy's 7-argument limit.

Test plan

  • analyzer scan results --object <uuid> --analysis cve shows CRITICAL findings first
  • analyzer scan results --object <uuid> --analysis cve --sort-order asc shows LOW findings first
  • analyzer scan results --object <uuid> --analysis capabilities shows HIGH findings first
  • MCP get_analysis_results JSON response includes current_page, total_pages, total_findings
  • total_pages is correct: ceil(total_findings / per_page)
  • CI passes

🤖 Generated with Claude Code

Alberto Gorni and others added 2 commits May 29, 2026 10:15
For CVE, hardening, password-hash and capabilities analyses the default
sort order is now "desc" so the most critical findings appear first.
Other analysis types keep "asc" (alphabetical by name/type).

Adds --sort-order asc|desc flag to `analyzer scan results` and a
sort_order param to the MCP get_analysis_results tool for overriding
the default. Introduces ResultsOptions struct to keep run_results
within clippy's argument-count limit.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The JSON response now wraps findings in an envelope with:
  current_page (1-based), total_pages, total_findings, findings.

This gives the LLM all the information needed to iterate pages
without guessing. Also updates the tool description and server
instructions to explicitly document the fetch-all pattern.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@algorni algorni requested a review from krsh May 29, 2026 12:50
Comment thread src/commands/scan.rs Outdated
pub struct ResultsOptions {
pub page: Option<u32>,
pub per_page: Option<u32>,
pub sort_order: Option<String>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing Option<String> with a enum SortOrder { Asc, Desc }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/mcp.rs
Ok(results) => match self.mcp_format {
McpFormat::Json => ok_json(&results),
McpFormat::Json => {
let total_pages = results.total_findings.div_ceil(per_page as u64).max(1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per_page = 0 will panic

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i should have fixed now

Comment thread src/mcp.rs
Ok(results) => match self.mcp_format {
McpFormat::Json => ok_json(&results),
McpFormat::Json => {
let total_pages = results.total_findings.div_ceil(per_page as u64).max(1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent .max(1) on total_pages. The MCP JSON envelope clamps to 1, so empty results read total_pages: 1. The CLI human path and MCP text path don't , they print "Page 1/0" on empty results.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right aligned the behavour now

Alberto Gorni and others added 3 commits June 3, 2026 15:49
- Add SortOrder { Asc, Desc } enum with clap::ValueEnum, serde and
  JsonSchema derives — CLI validates at parse time, MCP schema gets
  "enum": ["asc","desc"] so the LLM cannot pass invalid values.
- Fix per_page=0 panic: clamp to max(1) before div_ceil.
- Fix inconsistent .max(1) on total_pages: apply it uniformly in
  CLI human output, MCP JSON envelope, and MCP text formatter.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- page=0 is silently treated as page=1 (both CLI and MCP).
- per_page is clamped to [1, 100] to prevent oversized responses
  that could exhaust memory or consume LLM context budget.
- Update help text and MCP param descriptions to document the bounds.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@algorni algorni requested a review from krsh June 3, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants