-
Notifications
You must be signed in to change notification settings - Fork 5
AIML-189: Remove duplicate app_name/app_id tool variants to optimize AI context usage #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f6acd0f to
28729a4
Compare
22264b6 to
d9149ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR consolidates duplicate MCP tool variants to optimize AI context usage. The core change removes tools that accept application names in favor of those accepting application IDs, establishing a consistent workflow where agents first resolve names to IDs via list_applications_with_name, then use ID-based tools for operations.
Key changes:
- Removes 4 duplicate app_name tool variants (SCA, ADR, Assess services)
- Renames remaining app_id tools to simplified names (removes
_by_app_idsuffix) - Adds comprehensive test coverage (1,200+ lines across unit and integration tests)
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| SCAService.java | Removes getApplicationLibraries(app_name), renames tool to list_application_libraries, adds input validation |
| AssessService.java | Removes getVulnerability(app_name) and listVulnsInAppByName(app_name), renames remaining tools |
| ADRService.java | Removes getProtectData(app_name), renames tool to get_ADR_Protect_Rules, adds input validation |
| RouteCoverageService.java | Consolidates 6 route coverage methods into single parameterized method |
| SCAServiceTest.java | New comprehensive unit tests for library operations |
| SCAServiceIntegrationTest.java | New integration tests with automatic test data discovery |
| ADRServiceTest.java | Adds unit tests for getProtectDataByAppID |
| ADRServiceIntegrationTest.java | New integration tests for Protect/ADR rules |
| RouteCoverageServiceTest.java | New comprehensive unit tests for consolidated route coverage method |
| RouteCoverageServiceIntegrationTest.java | New integration tests for route coverage with filter validation |
| CLAUDE.md | Adds bead status management guidelines |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/test/java/com/contrast/labs/ai/mcp/contrast/RouteCoverageServiceIntegrationTest.java
Show resolved
Hide resolved
src/main/java/com/contrast/labs/ai/mcp/contrast/RouteCoverageService.java
Show resolved
Hide resolved
## Changes Made ### Tool Consolidation - Removed 4 duplicate app_name variant tools: - `SCAService.list_application_libraries` (app_name) - `ADRService.get_ADR_Protect_Rules` (app_name) - `AssessService.get_vulnerability` (app_name) - `AssessService.list_vulnerabilities` (app_name) ### Tool Renaming - Renamed remaining app_id tools to remove suffix: - `list_application_libraries_by_app_id` → `list_application_libraries` - `get_ADR_Protect_Rules_by_app_id` → `get_ADR_Protect_Rules` - `get_vulnerability_by_id` → `get_vulnerability` - `list_vulnerabilities_with_id` → `list_vulnerabilities` - Updated tool descriptions to mention using `list_applications_with_name` first to get application ID from name ### Code Improvements - Added input validation to `SCAService.getApplicationLibrariesByID()` for null/empty appID parameter ### Test Enhancements - Added comprehensive unit tests for SCA service methods - Added integration tests for ADR and SCA services with test data discovery - Fixed Mockito strictness issues with lenient settings - Fixed integration test for invalid CVE handling ### Documentation - Updated 4 test plan files with AIML-189 consolidation notes - Deleted 4 obsolete test plan files for removed app_name variants ## Test Results - All 248 unit and integration tests passing - mvn verify: SUCCESS 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
28729a4 to
4d8aacd
Compare
| @Tool(name = "list_application_libraries_by_app_id", description = "Takes a application ID and returns the libraries used in the application, note if class usage count is 0 the library is unlikely to be used") | ||
| @Tool(name = "list_application_libraries", description = "Takes an application ID and returns the libraries used in the application. Use list_applications_with_name first to get the application ID from a name. Note: if class usage count is 0 the library is unlikely to be used") | ||
| public List<LibraryExtended> getApplicationLibrariesByID(String appID) throws IOException { | ||
| if (appID == null || appID.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for future downstream changes....
Use StringUtils.isNotBlank() or the Spring StringUtils library...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its on my list. Sounds like a helpful library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for your other tech debt cleanup tickets, lets replace to @Service classes that are using it's own constructor we can replace with @RequiredArgsConstructor
example:
@Service
@RequiredArgsConstructor
public class ADRService {
private static final Logger logger = LoggerFactory.getLogger(ADRService.class);
private final PaginationHandler paginationHandler;
@Value("${contrast.host-name:${CONTRAST_HOST_NAME:}}")
private String hostName;
@Value("${contrast.api-key:${CONTRAST_API_KEY:}}")
private String apiKey;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a story to use lombok everywhere. I only used it in a few places for that first pr. We need to adopt it full on now.
9f1fe96 to
4d8aacd
Compare
|
So I'm having an issue with this branch.. new build, new deploy and i created a new chat so it doesn't have any context in it. then I prompt it: it returns this: and I opened the readme.html and reran the
But I know it's not a configuration issue because same chat: comes back with: Here are the applications in Contrast Security: Application IDs: Welcome to Tomcat - c6ad707e-fd5e-4cd3-934b-cb75b30db662 (Java, offline) |
|
Jason, what are you using to load the application list? There is no pagination, and most tools crash because it's too much data. That is something I am fixing this week. |
this is no longer an issue, Chris had me reboot my vscode (shut off completely and turn back on) and it corrected the issue. |
Rebased onto main after PR #25 (AIML-224) merged.
Summary
This PR consolidates duplicate MCP tool variants that accept either application name or application ID, reducing tool bloat and optimizing AI agent context window usage. Currently, the MCP server exposes two versions of each application-level operation—one accepting app_name and one accepting app_id—which unnecessarily consumes valuable context space.
Problem Statement
Why This Change Is Needed
The MCP server currently exposes duplicate tools for every application-scoped operation:
Example duplicates:
get_vulnerability(app_name, vulnID)ANDget_vulnerability_by_id(appID, vulnID)list_vulnerabilities(app_name)ANDlist_vulnerabilities_with_id(appID)get_ADR_Protect_Rules(app_name)ANDget_ADR_Protect_Rules_by_app_id(appID)list_application_libraries(app_name)ANDlist_application_libraries_by_app_id(appID)Issues with this approach:
Why app_id-only is sufficient:
list_applications_with_namefirst to resolve names to IDsSolution Design
Approach: Keep app_id variants, remove app_name variants
Rationale for choosing app_id over app_name:
list_applications_with_namefor name→ID resolutionChanges Made
1. Service Layer Consolidation
Removed duplicate methods:
SCAService.getApplicationLibraries(String app_name)ADRService.getProtectData(String applicationName)AssessService.getVulnerability(String vulnID, String app_name)AssessService.listVulnsInAppByName(String app_name)Renamed remaining methods (MCP tool names only, kept method names for compatibility):
list_application_libraries_by_app_id→list_application_librariesget_ADR_Protect_Rules_by_app_id→get_ADR_Protect_Rulesget_vulnerability_by_id→get_vulnerabilitylist_vulnerabilities_with_id→list_vulnerabilitiesEnhanced tool descriptions:
All consolidated tools now include guidance: "Use list_applications_with_name first to get the application ID from a name"
2. Code Quality Improvements
Added input validation:
Why this matters: Previously, invalid input would fail deep in the SDK with unclear errors. Now we fail fast with clear, actionable error messages.
3. Comprehensive Test Coverage
New test files (1,200+ lines of tests):
SCAServiceTest.java- Unit tests for library operationsSCAServiceIntegrationTest.java- Live API tests with test data discoveryADRServiceIntegrationTest.java- Live API tests for Protect rulesTest improvements:
@MockitoSettings(strictness = Strictness.LENIENT)to handle complex mock scenariosTest results:
mvn verifysuccessful4. Documentation Updates
Updated test plan files:
Added AIML-189 consolidation notes to 4 remaining test plans explaining:
Deleted obsolete documentation:
Removed 4 test plan files for deleted app_name variants:
test-plan-get_ADR_Protect_Rules.mdtest-plan-get_vulnerability.mdtest-plan-list_application_libraries.mdtest-plan-list_vulnerabilities.mdImpact Analysis
For AI Agents
Before:
After:
For Users
No breaking changes for well-designed agents:
list_applications_with_namewill work unchangedWorkflow example:
Backward Compatibility
This should be fully backward compatible. Agents dynamically discover the tools to call and will automatically adapt to getting the app id and calling the app id tools.
Testing Strategy
Unit Tests
Integration Tests
Manual Testing
Run these commands to verify:
Future Improvements
This consolidation establishes a pattern for future tools:
list_applications_with_name)Related Issues
Testing checklist:
Review focus areas: