Document and test sarif_list_rules per-rule resultCount field#219
Conversation
- Add second sql-injection result to test fixture for varied counts - Verify resultCount for all rules (not just the first) - Add test for rules with zero results (resultCount: 0) - Update related test assertions for the enriched fixture Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/7ea1caeb-de6d-40cd-b045-3dd634602403 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Address code review feedback: extract inline SARIF object into createZeroResultsSarif() helper for consistency with existing patterns. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/7ea1caeb-de6d-40cd-b045-3dd634602403 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
sarif_list_rules test coverage for per-rule resultCount
Document the per-rule resultCount field and complete response schema in the MCP resource file served to LLMs at runtime. Includes JSON example, top-level field descriptions, and per-rule field reference with types and required/optional markers. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/c1d03a5c-2041-41bb-a120-365ddf420c5b Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/c1d03a5c-2041-41bb-a120-365ddf420c5b Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Added production changes in d21f47a: Note: the |
sarif_list_rules test coverage for per-rule resultCountsarif_list_rules per-rule resultCount field
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned Files
|
There was a problem hiding this comment.
Pull request overview
This PR improves the usability of the sarif_list_rules MCP tool by documenting the full response schema (including per-rule resultCount) in the runtime-served tools resource, and by strengthening tests to validate varying and zero-result scenarios.
Changes:
- Expanded
server-tools.mdwith a detailedsarif_list_rulesresponse format section (example JSON + field tables). - Updated SARIF test fixtures and assertions to validate per-rule
resultCountacross multiple rules and a zero-results rule. - Regenerated the bundled server output to include the updated resource content.
Show a summary per file
| File | Description |
|---|---|
| server/test/src/tools/sarif-tools.test.ts | Enhances SARIF tool tests to catch constant/incorrect counting and validate zero-result rules. |
| server/src/resources/server-tools.md | Documents sarif_list_rules output schema for LLM consumers (per-rule and summary fields). |
| server/dist/codeql-development-mcp-server.js | Updates bundled artifact to include the latest server-tools.md content. |
| package-lock.json | Lockfile change included in PR scope (appears unrelated to the stated “no dependencies” change). |
Copilot's findings
- Files reviewed: 2/5 changed files
- Comments generated: 0
📝 Update Information
Primitive Details
sarif_list_rules✅ ALLOWED FILES:
server/src/**/*.ts)server/test/**/*.ts)server/src/resources/server-tools.md)🚫 FORBIDDEN FILES:
🛑 MANDATORY PR VALIDATION CHECKLIST
Update Metadata
🎯 Changes Description
Current Behavior
The
resultCountfield is implemented inSarifRuleSummary,listSarifRules(), and thesarif_list_rulestool response. However, the per-ruleresultCountfield and complete response schema were not documented in theserver-tools.mdMCP resource served to LLMs at runtime. Additionally, the tool-level test only assertedresultCounton the first rule, used a fixture where every rule had exactly 1 result (making off-by-one bugs invisible), and had no test for zero-result rules.Updated Behavior
The
server/src/resources/server-tools.mdresource now includes asarif_list_rulesResponse Format section documenting the per-ruleresultCountfield, complete JSON response example, top-level summary fields (totalRules,totalResults), and per-rule field reference table with types and required/optional markers. Test fixture now has varying result counts per rule (2 vs 1). Assertions coverresultCounton every rule. A dedicated test validatesresultCount: 0for defined-but-untriggered rules.Motivation
The per-rule
resultCountfield and response schema were undocumented in the MCP resource served to LLMs, making it harder for AI assistants to understand the tool's output format. The existing tool-level test could not distinguish a correct implementation from one that always returns1. These changes close both gaps.🔄 Before vs. After Comparison
Documentation Changes
Test Fixture Changes
New Test Case
🧪 Testing & Validation
Test Coverage Updates
sarif_extract_rule,sarif_diff_runs) for enriched fixtureTest Results
📋 Implementation Details
Files Modified
server/src/resources/server-tools.md— Addedsarif_list_rulesResponse Format section with JSON example, field tables, and per-ruleresultCountdocumentationserver/test/src/tools/sarif-tools.test.ts— Enhanced test coverage for per-ruleresultCountCode Changes Summary
sarif_list_rulesResponse Format section toserver-tools.mdwith JSON example, top-level field descriptions, and per-rule field reference tablejs/sql-injectionresult tocreateTestSarif()fixture for varying countscreateZeroResultsSarif()helper (consistent with existing fixture pattern)resultCountfor all rules insarif_list_rulestest'should return resultCount 0 for rules with no results'testsarif_extract_ruleexpected count from 1→2sarif_diff_runsresult filtering tofilter()instead of index-based spliceDependencies
🔗 References
Related Issues/PRs
🚀 Compatibility & Migration
Backward Compatibility
API Evolution
👥 Review Guidelines
For Reviewers
Testing Instructions