Skip to content

AIML-343: Fix get_scan_project returning empty data - #59

Merged
ChrisEdwards merged 1 commit into
mainfrom
AIML-343-get-scan-project-empty-data
Jan 7, 2026
Merged

ChrisEdwards merged 1 commit into
mainfrom
AIML-343-get-scan-project-empty-data

Conversation

@ChrisEdwards

@ChrisEdwards ChrisEdwards commented Jan 4, 2026 •

Copy link
Copy Markdown
Collaborator

Rebased onto main after #58 merged.


Why

The get_scan_project MCP tool was completely broken - it returned {"found": true, "data": {}} instead of actual project data. AI agents couldn't access any SAST project metadata (vulnerability counts, scan history, language, etc.).

Before this fix:

{
  "found": true,
  "data": {}
}

After this fix:

{
  "found": true,
  "data": {
    "id": "c9d93078-4ebb-49f2-b98f-75ac013a3d86",
    "name": "webgoat",
    "language": "JAVA",
    "critical": 0,
    "high": 12,
    "medium": 45,
    ...
  }
}

What

File Change
ScanProject.java NEW - Serializable record for project data
GetSastProjectTool.java Use ScanProject instead of raw SDK Project
ScanProjectTest.java NEW - Unit tests (5 test cases)
GetSastProjectToolIT.java NEW - Regression integration test
application-integration-test.properties Set test project name

How (Root Cause & Fix)

The Bug

Jackson couldn't serialize the Contrast SDK Project interface because:

  1. Method-style accessors: SDK uses id(), name() instead of JavaBean getId(), getName()
  2. Non-serializable methods: Interface includes codeArtifacts() and scans() that return SDK resource handles, not data
  3. Package-private implementation: ProjectImpl isn't annotated for Jackson

The Fix

Create a ScanProject record that:

  • Maps all 15 data fields from the SDK interface
  • Uses standard record syntax (Jackson serializes records natively)
  • Excludes non-data methods (codeArtifacts(), scans())
  • Handles null values defensively (namespace filters → empty lists)

This follows the established pattern used by VulnLight, ApplicationData, etc.


Step-by-Step Walkthrough

1. ScanProject.java (new file)

public record ScanProject(
    String id,
    String name,
    String organizationId,
    boolean archived,
    String language,
    int critical, int high, int medium, int low, int note,  // vuln counts
    String lastScanId,
    Instant lastScanTime,
    int completedScans,
    List<String> includeNamespaceFilters,
    List<String> excludeNamespaceFilters
) {
    public static ScanProject from(Project project) { ... }
}

Key decisions:

  • Record (not POJO) for immutability and automatic Jackson support
  • Factory method from() handles null namespace filters → empty lists
  • Defensive copies of lists to prevent external modification

2. GetSastProjectTool.java (modified)

Before:

public class GetSastProjectTool extends BaseSingleTool<..., Project> {
    protected Project doExecute(...) {
        return project;  // ← Jackson can't serialize this
    }
}

After:

public class GetSastProjectTool extends BaseSingleTool<..., ScanProject> {
    protected ScanProject doExecute(...) {
        return ScanProject.from(project);  // ← Jackson handles records
    }
}

Only 3 lines changed in the tool itself.

3. ScanProjectTest.java (new file)

5 unit tests covering:

Test Purpose
from_should_map_all_fields_correctly All 15 fields mapped
from_should_handle_null_lastScanId_and_lastScanTime New projects with no scans
from_should_handle_null_namespace_filters SDK may return null
from_should_create_defensive_copy_of_namespace_filters Immutability guarantee
from_should_throw_on_null_project Null safety

4. GetSastProjectToolIT.java (modified)

Added regression test getScanProject_regression_all_fields_should_be_populated() that:

  • Calls the real API
  • Asserts every field is accessible and has expected type
  • Explicitly documents what bug AIML-343 was
  • Logs all field values for debugging

Testing

Type Result
Unit tests 5 new tests, all passing
Integration tests 1 new regression test, passing
Existing tests No changes needed, all passing
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0  -- ScanProjectTest
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0  -- GetSastProjectToolIT

Jira

Fixes AIML-343

@ChrisEdwards
ChrisEdwards marked this pull request as ready for review January 4, 2026 04:05
@ChrisEdwards
ChrisEdwards force-pushed the AIML-342-test-plan-migration branch from 30cd642 to 678a0a2 Compare January 6, 2026 17:28
@ChrisEdwards
ChrisEdwards force-pushed the AIML-343-get-scan-project-empty-data branch from 8708c09 to 8862591 Compare January 6, 2026 17:30
@ChrisEdwards
ChrisEdwards force-pushed the AIML-342-test-plan-migration branch from 678a0a2 to e40b9c9 Compare January 7, 2026 00:18
The SDK Project interface could not be serialized by Jackson because it
uses method-style accessors (id() not getId()) and contains non-serializable
resource navigation methods. This caused the tool to return {"data":{}}
despite finding the project.

Solution: Create ScanProject record that maps SDK fields to a Jackson-
serializable data class, following the established VulnLight pattern.

Changes:
- Add ScanProject record with from() factory method
- Update GetSastProjectTool to return ScanProject instead of raw Project
- Add ScanProjectTest with 5 tests for factory method edge cases
- Add regression test in GetSastProjectToolIT verifying all 15 fields
- Configure test.scan.project-name=WebGoat for integration tests

All 553 unit tests and 6 integration tests pass.
@ChrisEdwards
ChrisEdwards force-pushed the AIML-343-get-scan-project-empty-data branch from 8862591 to c6b3403 Compare January 7, 2026 00:20
@ChrisEdwards
ChrisEdwards changed the base branch from AIML-342-test-plan-migration to main January 7, 2026 00:20
@ChrisEdwards ChrisEdwards changed the title AIML-343: Fix get_scan_project returning empty data [STACKED] AIML-343: Fix get_scan_project returning empty data Jan 7, 2026
ChrisEdwards added a commit that referenced this pull request Jan 7, 2026
Address PR #59 review feedback - integration tests don't need
verbose log.info() output. Assertions provide sufficient test
validation and failure information.
@ChrisEdwards
ChrisEdwards merged commit 47aa258 into main Jan 7, 2026
4 checks passed
ChrisEdwards added a commit that referenced this pull request Jan 7, 2026
Address PR #59 review feedback - integration tests don't need
verbose log.info() output. Assertions provide sufficient test
validation and failure information.
ChrisEdwards added a commit that referenced this pull request Jan 7, 2026
Address PR #59 review feedback - integration tests don't need
verbose log.info() output. Assertions provide sufficient test
validation and failure information.
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.

3 participants